Skip to content
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

Closed
untodesu opened this issue Mar 9, 2021 · 4 comments
Closed

HLSL/OpenGL: SV_InstanceID binds to the invalid builtin #2566

untodesu opened this issue Mar 9, 2021 · 4 comments

Comments

@untodesu
Copy link

untodesu commented Mar 9, 2021

When building an HLSL shader for OpenGL environment (it just works, don't ask), the SV_InstanceID semantic should be bound to the InstanceId builtin while being bound InstanceIndex.
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 to InstanceId and everything works as intended.
Possible workaround: chain-compile HLSL=>SPV=>GLSL=>SPV

Code generated by glslangValidator for HLSL (with -G --hlsl-dx9-compatibility):

OpDecorate %instance_id BuiltIn InstanceIndex

Code generated by glslangValidator for GLSL (with -G):

OpDecorate %gl_InstanceID BuiltIn InstanceId
@greg-lunarg
Copy link
Contributor

"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.

@greg-lunarg
Copy link
Contributor

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.

@greg-lunarg
Copy link
Contributor

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.

@greg-lunarg
Copy link
Contributor

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants