Skip to content

Commit

Permalink
GPUDevice: Disable SPIR-V optimization on GLSL output
Browse files Browse the repository at this point in the history
SSO causes SPIRV-Cross to redeclare builtins, which we don't want
(breaks on Mesa).
  • Loading branch information
stenzek committed Jun 28, 2024
1 parent dd420cb commit 8c72fd5
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/util/gpu_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,23 +1519,6 @@ bool GPUDevice::TranslateVulkanSpvToLanguage(const std::span<const u8> spirv, GP
static_cast<int>(sres));
return {};
}

const bool enable_sso = (is_gles ? (target_version >= 310) : (target_version >= 410));
if ((sres = dyn_libs::spvc_compiler_options_set_bool(soptions, SPVC_COMPILER_OPTION_GLSL_SEPARATE_SHADER_OBJECTS,
enable_sso)) != SPVC_SUCCESS)
{
Error::SetStringFmt(
error, "spvc_compiler_options_set_bool(SPVC_COMPILER_OPTION_GLSL_SEPARATE_SHADER_OBJECTS) failed: {}",
static_cast<int>(sres));
return {};
}
if (enable_sso && ((sres = dyn_libs::spvc_compiler_require_extension(
scompiler, "GL_ARB_separate_shader_objects")) != SPVC_SUCCESS))
{
Error::SetStringFmt(error, "spvc_compiler_require_extension(GL_ARB_separate_shader_objects) failed: {}",
static_cast<int>(sres));
return {};
}
}
break;
#endif
Expand Down Expand Up @@ -1638,12 +1621,9 @@ std::unique_ptr<GPUShader> GPUDevice::TranspileAndCreateShaderFromSource(
GPUShaderStage stage, GPUShaderLanguage source_language, std::string_view source, const char* entry_point,
GPUShaderLanguage target_language, u32 target_version, DynamicHeapArray<u8>* out_binary, Error* error)
{
// Disable optimization when targeting OpenGL GLSL, and separate shader objects are missing.
// Otherwise, the name-based linking will fail.
// Disable optimization when targeting OpenGL GLSL, otherwise, the name-based linking will fail.
const bool optimization =
(target_language != GPUShaderLanguage::GLSL && target_language != GPUShaderLanguage::GLSLES) ||
(target_language == GPUShaderLanguage::GLSL && target_version >= 410) ||
(target_language == GPUShaderLanguage::GLSLES && target_version >= 310);
(target_language != GPUShaderLanguage::GLSL && target_language != GPUShaderLanguage::GLSLES);
DynamicHeapArray<u8> spv;
if (!CompileGLSLShaderToVulkanSpv(stage, source_language, source, entry_point, optimization, false, &spv, error))
return {};
Expand Down

0 comments on commit 8c72fd5

Please sign in to comment.