Support the textureQueryLOD at #extension GL_ARB_texture_query_lod.

Signed-off-by: ZhiqianXia <xzq0528@outlook.com>
This commit is contained in:
ZhiqianXia 2021-08-02 16:20:02 +08:00
parent 0db0010d3c
commit 78de10954e
6 changed files with 209 additions and 47 deletions

View File

@ -111,8 +111,8 @@ void qlodFail()
vec2 pf2;
vec3 pf3;
lod = textureQueryLod(samp1D, pf); // ERROR, extension GL_ARB_texture_query_lod needed
lod = textureQueryLod(samp2Ds, pf2); // ERROR, extension GL_ARB_texture_query_lod needed
lod = textureQueryLOD(samp1D, pf); // ERROR, extension GL_ARB_texture_query_lod needed
lod = textureQueryLOD(samp2Ds, pf2); // ERROR, extension GL_ARB_texture_query_lod needed
}
#extension GL_ARB_texture_query_lod : enable
@ -138,21 +138,21 @@ void qlodPass()
vec2 pf2;
vec3 pf3;
lod = textureQueryLod(samp1D, pf);
lod = textureQueryLod(isamp2D, pf2);
lod = textureQueryLod(usamp3D, pf3);
lod = textureQueryLod(sampCube, pf3);
lod = textureQueryLod(isamp1DA, pf);
lod = textureQueryLod(usamp2DA, pf2);
lod = textureQueryLOD(samp1D, pf);
lod = textureQueryLOD(isamp2D, pf2);
lod = textureQueryLOD(usamp3D, pf3);
lod = textureQueryLOD(sampCube, pf3);
lod = textureQueryLOD(isamp1DA, pf);
lod = textureQueryLOD(usamp2DA, pf2);
lod = textureQueryLod(samp1Ds, pf);
lod = textureQueryLod(samp2Ds, pf2);
lod = textureQueryLod(sampCubes, pf3);
lod = textureQueryLod(samp1DAs, pf);
lod = textureQueryLod(samp2DAs, pf2);
lod = textureQueryLOD(samp1Ds, pf);
lod = textureQueryLOD(samp2Ds, pf2);
lod = textureQueryLOD(sampCubes, pf3);
lod = textureQueryLOD(samp1DAs, pf);
lod = textureQueryLOD(samp2DAs, pf2);
lod = textureQueryLod(sampBuf, pf); // ERROR
lod = textureQueryLod(sampRect, pf2); // ERROR
lod = textureQueryLOD(sampBuf, pf); // ERROR
lod = textureQueryLOD(sampRect, pf2); // ERROR
}
// Test extension GL_EXT_shader_integer_mix

View File

@ -10,11 +10,11 @@ ERROR: 0:53: 'double' : must be qualified as flat in
ERROR: 0:57: '=' : cannot convert from ' global double' to ' global int'
ERROR: 0:80: 'floatBitsToInt' : required extension not requested: GL_ARB_shader_bit_encoding
ERROR: 0:100: 'packSnorm2x16' : required extension not requested: GL_ARB_shading_language_packing
ERROR: 0:114: 'textureQueryLod' : required extension not requested: GL_ARB_texture_query_lod
ERROR: 0:115: 'textureQueryLod' : required extension not requested: GL_ARB_texture_query_lod
ERROR: 0:154: 'textureQueryLod' : no matching overloaded function found
ERROR: 0:114: 'textureQueryLOD' : required extension not requested: GL_ARB_texture_query_lod
ERROR: 0:115: 'textureQueryLOD' : required extension not requested: GL_ARB_texture_query_lod
ERROR: 0:154: 'textureQueryLOD' : no matching overloaded function found
ERROR: 0:154: 'assign' : cannot convert from ' const float' to ' temp 2-component vector of float'
ERROR: 0:155: 'textureQueryLod' : no matching overloaded function found
ERROR: 0:155: 'textureQueryLOD' : no matching overloaded function found
ERROR: 0:155: 'assign' : cannot convert from ' const float' to ' temp 2-component vector of float'
ERROR: 0:183: 'mix' : required extension not requested: GL_EXT_shader_integer_mix
ERROR: 18 compilation errors. No code generated.

View File

@ -0,0 +1,115 @@
textureQueryLOD.frag
WARNING: 0:7: '#extension' : extension is only partially supported: GL_ARB_gpu_shader5
Shader version: 150
Requested GL_ARB_gpu_shader5
Requested GL_ARB_texture_query_lod
0:? Sequence
0:24 Function Definition: main( ( global void)
0:24 Function Parameters:
0:26 Sequence
0:26 switch
0:26 condition
0:26 'funct' ( uniform int)
0:26 body
0:26 Sequence
0:28 case: with expression
0:28 Constant:
0:28 0 (const int)
0:? Sequence
0:29 Sequence
0:29 move second child to first child ( temp 2-component vector of int)
0:29 'iv2' ( temp 2-component vector of int)
0:29 textureSize ( global 2-component vector of int)
0:29 'sampler' ( uniform sampler2DShadow)
0:29 Constant:
0:29 0 (const int)
0:31 Sequence
0:31 move second child to first child ( temp 2-component vector of float)
0:31 'fv2' ( temp 2-component vector of float)
0:31 textureQueryLod ( global 2-component vector of float)
0:31 'sampler' ( uniform sampler2DShadow)
0:31 Constant:
0:31 0.000000
0:31 0.000000
0:33 move second child to first child ( temp 4-component vector of float)
0:33 'color' ( out 4-component vector of float)
0:33 Construct vec4 ( temp 4-component vector of float)
0:33 Convert int to float ( temp 2-component vector of float)
0:33 'iv2' ( temp 2-component vector of int)
0:33 'fv2' ( temp 2-component vector of float)
0:34 Branch: Break
0:35 default:
0:? Sequence
0:36 move second child to first child ( temp 4-component vector of float)
0:36 'color' ( out 4-component vector of float)
0:36 Constant:
0:36 1.000000
0:36 1.000000
0:36 1.000000
0:36 1.000000
0:37 Branch: Break
0:? Linker Objects
0:? 'vUV' ( smooth in 2-component vector of float)
0:? 'color' ( out 4-component vector of float)
0:? 'sampler' ( uniform sampler2DShadow)
0:? 'funct' ( uniform int)
Linked fragment stage:
Shader version: 150
Requested GL_ARB_gpu_shader5
Requested GL_ARB_texture_query_lod
0:? Sequence
0:24 Function Definition: main( ( global void)
0:24 Function Parameters:
0:26 Sequence
0:26 switch
0:26 condition
0:26 'funct' ( uniform int)
0:26 body
0:26 Sequence
0:28 case: with expression
0:28 Constant:
0:28 0 (const int)
0:? Sequence
0:29 Sequence
0:29 move second child to first child ( temp 2-component vector of int)
0:29 'iv2' ( temp 2-component vector of int)
0:29 textureSize ( global 2-component vector of int)
0:29 'sampler' ( uniform sampler2DShadow)
0:29 Constant:
0:29 0 (const int)
0:31 Sequence
0:31 move second child to first child ( temp 2-component vector of float)
0:31 'fv2' ( temp 2-component vector of float)
0:31 textureQueryLod ( global 2-component vector of float)
0:31 'sampler' ( uniform sampler2DShadow)
0:31 Constant:
0:31 0.000000
0:31 0.000000
0:33 move second child to first child ( temp 4-component vector of float)
0:33 'color' ( out 4-component vector of float)
0:33 Construct vec4 ( temp 4-component vector of float)
0:33 Convert int to float ( temp 2-component vector of float)
0:33 'iv2' ( temp 2-component vector of int)
0:33 'fv2' ( temp 2-component vector of float)
0:34 Branch: Break
0:35 default:
0:? Sequence
0:36 move second child to first child ( temp 4-component vector of float)
0:36 'color' ( out 4-component vector of float)
0:36 Constant:
0:36 1.000000
0:36 1.000000
0:36 1.000000
0:36 1.000000
0:37 Branch: Break
0:? Linker Objects
0:? 'vUV' ( smooth in 2-component vector of float)
0:? 'color' ( out 4-component vector of float)
0:? 'sampler' ( uniform sampler2DShadow)
0:? 'funct' ( uniform int)

39
Test/textureQueryLOD.frag Normal file
View File

@ -0,0 +1,39 @@
#version 150
#ifdef GL_ARB_texture_query_lod
#extension GL_ARB_texture_query_lod : enable
#endif
#ifdef GL_ARB_gpu_shader5
#extension GL_ARB_gpu_shader5 : enable
#endif
#ifdef GL_ES
precision highp float;
#endif
in vec2 vUV; // vert->frag
out vec4 color; // frag->fb
#define UV vUV
#define bias 1.5
#define TEX 128.0
#define offset ivec2(1,1)
uniform highp sampler2DShadow sampler;
uniform int funct;
void main (void)
{
switch (funct)
{
case 0:
ivec2 iv2 = textureSize(sampler, 0);
#ifdef GL_ARB_texture_query_lod
vec2 fv2 = textureQueryLOD(sampler, vec2(0.0, 0.0));
#endif
color = vec4(iv2,fv2);
break;
default:
color = vec4(1.0, 1.0, 1.0, 1.0);
break;
}
}

View File

@ -316,6 +316,7 @@ const CustomFunction CustomFunctions[] = {
{ EOpTextureQuerySize, "textureSize", nullptr },
{ EOpTextureQueryLod, "textureQueryLod", nullptr },
{ EOpTextureQueryLod, "textureQueryLOD", nullptr }, // extension GL_ARB_texture_query_lod
{ EOpTextureQueryLevels, "textureQueryLevels", nullptr },
{ EOpTextureQuerySamples, "textureSamples", nullptr },
{ EOpTexture, "texture", nullptr },
@ -6307,38 +6308,44 @@ void TBuiltIns::addQueryFunctions(TSampler sampler, const TString& typeName, int
//
// textureQueryLod(), fragment stage only
// Also enabled with extension GL_ARB_texture_query_lod
// Extension GL_ARB_texture_query_lod says that textureQueryLOD() also exist at extension.
if (profile != EEsProfile && version >= 150 && sampler.isCombined() && sampler.dim != EsdRect &&
! sampler.isMultiSample() && ! sampler.isBuffer()) {
for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) {
if (f16TexAddr && sampler.type != EbtFloat16)
continue;
stageBuiltins[EShLangFragment].append("vec2 textureQueryLod(");
stageBuiltins[EShLangFragment].append(typeName);
if (dimMap[sampler.dim] == 1)
if (f16TexAddr)
stageBuiltins[EShLangFragment].append(", float16_t");
else
stageBuiltins[EShLangFragment].append(", float");
else {
if (f16TexAddr)
stageBuiltins[EShLangFragment].append(", f16vec");
else
stageBuiltins[EShLangFragment].append(", vec");
stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]);
}
stageBuiltins[EShLangFragment].append(");\n");
}
stageBuiltins[EShLangCompute].append("vec2 textureQueryLod(");
stageBuiltins[EShLangCompute].append(typeName);
if (dimMap[sampler.dim] == 1)
stageBuiltins[EShLangCompute].append(", float");
else {
stageBuiltins[EShLangCompute].append(", vec");
stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]);
const TString funcName[2] = {"vec2 textureQueryLod(", "vec2 textureQueryLOD("};
for (int i = 0; i < 2; ++i){
for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) {
if (f16TexAddr && sampler.type != EbtFloat16)
continue;
stageBuiltins[EShLangFragment].append(funcName[i]);
stageBuiltins[EShLangFragment].append(typeName);
if (dimMap[sampler.dim] == 1)
if (f16TexAddr)
stageBuiltins[EShLangFragment].append(", float16_t");
else
stageBuiltins[EShLangFragment].append(", float");
else {
if (f16TexAddr)
stageBuiltins[EShLangFragment].append(", f16vec");
else
stageBuiltins[EShLangFragment].append(", vec");
stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]);
}
stageBuiltins[EShLangFragment].append(");\n");
}
stageBuiltins[EShLangCompute].append(funcName[i]);
stageBuiltins[EShLangCompute].append(typeName);
if (dimMap[sampler.dim] == 1)
stageBuiltins[EShLangCompute].append(", float");
else {
stageBuiltins[EShLangCompute].append(", vec");
stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]);
}
stageBuiltins[EShLangCompute].append(");\n");
}
stageBuiltins[EShLangCompute].append(");\n");
}
//
@ -8118,7 +8125,7 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
}
if (profile != EEsProfile && version < 400) {
symbolTable.setFunctionExtensions("textureQueryLod", 1, &E_GL_ARB_texture_query_lod);
symbolTable.setFunctionExtensions("textureQueryLOD", 1, &E_GL_ARB_texture_query_lod);
}
if (profile != EEsProfile && version >= 460) {

View File

@ -284,6 +284,7 @@ INSTANTIATE_TEST_SUITE_P(
"textureoffset_sampler2darrayshadow.vert",
"atomicAdd.comp",
"GL_ARB_gpu_shader5.u2i.vert",
"textureQueryLOD.frag",
})),
FileNameAsCustomTestSuffix
);