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

The array size of gl_SampleMask and gl_SampleMaskIn is ceil(gl_MaxSamples/32) #3399

Merged
merged 2 commits into from
Dec 29, 2023

Conversation

jimihem
Copy link
Contributor

@jimihem jimihem commented Nov 14, 2023

#version 320 es

layout(location = 0) out mediump vec4 fragColor;
void main (void)
{
for (int i = 0; i < gl_SampleMask.length(); ++i)
gl_SampleMask[i] = int(0xAAAAAAAA);

   fragColor = vec4(0.0, 1.0, 0.0, 1.0);

}
gl_SampleMask.length() report error: “array must have size before use length"

dEQP-GLES31.functional.shaders.sample_variables.sample_mask.discard_half_per_pixel.default_framebuffer

@CLAassistant
Copy link

CLAassistant commented Nov 14, 2023

CLA assistant check
All committers have signed the CLA.

@ncesario-lunarg
Copy link
Collaborator

@jimihem Can you please add a test to validate this change?

It might also be helpful if the commit message is a bit more explicit with respect to what is being fixed.

@jimihem
Copy link
Contributor Author

jimihem commented Nov 15, 2023

@ncesario-lunarg How to add a test to glslang?

@jimihem jimihem force-pushed the gl_SampleMask_length branch from b547a25 to 2294aec Compare November 21, 2023 07:36
@jimihem
Copy link
Contributor Author

jimihem commented Nov 22, 2023

@ncesario-lunarg I have add a test to glslang, Can you help to merge this pr?

@ncesario-lunarg
Copy link
Collaborator

Thanks for these changes @jimihem, and sorry for the late reply (somehow I missed your previous comment).

This LGTM with just a few minor nits for the tests:

  1. runtests is generally for testing the standalone glslang executable, but I don't think this change needs to test anything with respect to the standalone executable specifically? If that's true, then I would revert the changes to runtests and instead add the test file you added to gtests/AST.FromFile.cpp. e..g,:
diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp
index cf56dae5..540cd99b 100644
--- a/gtests/AST.FromFile.cpp
+++ b/gtests/AST.FromFile.cpp
@@ -282,6 +282,7 @@ INSTANTIATE_TEST_SUITE_P(
         "glsl.es320.subgroupQuad.comp",
         "glsl.es320.subgroupVote.comp",
         "glsl.es320.extTextureShadowLod.frag",
+        "gl_samplemask_array_size.frag",
         "glsl.ext.textureShadowLod.frag",
         "terminate.frag",
         "terminate.vert",

Once you have that, you can run the gtest executable in "update mode" to automatically update the test results file (e.g., build/gtests/glslangtests --update-mode), though you should double check the result file contents afterward.

  1. The result file should be named <test name>.out, where <test name> includes the extension, so you just need to rename Test/baseResults/gl_samplemask_array_size.out to Test/baseResults/gl_samplemask_array_size.frag.out. Running glslangtest in "update mode" may do this for you, but then you'll need to remove Test/baseResults/gl_samplemask_array_size.out.

Copy link
Collaborator

@ncesario-lunarg ncesario-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, but otherwise LGTM modulo some changes to the tests.

@jimihem If you're ok with me updating your branch, I can push the testing changes I suggested.

Comment on lines 1749 to 1751
} else if (intermNode->getAsSymbolNode()) {
const TString& name = intermNode->getAsSymbolNode()->getName();
if (name == "gl_SampleMask" || name == "gl_SampleMaskIn") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to instead get the qualifier and compare against EbvSampleMask here? e.g.,

} else if (const auto typed = intermNode->getAsTyped()) {
    if (typed->getQualifier().builtIn == EbvSampleMask) {

…ples/32)

    Oes spec says:
    For the both the input array gl_SampleMaskIn[] and the output array gl_SampleMask[], bit B of mask M
    (gl_SampleMaskIn[M] or gl_SampleMask[M]) corresponds to sample 32*M+B. These arrays have
    ceil(gl_MaxSamples/32) elements, where gl_MaxSamples is the maximum number of color samples
    supported by the implementation.

    But glslang report error "array must have size before use length".

    layout(location = 0) out mediump vec4 fragColor;
    void main (void)
    {
    for (int i = 0; i < gl_SampleMask.length(); ++i)
    gl_SampleMask[i] = int(0xAAAAAAAA);

       fragColor = vec4(0.0, 1.0, 0.0, 1.0);
    }
@jimihem jimihem force-pushed the gl_SampleMask_length branch from 2294aec to 4dac03d Compare November 23, 2023 03:11
@jimihem
Copy link
Contributor Author

jimihem commented Nov 23, 2023

@ncesario-lunarg Thank you for your reply, I have made some changes to this pr based on your suggestion.

Copy link
Collaborator

@ncesario-lunarg ncesario-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jimihem, this LGTM, but I'll give @arcady-lunarg a chance to take a look before merging.

Copy link
Contributor

@arcady-lunarg arcady-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be a good idea to add a test for the case where gl_MaxSamples is greater than 32 (something like 64 would probably be a good value since that's the highest I have heard of).

@jimihem
Copy link
Contributor Author

jimihem commented Dec 27, 2023

@arcady-lunarg gl_MaxSamples cann't be redeclared, when I try to redeclared it and initialize it as 64, glslang will report error.
glslangtests use default builtin resource and gl_MaxSamples is 4, so I cann't modify gl_MaxSamples to 64.

@arcady-lunarg
Copy link
Contributor

@jimihem I think this would be a good case for a runtests style test, passing 2 different configurations to glslang and having 2 different expected results based on which configuration is used.

Copy link
Contributor

@arcady-lunarg arcady-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good.

@arcady-lunarg arcady-lunarg added the kokoro:run Trigger Google bot runs label Dec 29, 2023
@kokoro-team kokoro-team removed the kokoro:run Trigger Google bot runs label Dec 29, 2023
@arcady-lunarg arcady-lunarg merged commit db4d6f8 into KhronosGroup:main Dec 29, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants