From 808a14dede94a0cddb969b5f5d84f7fab9ee872c Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 12 Aug 2024 12:42:23 +0100 Subject: [PATCH] Handle SPIR-V GL shaders with no location on texture binds. Closes #3405 * Since GL doesn't have sets, use the fixedBindSetOrSpace to namespace bindings with locations (that need to be queried) from bindings without locations (which have a fixed bind). Prior to the descriptor refactor this was indiated with negative binds. --- renderdoc/driver/gl/gl_shader_refl.cpp | 24 +++++++++++++++---- .../driver/shaders/spirv/spirv_reflect.cpp | 5 +++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/renderdoc/driver/gl/gl_shader_refl.cpp b/renderdoc/driver/gl/gl_shader_refl.cpp index ccaf86eb2..447d21508 100644 --- a/renderdoc/driver/gl/gl_shader_refl.cpp +++ b/renderdoc/driver/gl/gl_shader_refl.cpp @@ -2485,11 +2485,25 @@ void GetCurrentBinding(GLuint curProg, ShaderReflection *refl, const ShaderResou if(refl->encoding == ShaderEncoding::OpenGLSPIRV) { - if(resource.isTexture && resource.fixedBindNumber != ~0U) + slot = 0; + if(resource.isTexture) { - GL.glGetUniformiv(curProg, resource.fixedBindNumber, dummyReadback); - slot = dummyReadback[0]; - used = true; + if(resource.fixedBindNumber == ~0U) + { + slot = 0; + } + // the fixedBindSetOrSpace is set to 1 if a location is provided (whether or not there's a fixed binding) + else if(resource.fixedBindSetOrSpace == 0) + { + slot = resource.fixedBindNumber; + used = true; + } + else + { + GL.glGetUniformiv(curProg, resource.fixedBindNumber, dummyReadback); + slot = dummyReadback[0]; + used = true; + } } } else if(resource.isReadOnly) @@ -2669,6 +2683,8 @@ void GetCurrentBinding(GLuint curProg, ShaderReflection *refl, const ConstantBlo { // It's fuzzy on whether UBOs can be remapped with glUniformBlockBinding so for now we hope that // anyone using UBOs and SPIR-V will at least specify immutable bindings in the SPIR-V. + slot = cblock.fixedBindNumber; + used = true; return; } diff --git a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp index 0327233b0..c50502ef5 100644 --- a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp @@ -1386,9 +1386,12 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st Decorations::Flags flags = Decorations::Flags( decorations[global.id].flags & (Decorations::HasLocation | Decorations::HasBinding)); + bindset = 0; + if(flags == Decorations::HasLocation) { bind = decorations[global.id].location; + bindset = 1; } else if(flags == Decorations::NoFlags) { @@ -1422,7 +1425,7 @@ void Reflector::MakeReflection(const GraphicsAPI sourceAPI, const ShaderStage st res.variableType.baseType = VarType::UInt; res.variableType.name = varType->name; - res.fixedBindSetOrSpace = 0; + res.fixedBindSetOrSpace = bindset; res.fixedBindNumber = GetBinding(decorations[global.id].binding); res.bindArraySize = arraySize;