VideoVulkan/ShaderCompiler: Use a std::optional instead of bool+out variable

Now that we utilize C++17, we can simply return an optional containing
the code instead of using an out variable and a boolean result,
essentially combining them into one.

This provides a much more straightforward interface.
This commit is contained in:
Lioncash
2019-05-30 03:52:05 -04:00
parent e60268bd42
commit d6a60050ff
3 changed files with 30 additions and 30 deletions

View File

@ -88,31 +88,29 @@ static std::unique_ptr<VKShader> CreateShaderObject(ShaderStage stage,
std::unique_ptr<VKShader> VKShader::CreateFromSource(ShaderStage stage, std::string_view source)
{
ShaderCompiler::SPIRVCodeVector spv;
bool result;
std::optional<ShaderCompiler::SPIRVCodeVector> spv;
switch (stage)
{
case ShaderStage::Vertex:
result = ShaderCompiler::CompileVertexShader(&spv, source);
spv = ShaderCompiler::CompileVertexShader(source);
break;
case ShaderStage::Geometry:
result = ShaderCompiler::CompileGeometryShader(&spv, source);
spv = ShaderCompiler::CompileGeometryShader(source);
break;
case ShaderStage::Pixel:
result = ShaderCompiler::CompileFragmentShader(&spv, source);
spv = ShaderCompiler::CompileFragmentShader(source);
break;
case ShaderStage::Compute:
result = ShaderCompiler::CompileComputeShader(&spv, source);
spv = ShaderCompiler::CompileComputeShader(source);
break;
default:
result = false;
break;
}
if (!result)
if (!spv)
return nullptr;
return CreateShaderObject(stage, std::move(spv));
return CreateShaderObject(stage, std::move(*spv));
}
std::unique_ptr<VKShader> VKShader::CreateFromBinary(ShaderStage stage, const void* data,