From 88c5373ee4fb78888fa8c9668500bd1d03760ecf Mon Sep 17 00:00:00 2001 From: jimihem <149994911+jimihem@users.noreply.github.com> Date: Fri, 29 Dec 2023 07:38:39 +0800 Subject: [PATCH] support GL_ARB_texture_multisample extension. This extension allows the use of "texelFetch" and "textureSize" with 2DMS sampler. --- Test/GL_ARB_texture_multisample.vert | 28 ++ .../GL_ARB_texture_multisample.vert.out | 245 ++++++++++++++++++ glslang/MachineIndependent/Initialize.cpp | 2 +- glslang/MachineIndependent/ParseHelper.cpp | 5 +- gtests/AST.FromFile.cpp | 1 + 5 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 Test/GL_ARB_texture_multisample.vert create mode 100644 Test/baseResults/GL_ARB_texture_multisample.vert.out diff --git a/Test/GL_ARB_texture_multisample.vert b/Test/GL_ARB_texture_multisample.vert new file mode 100644 index 00000000..d3c5e85c --- /dev/null +++ b/Test/GL_ARB_texture_multisample.vert @@ -0,0 +1,28 @@ +#version 140 +#extension GL_ARB_texture_multisample : enable + +out float result; +out int result1; +out uint result2; + +uniform sampler2DMS data; +uniform sampler2DMSArray data1; +uniform isampler2DMS data2; +uniform usampler2DMSArray data3; +uniform usampler2DMS data4; +uniform isampler2DMSArray data5; +void main() +{ + result = texelFetch(data, ivec2(0), 3).r; + ivec2 temp = textureSize(data); + result = texelFetch(data1, ivec3(0), 3).r; + ivec3 temp1 = textureSize(data1); + result1 = texelFetch(data2, ivec2(0), 3).r; + temp = textureSize(data2); + result2 = texelFetch(data3, ivec3(0), 3).r; + temp1 = textureSize(data3); + result2 = texelFetch(data4, ivec2(0), 3).r; + temp = textureSize(data4); + result1 = texelFetch(data5, ivec3(0), 3).r; + temp1 = textureSize(data5); +} diff --git a/Test/baseResults/GL_ARB_texture_multisample.vert.out b/Test/baseResults/GL_ARB_texture_multisample.vert.out new file mode 100644 index 00000000..16912a4a --- /dev/null +++ b/Test/baseResults/GL_ARB_texture_multisample.vert.out @@ -0,0 +1,245 @@ +GL_ARB_texture_multisample.vert +Shader version: 140 +Requested GL_ARB_texture_multisample +0:? Sequence +0:14 Function Definition: main( ( global void) +0:14 Function Parameters: +0:16 Sequence +0:16 move second child to first child ( temp float) +0:16 'result' ( smooth out float) +0:16 direct index ( temp float) +0:16 textureFetch ( global 4-component vector of float) +0:16 'data' ( uniform sampler2DMS) +0:16 Constant: +0:16 0 (const int) +0:16 0 (const int) +0:16 Constant: +0:16 3 (const int) +0:16 Constant: +0:16 0 (const int) +0:17 Sequence +0:17 move second child to first child ( temp 2-component vector of int) +0:17 'temp' ( temp 2-component vector of int) +0:17 textureSize ( global 2-component vector of int) +0:17 'data' ( uniform sampler2DMS) +0:18 move second child to first child ( temp float) +0:18 'result' ( smooth out float) +0:18 direct index ( temp float) +0:18 textureFetch ( global 4-component vector of float) +0:18 'data1' ( uniform sampler2DMSArray) +0:18 Constant: +0:18 0 (const int) +0:18 0 (const int) +0:18 0 (const int) +0:18 Constant: +0:18 3 (const int) +0:18 Constant: +0:18 0 (const int) +0:19 Sequence +0:19 move second child to first child ( temp 3-component vector of int) +0:19 'temp1' ( temp 3-component vector of int) +0:19 textureSize ( global 3-component vector of int) +0:19 'data1' ( uniform sampler2DMSArray) +0:20 move second child to first child ( temp int) +0:20 'result1' ( smooth out int) +0:20 direct index ( temp int) +0:20 textureFetch ( global 4-component vector of int) +0:20 'data2' ( uniform isampler2DMS) +0:20 Constant: +0:20 0 (const int) +0:20 0 (const int) +0:20 Constant: +0:20 3 (const int) +0:20 Constant: +0:20 0 (const int) +0:21 move second child to first child ( temp 2-component vector of int) +0:21 'temp' ( temp 2-component vector of int) +0:21 textureSize ( global 2-component vector of int) +0:21 'data2' ( uniform isampler2DMS) +0:22 move second child to first child ( temp uint) +0:22 'result2' ( smooth out uint) +0:22 direct index ( temp uint) +0:22 textureFetch ( global 4-component vector of uint) +0:22 'data3' ( uniform usampler2DMSArray) +0:22 Constant: +0:22 0 (const int) +0:22 0 (const int) +0:22 0 (const int) +0:22 Constant: +0:22 3 (const int) +0:22 Constant: +0:22 0 (const int) +0:23 move second child to first child ( temp 3-component vector of int) +0:23 'temp1' ( temp 3-component vector of int) +0:23 textureSize ( global 3-component vector of int) +0:23 'data3' ( uniform usampler2DMSArray) +0:24 move second child to first child ( temp uint) +0:24 'result2' ( smooth out uint) +0:24 direct index ( temp uint) +0:24 textureFetch ( global 4-component vector of uint) +0:24 'data4' ( uniform usampler2DMS) +0:24 Constant: +0:24 0 (const int) +0:24 0 (const int) +0:24 Constant: +0:24 3 (const int) +0:24 Constant: +0:24 0 (const int) +0:25 move second child to first child ( temp 2-component vector of int) +0:25 'temp' ( temp 2-component vector of int) +0:25 textureSize ( global 2-component vector of int) +0:25 'data4' ( uniform usampler2DMS) +0:26 move second child to first child ( temp int) +0:26 'result1' ( smooth out int) +0:26 direct index ( temp int) +0:26 textureFetch ( global 4-component vector of int) +0:26 'data5' ( uniform isampler2DMSArray) +0:26 Constant: +0:26 0 (const int) +0:26 0 (const int) +0:26 0 (const int) +0:26 Constant: +0:26 3 (const int) +0:26 Constant: +0:26 0 (const int) +0:27 move second child to first child ( temp 3-component vector of int) +0:27 'temp1' ( temp 3-component vector of int) +0:27 textureSize ( global 3-component vector of int) +0:27 'data5' ( uniform isampler2DMSArray) +0:? Linker Objects +0:? 'result' ( smooth out float) +0:? 'result1' ( smooth out int) +0:? 'result2' ( smooth out uint) +0:? 'data' ( uniform sampler2DMS) +0:? 'data1' ( uniform sampler2DMSArray) +0:? 'data2' ( uniform isampler2DMS) +0:? 'data3' ( uniform usampler2DMSArray) +0:? 'data4' ( uniform usampler2DMS) +0:? 'data5' ( uniform isampler2DMSArray) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + + +Linked vertex stage: + + +Shader version: 140 +Requested GL_ARB_texture_multisample +0:? Sequence +0:14 Function Definition: main( ( global void) +0:14 Function Parameters: +0:16 Sequence +0:16 move second child to first child ( temp float) +0:16 'result' ( smooth out float) +0:16 direct index ( temp float) +0:16 textureFetch ( global 4-component vector of float) +0:16 'data' ( uniform sampler2DMS) +0:16 Constant: +0:16 0 (const int) +0:16 0 (const int) +0:16 Constant: +0:16 3 (const int) +0:16 Constant: +0:16 0 (const int) +0:17 Sequence +0:17 move second child to first child ( temp 2-component vector of int) +0:17 'temp' ( temp 2-component vector of int) +0:17 textureSize ( global 2-component vector of int) +0:17 'data' ( uniform sampler2DMS) +0:18 move second child to first child ( temp float) +0:18 'result' ( smooth out float) +0:18 direct index ( temp float) +0:18 textureFetch ( global 4-component vector of float) +0:18 'data1' ( uniform sampler2DMSArray) +0:18 Constant: +0:18 0 (const int) +0:18 0 (const int) +0:18 0 (const int) +0:18 Constant: +0:18 3 (const int) +0:18 Constant: +0:18 0 (const int) +0:19 Sequence +0:19 move second child to first child ( temp 3-component vector of int) +0:19 'temp1' ( temp 3-component vector of int) +0:19 textureSize ( global 3-component vector of int) +0:19 'data1' ( uniform sampler2DMSArray) +0:20 move second child to first child ( temp int) +0:20 'result1' ( smooth out int) +0:20 direct index ( temp int) +0:20 textureFetch ( global 4-component vector of int) +0:20 'data2' ( uniform isampler2DMS) +0:20 Constant: +0:20 0 (const int) +0:20 0 (const int) +0:20 Constant: +0:20 3 (const int) +0:20 Constant: +0:20 0 (const int) +0:21 move second child to first child ( temp 2-component vector of int) +0:21 'temp' ( temp 2-component vector of int) +0:21 textureSize ( global 2-component vector of int) +0:21 'data2' ( uniform isampler2DMS) +0:22 move second child to first child ( temp uint) +0:22 'result2' ( smooth out uint) +0:22 direct index ( temp uint) +0:22 textureFetch ( global 4-component vector of uint) +0:22 'data3' ( uniform usampler2DMSArray) +0:22 Constant: +0:22 0 (const int) +0:22 0 (const int) +0:22 0 (const int) +0:22 Constant: +0:22 3 (const int) +0:22 Constant: +0:22 0 (const int) +0:23 move second child to first child ( temp 3-component vector of int) +0:23 'temp1' ( temp 3-component vector of int) +0:23 textureSize ( global 3-component vector of int) +0:23 'data3' ( uniform usampler2DMSArray) +0:24 move second child to first child ( temp uint) +0:24 'result2' ( smooth out uint) +0:24 direct index ( temp uint) +0:24 textureFetch ( global 4-component vector of uint) +0:24 'data4' ( uniform usampler2DMS) +0:24 Constant: +0:24 0 (const int) +0:24 0 (const int) +0:24 Constant: +0:24 3 (const int) +0:24 Constant: +0:24 0 (const int) +0:25 move second child to first child ( temp 2-component vector of int) +0:25 'temp' ( temp 2-component vector of int) +0:25 textureSize ( global 2-component vector of int) +0:25 'data4' ( uniform usampler2DMS) +0:26 move second child to first child ( temp int) +0:26 'result1' ( smooth out int) +0:26 direct index ( temp int) +0:26 textureFetch ( global 4-component vector of int) +0:26 'data5' ( uniform isampler2DMSArray) +0:26 Constant: +0:26 0 (const int) +0:26 0 (const int) +0:26 0 (const int) +0:26 Constant: +0:26 3 (const int) +0:26 Constant: +0:26 0 (const int) +0:27 move second child to first child ( temp 3-component vector of int) +0:27 'temp1' ( temp 3-component vector of int) +0:27 textureSize ( global 3-component vector of int) +0:27 'data5' ( uniform isampler2DMSArray) +0:? Linker Objects +0:? 'result' ( smooth out float) +0:? 'result1' ( smooth out int) +0:? 'result2' ( smooth out uint) +0:? 'data' ( uniform sampler2DMS) +0:? 'data1' ( uniform sampler2DMSArray) +0:? 'data2' ( uniform isampler2DMS) +0:? 'data3' ( uniform usampler2DMSArray) +0:? 'data4' ( uniform usampler2DMS) +0:? 'data5' ( uniform isampler2DMSArray) +0:? 'gl_VertexID' ( gl_VertexId int VertexId) +0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId) + diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp index 39f5a243..dddb5957 100755 --- a/glslang/MachineIndependent/Initialize.cpp +++ b/glslang/MachineIndependent/Initialize.cpp @@ -6281,7 +6281,7 @@ void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, c { if ((ms || image) && shadow) continue; - if (ms && profile != EEsProfile && version < 150) + if (ms && profile != EEsProfile && version < 140) continue; if (ms && image && profile == EEsProfile) continue; diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index d9cb640b..d1aaf314 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1360,7 +1360,10 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction requireInt16Arithmetic(loc, "built-in function", "(u)int16 types can only be in uniform block or buffer storage"); if (builtIn && fnCandidate->getType().contains8BitInt()) requireInt8Arithmetic(loc, "built-in function", "(u)int8 types can only be in uniform block or buffer storage"); - + if (builtIn && (fnCandidate->getBuiltInOp() == EOpTextureFetch || fnCandidate->getBuiltInOp() == EOpTextureQuerySize)) { + if ((*fnCandidate)[0].type->getSampler().isMultiSample() && version <= 140) + requireExtensions(loc, 1, &E_GL_ARB_texture_multisample, fnCandidate->getName().c_str()); + } if (arguments != nullptr) { // Make sure qualifications work for these arguments. TIntermAggregate* aggregate = arguments->getAsAggregate(); diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index 621d4fe0..e8cf468b 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -295,6 +295,7 @@ INSTANTIATE_TEST_SUITE_P( "GL_ARB_draw_instanced.vert", "GL_ARB_fragment_coord_conventions.vert", "GL_ARB_bindless_texture.frag", + "GL_ARB_texture_multisample.vert", "BestMatchFunction.vert", "EndStreamPrimitive.geom", "floatBitsToInt.vert",