mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
D3DCommon/Shader: Use std::optional with CompileShader()
Allows removing the use of an out parameter, making it nicer to use.
This commit is contained in:
@ -89,8 +89,8 @@ static const char* GetCompileTarget(D3D_FEATURE_LEVEL feature_level, ShaderStage
|
||||
}
|
||||
}
|
||||
|
||||
bool Shader::CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_bytecode,
|
||||
ShaderStage stage, std::string_view source)
|
||||
std::optional<Shader::BinaryData> Shader::CompileShader(D3D_FEATURE_LEVEL feature_level,
|
||||
ShaderStage stage, std::string_view source)
|
||||
{
|
||||
static constexpr D3D_SHADER_MACRO macros[] = {{"API_D3D", "1"}, {nullptr, nullptr}};
|
||||
const UINT flags = g_ActiveConfig.bEnableValidationLayer ?
|
||||
@ -116,7 +116,7 @@ bool Shader::CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_byte
|
||||
|
||||
PanicAlert("Failed to compile %s:\nDebug info (%s):\n%s", filename.c_str(), target,
|
||||
static_cast<const char*>(errors->GetBufferPointer()));
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (errors && errors->GetBufferSize() > 0)
|
||||
@ -125,9 +125,7 @@ bool Shader::CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_byte
|
||||
static_cast<const char*>(errors->GetBufferPointer()));
|
||||
}
|
||||
|
||||
out_bytecode->resize(code->GetBufferSize());
|
||||
std::memcpy(out_bytecode->data(), code->GetBufferPointer(), code->GetBufferSize());
|
||||
return true;
|
||||
return CreateByteCode(code->GetBufferPointer(), code->GetBufferSize());
|
||||
}
|
||||
|
||||
AbstractShader::BinaryData Shader::CreateByteCode(const void* data, size_t length)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include "VideoBackends/D3DCommon/Common.h"
|
||||
#include "VideoCommon/AbstractShader.h"
|
||||
@ -19,8 +20,8 @@ public:
|
||||
|
||||
BinaryData GetBinary() const override;
|
||||
|
||||
static bool CompileShader(D3D_FEATURE_LEVEL feature_level, BinaryData* out_bytecode,
|
||||
ShaderStage stage, std::string_view source);
|
||||
static std::optional<BinaryData> CompileShader(D3D_FEATURE_LEVEL feature_level, ShaderStage stage,
|
||||
std::string_view source);
|
||||
|
||||
static BinaryData CreateByteCode(const void* data, size_t length);
|
||||
|
||||
|
Reference in New Issue
Block a user