Emit SampleCmpLevelZero for lod/grad variants of SampleCmp.
This commit is contained in:
parent
c65248fdce
commit
dbfa686990
38
reference/opt/shaders-hlsl/frag/sample-cmp-level-zero.frag
Normal file
38
reference/opt/shaders-hlsl/frag/sample-cmp-level-zero.frag
Normal file
@ -0,0 +1,38 @@
|
||||
Texture2D<float4> uSampler2D : register(t0);
|
||||
SamplerComparisonState _uSampler2D_sampler : register(s0);
|
||||
Texture2DArray<float4> uSampler2DArray : register(t1);
|
||||
SamplerComparisonState _uSampler2DArray_sampler : register(s1);
|
||||
TextureCube<float4> uSamplerCube : register(t2);
|
||||
SamplerComparisonState _uSamplerCube_sampler : register(s2);
|
||||
TextureCubeArray<float4> uSamplerCubeArray : register(t3);
|
||||
SamplerComparisonState _uSamplerCubeArray_sampler : register(s3);
|
||||
|
||||
static float3 vUVRef;
|
||||
static float4 vDirRef;
|
||||
static float FragColor;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float3 vUVRef : TEXCOORD0;
|
||||
float4 vDirRef : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float FragColor : SV_Target0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
FragColor = (((((uSampler2D.SampleCmp(_uSampler2D_sampler, vUVRef.xy, vUVRef.z, int2(-1, -1)) + uSampler2DArray.SampleCmp(_uSampler2DArray_sampler, vDirRef.xyz, vDirRef.w, int2(-1, -1))) + uSamplerCube.SampleCmp(_uSamplerCube_sampler, vDirRef.xyz, vDirRef.w)) + uSamplerCubeArray.SampleCmp(_uSamplerCubeArray_sampler, vDirRef, 0.5f)) + uSampler2D.SampleCmpLevelZero(_uSampler2D_sampler, vUVRef.xy, vUVRef.z, int2(-1, -1))) + uSampler2DArray.SampleCmpLevelZero(_uSampler2DArray_sampler, vDirRef.xyz, vDirRef.w, int2(-1, -1))) + uSamplerCube.SampleCmpLevelZero(_uSamplerCube_sampler, vDirRef.xyz, vDirRef.w);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vUVRef = stage_input.vUVRef;
|
||||
vDirRef = stage_input.vDirRef;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = FragColor;
|
||||
return stage_output;
|
||||
}
|
45
reference/shaders-hlsl/frag/sample-cmp-level-zero.frag
Normal file
45
reference/shaders-hlsl/frag/sample-cmp-level-zero.frag
Normal file
@ -0,0 +1,45 @@
|
||||
Texture2D<float4> uSampler2D : register(t0);
|
||||
SamplerComparisonState _uSampler2D_sampler : register(s0);
|
||||
Texture2DArray<float4> uSampler2DArray : register(t1);
|
||||
SamplerComparisonState _uSampler2DArray_sampler : register(s1);
|
||||
TextureCube<float4> uSamplerCube : register(t2);
|
||||
SamplerComparisonState _uSamplerCube_sampler : register(s2);
|
||||
TextureCubeArray<float4> uSamplerCubeArray : register(t3);
|
||||
SamplerComparisonState _uSamplerCubeArray_sampler : register(s3);
|
||||
|
||||
static float3 vUVRef;
|
||||
static float4 vDirRef;
|
||||
static float FragColor;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float3 vUVRef : TEXCOORD0;
|
||||
float4 vDirRef : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float FragColor : SV_Target0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
float s0 = uSampler2D.SampleCmp(_uSampler2D_sampler, vUVRef.xy, vUVRef.z, int2(-1, -1));
|
||||
float s1 = uSampler2DArray.SampleCmp(_uSampler2DArray_sampler, vDirRef.xyz, vDirRef.w, int2(-1, -1));
|
||||
float s2 = uSamplerCube.SampleCmp(_uSamplerCube_sampler, vDirRef.xyz, vDirRef.w);
|
||||
float s3 = uSamplerCubeArray.SampleCmp(_uSamplerCubeArray_sampler, vDirRef, 0.5f);
|
||||
float l0 = uSampler2D.SampleCmpLevelZero(_uSampler2D_sampler, vUVRef.xy, vUVRef.z, int2(-1, -1));
|
||||
float l1 = uSampler2DArray.SampleCmpLevelZero(_uSampler2DArray_sampler, vDirRef.xyz, vDirRef.w, int2(-1, -1));
|
||||
float l2 = uSamplerCube.SampleCmpLevelZero(_uSamplerCube_sampler, vDirRef.xyz, vDirRef.w);
|
||||
FragColor = (((((s0 + s1) + s2) + s3) + l0) + l1) + l2;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vUVRef = stage_input.vUVRef;
|
||||
vDirRef = stage_input.vDirRef;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.FragColor = FragColor;
|
||||
return stage_output;
|
||||
}
|
24
shaders-hlsl/frag/sample-cmp-level-zero.frag
Normal file
24
shaders-hlsl/frag/sample-cmp-level-zero.frag
Normal file
@ -0,0 +1,24 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
layout(binding = 0) uniform sampler2DShadow uSampler2D;
|
||||
layout(binding = 1) uniform sampler2DArrayShadow uSampler2DArray;
|
||||
layout(binding = 2) uniform samplerCubeShadow uSamplerCube;
|
||||
layout(binding = 3) uniform samplerCubeArrayShadow uSamplerCubeArray;
|
||||
|
||||
layout(location = 0) in vec3 vUVRef;
|
||||
layout(location = 1) in vec4 vDirRef;
|
||||
|
||||
void main()
|
||||
{
|
||||
float s0 = textureOffset(uSampler2D, vUVRef, ivec2(-1));
|
||||
float s1 = textureOffset(uSampler2DArray, vDirRef, ivec2(-1));
|
||||
float s2 = texture(uSamplerCube, vDirRef);
|
||||
float s3 = texture(uSamplerCubeArray, vDirRef, 0.5);
|
||||
|
||||
float l0 = textureLodOffset(uSampler2D, vUVRef, 0.0, ivec2(-1));
|
||||
float l1 = textureGradOffset(uSampler2DArray, vDirRef, vec2(0.0), vec2(0.0), ivec2(-1));
|
||||
float l2 = textureGrad(uSamplerCube, vDirRef, vec3(0.0), vec3(0.0));
|
||||
|
||||
FragColor = s0 + s1 + s2 + s3 + l0 + l1 + l2;
|
||||
}
|
@ -1974,7 +1974,19 @@ void CompilerHLSL::emit_texture_op(const Instruction &i)
|
||||
texop += img_expr;
|
||||
|
||||
if (imgtype.image.depth)
|
||||
texop += ".SampleCmp";
|
||||
{
|
||||
if (gather)
|
||||
{
|
||||
SPIRV_CROSS_THROW("GatherCmp does not exist in HLSL.");
|
||||
}
|
||||
else if (lod || grad_x || grad_y)
|
||||
{
|
||||
// Assume we want a fixed level, and the only thing we can get in HLSL is SampleCmpLevelZero.
|
||||
texop += ".SampleCmpLevelZero";
|
||||
}
|
||||
else
|
||||
texop += ".SampleCmp";
|
||||
}
|
||||
else if (gather)
|
||||
{
|
||||
uint32_t comp_num = get<SPIRConstant>(comp).scalar();
|
||||
@ -2146,7 +2158,7 @@ void CompilerHLSL::emit_texture_op(const Instruction &i)
|
||||
expr += to_expression(dref);
|
||||
}
|
||||
|
||||
if (grad_x || grad_y)
|
||||
if (!dref && (grad_x || grad_y))
|
||||
{
|
||||
forward = forward && should_forward(grad_x);
|
||||
forward = forward && should_forward(grad_y);
|
||||
@ -2156,14 +2168,14 @@ void CompilerHLSL::emit_texture_op(const Instruction &i)
|
||||
expr += to_expression(grad_y);
|
||||
}
|
||||
|
||||
if (lod && options.shader_model >= 40 && op != OpImageFetch)
|
||||
if (!dref && lod && options.shader_model >= 40 && op != OpImageFetch)
|
||||
{
|
||||
forward = forward && should_forward(lod);
|
||||
expr += ", ";
|
||||
expr += to_expression(lod);
|
||||
}
|
||||
|
||||
if (bias && options.shader_model >= 40)
|
||||
if (!dref && bias && options.shader_model >= 40)
|
||||
{
|
||||
forward = forward && should_forward(bias);
|
||||
expr += ", ";
|
||||
|
Loading…
Reference in New Issue
Block a user