-
Notifications
You must be signed in to change notification settings - Fork 842
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
HLSL/OpenGL: SV_InstanceID binds to the invalid builtin #2566
Comments
"Officially", the -G option is only supported for GLSL. That is why users might find assumptions that HLSL should be targeted to Vulkan only. That said, I understand people are having success with -G --hlsl-dx9-compatibility, and while I am not funded to develop this mode, I am open to changes to improve it. I am not officially saying that -G will support HLSL at this point. But I am not disallowing it either. Currently, when targeting Vulkan, SV_InstanceID is indeed mapped to InstanceIndex builtin. That needs to continue. But when targeting OGL, this can be mapped to InstanceID. If I can make this change easily, I will. Otherwise I will add a request for help to this issue. I will not be adding a regression test. If someone wishes to add a regression test, I would be willing to accept it. |
It appears we currently are prohibiting compilation of HLSL targeting OGL. An error is issued and SPIR-V is not generated. This is a recent change. I will need to rethink this policy in order to proceed with this issue. Please stand by. |
The error was added because glslang does not currently support -D -G, that is, targeting HLSL shaders to OGL, particularly the general DX10 separate texture / sampler model. Use of the dx9 compatible mode helps overcome this obstacle, and could likely play a role in reshaping this policy. |
#1417 documents the request for support for HLSL targeting OGL. I am not currently funded to do the development for this, but if someone wishes to I am certainly available to help integrate this work. Specifically, I would like someone to identify a version of HLSL that will be accepted (DX9? - some features?) as well as develop the code to make this happen (eg utilize InstanceID) so that it can be confidently claimed that given an HLSL shader glslang generates semantically correct OGL SPIR-V or generates an error. Until then, cross compiling via spirv-cross is an option. Given #1417 covers the request in this issue and now will have a pointer to this issue, I will close this issue. Please re-open if I am missing something. |
When building an HLSL shader for OpenGL environment (it just works, don't ask), the
SV_InstanceID
semantic should be bound to theInstanceId
builtin while being boundInstanceIndex
.GL doesn't seem to write anything to
InstanceIndex
which results in the instance id being zero all the time.However when the GLSL code generated by SPIRV-Cross is being compiled,
gl_InstanceID
is bound toInstanceId
and everything works as intended.Possible workaround: chain-compile HLSL=>SPV=>GLSL=>SPV
Code generated by glslangValidator for HLSL (with
-G --hlsl-dx9-compatibility
):Code generated by glslangValidator for GLSL (with
-G
):The text was updated successfully, but these errors were encountered: