GLSL: Ensure correct signed integer type for more texture functions.

This commit is contained in:
Hans-Kristian Arntzen 2022-02-16 11:13:29 +01:00
parent 131278458e
commit 5d9a95370f
3 changed files with 89 additions and 17 deletions

View File

@ -0,0 +1,15 @@
#version 450
layout(binding = 0) uniform sampler2DMS uSamp;
layout(location = 0) out vec4 FragColor;
void main()
{
ivec2 _28 = ivec2(gl_FragCoord.xy);
FragColor.x = texelFetch(uSamp, _28, int(0u)).x;
FragColor.y = texelFetch(uSamp, _28, int(1u)).x;
FragColor.z = texelFetch(uSamp, _28, int(2u)).x;
FragColor.w = texelFetch(uSamp, _28, int(3u)).x;
}

View File

@ -0,0 +1,68 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 61
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %FragColor %gl_FragCoord
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %FragColor "FragColor"
OpName %uSamp "uSamp"
OpName %gl_FragCoord "gl_FragCoord"
OpDecorate %FragColor Location 0
OpDecorate %uSamp DescriptorSet 0
OpDecorate %uSamp Binding 0
OpDecorate %gl_FragCoord BuiltIn FragCoord
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%FragColor = OpVariable %_ptr_Output_v4float Output
%10 = OpTypeImage %float 2D 0 0 1 1 Unknown
%11 = OpTypeSampledImage %10
%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
%uSamp = OpVariable %_ptr_UniformConstant_11 UniformConstant
%_ptr_Input_v4float = OpTypePointer Input %v4float
%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
%v2float = OpTypeVector %float 2
%uint = OpTypeInt 32 0
%int = OpTypeInt 32 1
%v2int = OpTypeVector %int 2
%uint_0 = OpConstant %uint 0
%_ptr_Output_float = OpTypePointer Output %float
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_3 = OpConstant %uint 3
%main = OpFunction %void None %3
%5 = OpLabel
%14 = OpLoad %11 %uSamp
%18 = OpLoad %v4float %gl_FragCoord
%19 = OpVectorShuffle %v2float %18 %18 0 1
%22 = OpConvertFToS %v2int %19
%24 = OpImage %10 %14
%25 = OpImageFetch %v4float %24 %22 Sample %uint_0
%28 = OpCompositeExtract %float %25 0
%30 = OpAccessChain %_ptr_Output_float %FragColor %uint_0
OpStore %30 %28
%36 = OpImage %10 %14
%37 = OpImageFetch %v4float %36 %22 Sample %uint_1
%38 = OpCompositeExtract %float %37 0
%40 = OpAccessChain %_ptr_Output_float %FragColor %uint_1
OpStore %40 %38
%46 = OpImage %10 %14
%47 = OpImageFetch %v4float %46 %22 Sample %uint_2
%48 = OpCompositeExtract %float %47 0
%50 = OpAccessChain %_ptr_Output_float %FragColor %uint_2
OpStore %50 %48
%56 = OpImage %10 %14
%57 = OpImageFetch %v4float %56 %22 Sample %uint_3
%58 = OpCompositeExtract %float %57 0
%60 = OpAccessChain %_ptr_Output_float %FragColor %uint_3
OpStore %60 %58
OpReturn
OpFunctionEnd

View File

@ -7237,18 +7237,11 @@ string CompilerGLSL::to_function_args(const TextureFunctionArguments &args, bool
forward = forward && should_forward(args.lod);
farg_str += ", ";
auto &lod_expr_type = expression_type(args.lod);
// Lod expression for TexelFetch in GLSL must be int, and only int.
if (args.base.is_fetch && imgtype.image.dim != DimBuffer && !imgtype.image.ms &&
lod_expr_type.basetype != SPIRType::Int)
{
farg_str += join("int(", to_expression(args.lod), ")");
}
if (args.base.is_fetch && imgtype.image.dim != DimBuffer && !imgtype.image.ms)
farg_str += bitcast_expression(SPIRType::Int, args.lod);
else
{
farg_str += to_expression(args.lod);
}
}
}
else if (args.base.is_fetch && imgtype.image.dim != DimBuffer && !imgtype.image.ms)
@ -7261,19 +7254,19 @@ string CompilerGLSL::to_function_args(const TextureFunctionArguments &args, bool
{
forward = forward && should_forward(args.coffset);
farg_str += ", ";
farg_str += to_expression(args.coffset);
farg_str += bitcast_expression(SPIRType::Int, args.coffset);
}
else if (args.offset)
{
forward = forward && should_forward(args.offset);
farg_str += ", ";
farg_str += to_expression(args.offset);
farg_str += bitcast_expression(SPIRType::Int, args.offset);
}
if (args.sample)
{
farg_str += ", ";
farg_str += to_expression(args.sample);
farg_str += bitcast_expression(SPIRType::Int, args.sample);
}
if (args.min_lod)
@ -7300,11 +7293,7 @@ string CompilerGLSL::to_function_args(const TextureFunctionArguments &args, bool
{
forward = forward && should_forward(args.component);
farg_str += ", ";
auto &component_type = expression_type(args.component);
if (component_type.basetype == SPIRType::Int)
farg_str += to_expression(args.component);
else
farg_str += join("int(", to_expression(args.component), ")");
farg_str += bitcast_expression(SPIRType::Int, args.component);
}
*p_forward = forward;