-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
[spirv][glspirv] Const Arrays #35
Comments
Pretty sure this is the relevant block: https://github.com/FNA-XNA/MojoShader/blob/upstream/profiles/mojoshader_profile_spirv.c#L2345-L2454 It should be emitting constants, vs ARB_gl_spirv where it emits constants as uniform data. |
More context for testing/troubleshooting, since I ran into another bit of code (not mine, this time) that uses them. Neither of these snippets work in Vulkan: static const float thresholdMatrix[] = {
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
};
bool StippleReject (float index, float stippleFactor) {
float stippleThreshold = thresholdMatrix[index % 16];
return (stippleFactor - stippleThreshold) <= 0;
} nor this: bool StippleReject (float index, float stippleFactor) {
const float thresholdMatrix[] = {
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
};
float stippleThreshold = thresholdMatrix[index % 16];
return (stippleFactor - stippleThreshold) <= 0;
} |
Bad news is that |
The workaround seems fine, but this tells me the block I linked to is right - the only difference between the GL and VK modes are the VPOS fixup and the const array emit block. |
It will still be a few days until I fully catch up with mojoshader and fna3d development after summer madness. I will try to build some test shaders when I get around to it to see what dxbc looks like for them. I don't see any obvious reason why it would work with Is there difference between dxbc for local and global const array? Also, who fills in values? Should those be baked into the shader or is it done by preshader? |
I've been experimenting with those arrays, but nothing obviously wrong comes to mind. Test shaders I used were compiled with
Unfortunately, fxc spits out exactly same binary for global and local array in @kg, can you provide compiled versions of any of those problematic shaders? Ideally version that works and one that doesn't so I can see what is different between them. It is possible that the way constants are emitted for SPIR-V is only compatible with OpenGL and not with Vulkan, but that would probably show up elsewhere as well, so I'm not convinced that is the case. Ethan might be right that the problem stems from uniform handling, though I'd like to be sure before making changes in it. |
The global and local array should produce the same binary, the thing that works is |
Ah, right, you said that neither of them works. In any case, those shaders I posted compile into what looks like perfectly normal binary. Unfortunately, |
I found some minor difference between SPIR-V output of glslangValidator and mojoshader. While mojoshader uses initializer operand of Here's the commit, if you could give it a try and see if it helps: https://github.com/krolli/MojoShader/commit/06f924f1e0efe625b508a5cd1be7a26777785970 |
@kg, have you tried those changes to see if they help with the problem? |
Missed the previous comment, will try to take a look soon |
Just a note for posterity that, like in every other backend before it, the spir-v backend seems to have a partially or completely broken implementation for local const arrays. static const arrays might also be broken but i haven't tested them.
Example problem code snippet:
in original XNA along with FNA3D d3d11 and FNA3D glsl, QuadCorners[1] will be {1, 0} but in spir-v right now, it seems to always be 0.
I'm just going to learn my lesson and never use arrays again but maybe someone else will run into this problem in the future.
The text was updated successfully, but these errors were encountered: