Add exhaustive image query to HLSL.
Need to strip this down somehow ...
This commit is contained in:
parent
7c58f15928
commit
1bc5b70752
278
reference/shaders-hlsl/frag/image-query.frag
Normal file
278
reference/shaders-hlsl/frag/image-query.frag
Normal file
@ -0,0 +1,278 @@
|
||||
Texture1D<float4> uSampler1D : register(t0);
|
||||
SamplerState _uSampler1D_sampler : register(s0);
|
||||
Texture2D<float4> uSampler2D : register(t1);
|
||||
SamplerState _uSampler2D_sampler : register(s1);
|
||||
Texture2DArray<float4> uSampler2DArray : register(t2);
|
||||
SamplerState _uSampler2DArray_sampler : register(s2);
|
||||
Texture3D<float4> uSampler3D : register(t3);
|
||||
SamplerState _uSampler3D_sampler : register(s3);
|
||||
TextureCube<float4> uSamplerCube : register(t4);
|
||||
SamplerState _uSamplerCube_sampler : register(s4);
|
||||
TextureCubeArray<float4> uSamplerCubeArray : register(t5);
|
||||
SamplerState _uSamplerCubeArray_sampler : register(s5);
|
||||
Buffer<float4> uSamplerBuffer : register(t6);
|
||||
Texture2D<float4> uSamplerMS : register(t7);
|
||||
SamplerState _uSamplerMS_sampler : register(s7);
|
||||
Texture2DArray<float4> uSamplerMSArray : register(t8);
|
||||
SamplerState _uSamplerMSArray_sampler : register(s8);
|
||||
|
||||
uint SPIRV_Cross_textureSize(Texture1D<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint ret;
|
||||
Tex.GetDimensions(Level, ret.x, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint SPIRV_Cross_textureSize(Texture1D<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint ret;
|
||||
Tex.GetDimensions(Level, ret.x, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint SPIRV_Cross_textureSize(Texture1D<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint ret;
|
||||
Tex.GetDimensions(Level, ret.x, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture1DArray<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture1DArray<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture1DArray<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture2D<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture2D<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture2D<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture2DArray<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture2DArray<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture2DArray<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture3D<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture3D<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture3D<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint SPIRV_Cross_textureSize(Buffer<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint ret;
|
||||
Tex.GetDimensions(ret.x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint SPIRV_Cross_textureSize(Buffer<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint ret;
|
||||
Tex.GetDimensions(ret.x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint SPIRV_Cross_textureSize(Buffer<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint ret;
|
||||
Tex.GetDimensions(ret.x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(TextureCube<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(TextureCube<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(TextureCube<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(TextureCubeArray<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(TextureCubeArray<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(TextureCubeArray<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture2DMS<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture2DMS<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint2 SPIRV_Cross_textureSize(Texture2DMS<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint2 ret;
|
||||
Tex.GetDimensions(ret.x, ret.y, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture2DMSArray<float4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture2DMSArray<int4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint3 SPIRV_Cross_textureSize(Texture2DMSArray<uint4> Tex, uint Level, out uint Param)
|
||||
{
|
||||
uint3 ret;
|
||||
Tex.GetDimensions(ret.x, ret.y, ret.z, Param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
uint _17_dummy_parameter;
|
||||
int a = int(SPIRV_Cross_textureSize(uSampler1D, uint(0), _17_dummy_parameter));
|
||||
uint _27_dummy_parameter;
|
||||
int2 b = int2(SPIRV_Cross_textureSize(uSampler2D, uint(0), _27_dummy_parameter));
|
||||
uint _37_dummy_parameter;
|
||||
int3 c = int3(SPIRV_Cross_textureSize(uSampler2DArray, uint(0), _37_dummy_parameter));
|
||||
uint _45_dummy_parameter;
|
||||
int3 d = int3(SPIRV_Cross_textureSize(uSampler3D, uint(0), _45_dummy_parameter));
|
||||
uint _53_dummy_parameter;
|
||||
int2 e = int2(SPIRV_Cross_textureSize(uSamplerCube, uint(0), _53_dummy_parameter));
|
||||
uint _61_dummy_parameter;
|
||||
int3 f = int3(SPIRV_Cross_textureSize(uSamplerCubeArray, uint(0), _61_dummy_parameter));
|
||||
uint _69_dummy_parameter;
|
||||
int g = int(SPIRV_Cross_textureSize(uSamplerBuffer, 0u, _69_dummy_parameter));
|
||||
uint _77_dummy_parameter;
|
||||
int2 h = int2(SPIRV_Cross_textureSize(uSamplerMS, 0u, _77_dummy_parameter));
|
||||
uint _85_dummy_parameter;
|
||||
int3 i = int3(SPIRV_Cross_textureSize(uSamplerMSArray, 0u, _85_dummy_parameter));
|
||||
int _89;
|
||||
SPIRV_Cross_textureSize(uSampler1D, 0u, _89);
|
||||
int l0 = int(_89);
|
||||
int _93;
|
||||
SPIRV_Cross_textureSize(uSampler2D, 0u, _93);
|
||||
int l1 = int(_93);
|
||||
int _97;
|
||||
SPIRV_Cross_textureSize(uSampler2DArray, 0u, _97);
|
||||
int l2 = int(_97);
|
||||
int _101;
|
||||
SPIRV_Cross_textureSize(uSampler3D, 0u, _101);
|
||||
int l3 = int(_101);
|
||||
int _105;
|
||||
SPIRV_Cross_textureSize(uSamplerCube, 0u, _105);
|
||||
int l4 = int(_105);
|
||||
int _109;
|
||||
SPIRV_Cross_textureSize(uSamplerCubeArray, 0u, _109);
|
||||
int l5 = int(_109);
|
||||
int _113;
|
||||
SPIRV_Cross_textureSize(uSamplerMS, 0u, _113);
|
||||
int s0 = int(_113);
|
||||
int _117;
|
||||
SPIRV_Cross_textureSize(uSamplerMSArray, 0u, _117);
|
||||
int s1 = int(_117);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
frag_main();
|
||||
}
|
33
shaders-hlsl/frag/image-query.frag
Normal file
33
shaders-hlsl/frag/image-query.frag
Normal file
@ -0,0 +1,33 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0) uniform sampler1D uSampler1D;
|
||||
layout(binding = 1) uniform sampler2D uSampler2D;
|
||||
layout(binding = 2) uniform sampler2DArray uSampler2DArray;
|
||||
layout(binding = 3) uniform sampler3D uSampler3D;
|
||||
layout(binding = 4) uniform samplerCube uSamplerCube;
|
||||
layout(binding = 5) uniform samplerCubeArray uSamplerCubeArray;
|
||||
layout(binding = 6) uniform samplerBuffer uSamplerBuffer;
|
||||
layout(binding = 7) uniform sampler2DMS uSamplerMS;
|
||||
layout(binding = 8) uniform sampler2DMSArray uSamplerMSArray;
|
||||
|
||||
void main()
|
||||
{
|
||||
int a = textureSize(uSampler1D, 0);
|
||||
ivec2 b = textureSize(uSampler2D, 0);
|
||||
ivec3 c = textureSize(uSampler2DArray, 0);
|
||||
ivec3 d = textureSize(uSampler3D, 0);
|
||||
ivec2 e = textureSize(uSamplerCube, 0);
|
||||
ivec3 f = textureSize(uSamplerCubeArray, 0);
|
||||
int g = textureSize(uSamplerBuffer);
|
||||
ivec2 h = textureSize(uSamplerMS);
|
||||
ivec3 i = textureSize(uSamplerMSArray);
|
||||
|
||||
int l0 = textureQueryLevels(uSampler1D);
|
||||
int l1 = textureQueryLevels(uSampler2D);
|
||||
int l2 = textureQueryLevels(uSampler2DArray);
|
||||
int l3 = textureQueryLevels(uSampler3D);
|
||||
int l4 = textureQueryLevels(uSamplerCube);
|
||||
int l5 = textureQueryLevels(uSamplerCubeArray);
|
||||
int s0 = textureSamples(uSamplerMS);
|
||||
int s1 = textureSamples(uSamplerMSArray);
|
||||
}
|
@ -5666,11 +5666,18 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
|
||||
case OpImageQueryLevels:
|
||||
{
|
||||
uint32_t result_type = ops[0];
|
||||
uint32_t id = ops[1];
|
||||
|
||||
if (!options.es && options.version < 430)
|
||||
require_extension("GL_ARB_texture_query_levels");
|
||||
if (options.es)
|
||||
SPIRV_CROSS_THROW("textureQueryLevels not supported in ES profile.");
|
||||
UFOP(textureQueryLevels);
|
||||
|
||||
auto expr = join("textureQueryLevels(", to_expression(ops[2]), ")");
|
||||
auto &restype = get<SPIRType>(ops[0]);
|
||||
expr = bitcast_expression(restype, SPIRType::Int, expr);
|
||||
emit_op(result_type, id, expr, true);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -5706,7 +5713,6 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
uint32_t id = ops[1];
|
||||
|
||||
auto expr = join("textureSize(", to_expression(ops[2]), ", ", bitcast_expression(SPIRType::Int, ops[3]), ")");
|
||||
|
||||
auto &restype = get<SPIRType>(ops[0]);
|
||||
expr = bitcast_expression(restype, SPIRType::Int, expr);
|
||||
emit_op(result_type, id, expr, true);
|
||||
|
125
spirv_hlsl.cpp
125
spirv_hlsl.cpp
@ -938,6 +938,62 @@ void CompilerHLSL::emit_resources()
|
||||
statement("");
|
||||
}
|
||||
}
|
||||
|
||||
if (requires_textureSize)
|
||||
{
|
||||
static const char *types[] = { "float4", "int4", "uint4" };
|
||||
static const char *dims[] = { "Texture1D", "Texture1DArray", "Texture2D", "Texture2DArray",
|
||||
"Texture3D", "Buffer", "TextureCube", "TextureCubeArray",
|
||||
"Texture2DMS", "Texture2DMSArray" };
|
||||
|
||||
static const bool has_lod[] = { true, true, true, true, true, false, true, true, false, false };
|
||||
|
||||
static const char *ret_types[] = {
|
||||
"uint", "uint2", "uint2", "uint3", "uint3", "uint", "uint2", "uint3", "uint2", "uint3",
|
||||
};
|
||||
|
||||
static const uint32_t return_arguments[] = {
|
||||
1, 2, 2, 3, 3, 1, 2, 3, 2, 3,
|
||||
};
|
||||
|
||||
for (auto &dim : dims)
|
||||
{
|
||||
uint32_t index = uint32_t(&dim - dims);
|
||||
|
||||
for (auto &type : types)
|
||||
{
|
||||
statement(ret_types[index], " SPIRV_Cross_textureSize(", dim, "<", type,
|
||||
"> Tex, uint Level, out uint Param)");
|
||||
begin_scope();
|
||||
statement(ret_types[index], " ret;");
|
||||
switch (return_arguments[index])
|
||||
{
|
||||
case 1:
|
||||
if (has_lod[index])
|
||||
statement("Tex.GetDimensions(Level, ret.x, Param);");
|
||||
else
|
||||
statement("Tex.GetDimensions(ret.x);");
|
||||
break;
|
||||
case 2:
|
||||
if (has_lod[index])
|
||||
statement("Tex.GetDimensions(Level, ret.x, ret.y, Param);");
|
||||
else
|
||||
statement("Tex.GetDimensions(ret.x, ret.y, Param);");
|
||||
break;
|
||||
case 3:
|
||||
if (has_lod[index])
|
||||
statement("Tex.GetDimensions(Level, ret.x, ret.y, ret.z, Param);");
|
||||
else
|
||||
statement("Tex.GetDimensions(ret.x, ret.y, ret.z, Param);");
|
||||
break;
|
||||
}
|
||||
|
||||
statement("return ret;");
|
||||
end_scope();
|
||||
statement("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string CompilerHLSL::layout_for_member(const SPIRType &, uint32_t)
|
||||
@ -2337,6 +2393,75 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
|
||||
break;
|
||||
}
|
||||
|
||||
case OpImageQuerySizeLod:
|
||||
{
|
||||
auto result_type = ops[0];
|
||||
auto id = ops[1];
|
||||
|
||||
if (!requires_textureSize)
|
||||
{
|
||||
requires_textureSize = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
|
||||
auto dummy_samples_levels = join(get_fallback_name(id), "_dummy_parameter");
|
||||
statement("uint ", dummy_samples_levels, ";");
|
||||
|
||||
auto expr = join("SPIRV_Cross_textureSize(", to_expression(ops[2]), ", ",
|
||||
bitcast_expression(SPIRType::UInt, ops[3]), ", ", dummy_samples_levels, ")");
|
||||
|
||||
auto &restype = get<SPIRType>(ops[0]);
|
||||
expr = bitcast_expression(restype, SPIRType::UInt, expr);
|
||||
emit_op(result_type, id, expr, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case OpImageQuerySize:
|
||||
{
|
||||
auto result_type = ops[0];
|
||||
auto id = ops[1];
|
||||
|
||||
if (!requires_textureSize)
|
||||
{
|
||||
requires_textureSize = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
|
||||
auto dummy_samples_levels = join(get_fallback_name(id), "_dummy_parameter");
|
||||
statement("uint ", dummy_samples_levels, ";");
|
||||
|
||||
auto expr = join("SPIRV_Cross_textureSize(", to_expression(ops[2]), ", 0u, ", dummy_samples_levels, ")");
|
||||
auto &restype = get<SPIRType>(ops[0]);
|
||||
expr = bitcast_expression(restype, SPIRType::UInt, expr);
|
||||
emit_op(result_type, id, expr, true);
|
||||
break;
|
||||
}
|
||||
|
||||
case OpImageQuerySamples:
|
||||
case OpImageQueryLevels:
|
||||
{
|
||||
auto result_type = ops[0];
|
||||
auto id = ops[1];
|
||||
|
||||
if (!requires_textureSize)
|
||||
{
|
||||
requires_textureSize = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
|
||||
// Keep it simple and do not emit special variants to make this look nicer ...
|
||||
// This stuff is barely, if ever, used.
|
||||
forced_temporaries.insert(id);
|
||||
auto &type = get<SPIRType>(result_type);
|
||||
statement(variable_decl(type, to_name(id)), ";");
|
||||
statement("SPIRV_Cross_textureSize(", to_expression(ops[2]), ", 0u, ", to_name(id), ");");
|
||||
|
||||
auto &restype = get<SPIRType>(ops[0]);
|
||||
auto expr = bitcast_expression(restype, SPIRType::UInt, to_name(id));
|
||||
set<SPIRExpression>(id, expr, result_type, true);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
CompilerGLSL::emit_instruction(instruction);
|
||||
break;
|
||||
|
@ -98,6 +98,7 @@ private:
|
||||
Options options;
|
||||
bool requires_op_fmod = false;
|
||||
bool requires_textureProj = false;
|
||||
bool requires_textureSize = false;
|
||||
|
||||
void emit_builtin_variables();
|
||||
bool require_output = false;
|
||||
|
Loading…
Reference in New Issue
Block a user