-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for CapabilityShaderViewportIndex and CapabilityShaderLayer #2432
Conversation
…ity ShaderViewportIndex and using gl_Layer will emit OpCapability CapabilityShaderLayer. OpCapability ShaderViewportIndexLayerEXT will only get emitted if the target < SPIR-V 1.5
…pCapability ShaderViewportIndexLayerEXT, even when targeting SPIR-V 1.5
I have also made a pull request for I'm guessing this pull request won't be merge-able until the other one is merged and the external dependencies can be updated. |
This isn't quite true.
It was split into these two finer-granularity capabilities.
They've always been built-ins.
Yes, I think that's the point: SPIR-V 1.5 brought this functionality into core, using different capabilities than it had when using the extension. When targeting 1.5, glslang should use the newer-core capabilities, and before that it should us the extension capabilities. Both should still be in play. This should be triggered by seeing use/declaration, not by source extension, and when triggered it should emit capabilities/extensions based on the target, not on source extension. |
SPIRV/SpvBuilder.h
Outdated
@@ -80,6 +80,23 @@ class Builder { | |||
|
|||
unsigned int getSpvVersion() const { return spvVersion; } | |||
|
|||
bool hasSourceExtension(const char* ext) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not be making these decisions based on source extension, only on feature use and target environment.
Huh, TIL, thank you. I'm no spec lawyer, I just went along the ride with compiler errors/validation layer problems until I made it here. Although from how I understand this, glslang is currently emitting invalid SPIR-V because the compiler won't emit the OpExtension requirement for
Can you elaborate on what you think this should look like? I'm happy to make any changes to this pull request so I can target SPIR-V 1.5 and get valid SPIR-V out of it. It's my understanding that This led me to using the source extension as a hint what to do. The Vulkan spec text is a bit vague (again, no spec lawyer), but it says you get |
Yes, I think glslang needs a fix, to reflect the split into two capabilities, based on what the target version is. I think we need something like:
Similarly for Doing it from the top of my head, initial stab. Does this miss something? |
Ah, gotcha. I believe this was already implemented by my first commit (670536b). I can revert the second commit and just leave the first one. |
…ack to OpCapability ShaderViewportIndexLayerEXT, even when targeting SPIR-V 1.5" This reverts commit dccca82.
@@ -7548,7 +7548,7 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion | |||
BuiltInVariable("gl_Layer", EbvLayer, symbolTable); | |||
BuiltInVariable("gl_ViewportIndex", EbvViewportIndex, symbolTable); | |||
|
|||
if (language != EShLangGeometry) { | |||
if (language != EShLangGeometry && spvVersion.spv < glslang::EShTargetSpv_1_5) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variables should have the same GLSL semantics regardless of selected SPIR-V target.
Or, did the SPIR-V extension really say that core GLSL is modified to not need the GLSL extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errr, I'm no spec lawyer and I might be completely wrong here, but how I read this is as follows:
SPV_EXT_shader_viewport_index_layer
makes the layer and viewport index built ins available outside of the geometry shaders. To quote the extension text:
The new ShaderViewportIndexLayerEXT capability allows the Layer and ViewportIndex builtin variables to be exported from Vertex or Tessellation shaders, in addition to Geometry shaders. This is functionality added GLSL by both GL_ARB_shader_viewport_layer_array and GL_NV_viewport_array2, and separately by GL_AMD_vertex_shader_layer, and GL_AMD_vertex_shader_viewport_index.
SPIR-V 1.5 adds the following to the built ins:
ViewportIndex
Viewport selection for viewport transformation when using multiple viewports. See the client API specification for more detail.
[...]
The ShaderViewportIndex capability allows for a ViewportIndex output by a Vertex or Tessellation Execution Model.
If I read this right, and mind you, big if here, then that means that targeting SPIR-V 1.5 means that ViewportIndex
built in can just be used without anything else. Same goes for the layer.
Now, this doesn't necessarily mean that the GLSL gl_Layer
and gl_ViewportIndex
tokens are usable without extension. I kinda assumed they are, but in my mind GLSL is just the human readable form of SPIR-V and so my assumption might be completely off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the spec. quotes are about SPIR-V and not about GLSL. SPIR-V and GLSL have independent specifications, and it is not required that their extension declarations run in parallel.
Glslang is currently representing pretty detailed versioning about these variables, and I'd like to not change that without seeing the spec. language for it.
I think the SPIR-V part of your change is good though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, that makes sense. Sorry, the GLSL/SPIR-V/Vulkan line is blurry at best to me.
I have reverted the piece of code in question. Thank you for looking at this :)
…age still requires one of the viewport extensions even when targeting SPIR-V 1.5 (Fixes a problem introduced by 670536b)
With SPIR-V 1.5,
CapabilityShaderViewportIndexLayerEXT
has gone the way of the dodo and has been replaced withCapabilityShaderViewportIndex
andCapabilityShaderLayer
. These two makegl_Layer
andgl_ViewportIndex
actual built ins, that don't require any extension anymore. Unfortunately glslang seems to have no idea about this, using these native built ins when targeting SPIR-V 1.5 will result in an error that extensions are required to make them work.This pull request is split into two commits. The first is basic emitting of
CapabilityShaderViewportIndex
andCapabilityShaderLayer
when encountering the new built ins under SPIR-V 1.5, as well as no longer requiring an extension to use the built ins. The second commit expands on this by introducing a fallback toCapabilityShaderViewportIndexLayerEXT
when one of the previous extensions is present as a source extension. So shaders that use eg.GL_ARB_shader_viewport_layer_array
right now won't get opted into the new built ins and capability.The second commit required adding helper functions to the
Builder
object. Not sure if that's the correct way to do that, or if there is a better way. I'm new to the code base, so I'm not sure what the preferred way for this kind of thing is. Let me know if there are any problems and I'd be happy to correct them :)