Skip to content

Commit

Permalink
Add exhaustive image query to HLSL.
Browse files Browse the repository at this point in the history
Need to strip this down somehow ...
  • Loading branch information
HansKristian-Work committed Sep 20, 2017
1 parent 7c58f15 commit 1bc5b70
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 2 deletions.
278 changes: 278 additions & 0 deletions reference/shaders-hlsl/frag/image-query.frag
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions shaders-hlsl/frag/image-query.frag
Original file line number Diff line number Diff line change
@@ -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);
}
10 changes: 8 additions & 2 deletions spirv_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 1bc5b70

Please sign in to comment.