Merge pull request #356 from KhronosGroup/fix-352
Make sure image integer coords are int, not uint.
This commit is contained in:
Коммит
197e5bd7fb
|
@ -0,0 +1,17 @@
|
|||
#version 450
|
||||
|
||||
layout(binding = 1, rgba32f) uniform image2D RWIm;
|
||||
layout(binding = 0, rgba32f) uniform writeonly imageBuffer RWBuf;
|
||||
layout(binding = 1) uniform sampler2D ROIm;
|
||||
layout(binding = 0) uniform samplerBuffer ROBuf;
|
||||
|
||||
layout(location = 0) out vec4 _entryPointOutput;
|
||||
|
||||
void main()
|
||||
{
|
||||
imageStore(RWIm, ivec2(uvec2(10u)), vec4(10.0, 0.5, 8.0, 2.0));
|
||||
vec4 _69 = imageLoad(RWIm, ivec2(uvec2(30u)));
|
||||
imageStore(RWBuf, int(80u), _69);
|
||||
_entryPointOutput = (_69 + texelFetch(ROIm, ivec2(uvec2(50u, 60u)), 0)) + texelFetch(ROBuf, int(80u));
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#version 450
|
||||
|
||||
layout(binding = 1, rgba32f) uniform image2D RWIm;
|
||||
layout(binding = 0, rgba32f) uniform writeonly imageBuffer RWBuf;
|
||||
layout(binding = 1) uniform sampler2D ROIm;
|
||||
layout(binding = 0) uniform samplerBuffer ROBuf;
|
||||
|
||||
layout(location = 0) out vec4 _entryPointOutput;
|
||||
|
||||
vec4 _main()
|
||||
{
|
||||
vec4 storeTemp = vec4(10.0, 0.5, 8.0, 2.0);
|
||||
imageStore(RWIm, ivec2(uvec2(10u)), storeTemp);
|
||||
vec4 v = imageLoad(RWIm, ivec2(uvec2(30u)));
|
||||
imageStore(RWBuf, int(80u), v);
|
||||
v += texelFetch(ROIm, ivec2(uvec2(50u, 60u)), 0);
|
||||
v += texelFetch(ROBuf, int(80u));
|
||||
return v;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 _45 = _main();
|
||||
_entryPointOutput = _45;
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 2
|
||||
; Bound: 63
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpCapability SampledBuffer
|
||||
OpCapability ImageBuffer
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main" %_entryPointOutput
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpSource HLSL 500
|
||||
OpName %main "main"
|
||||
OpName %_main_ "@main("
|
||||
OpName %storeTemp "storeTemp"
|
||||
OpName %RWIm "RWIm"
|
||||
OpName %v "v"
|
||||
OpName %RWBuf "RWBuf"
|
||||
OpName %ROIm "ROIm"
|
||||
OpName %ROBuf "ROBuf"
|
||||
OpName %_entryPointOutput "@entryPointOutput"
|
||||
OpDecorate %RWIm DescriptorSet 0
|
||||
OpDecorate %RWIm Binding 1
|
||||
OpDecorate %RWBuf DescriptorSet 0
|
||||
OpDecorate %RWBuf Binding 0
|
||||
OpDecorate %ROIm DescriptorSet 0
|
||||
OpDecorate %ROIm Binding 1
|
||||
OpDecorate %ROBuf DescriptorSet 0
|
||||
OpDecorate %ROBuf Binding 0
|
||||
OpDecorate %_entryPointOutput Location 0
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%8 = OpTypeFunction %v4float
|
||||
%_ptr_Function_v4float = OpTypePointer Function %v4float
|
||||
%float_10 = OpConstant %float 10
|
||||
%float_0_5 = OpConstant %float 0.5
|
||||
%float_8 = OpConstant %float 8
|
||||
%float_2 = OpConstant %float 2
|
||||
%17 = OpConstantComposite %v4float %float_10 %float_0_5 %float_8 %float_2
|
||||
%18 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
|
||||
%_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
|
||||
%RWIm = OpVariable %_ptr_UniformConstant_18 UniformConstant
|
||||
%uint = OpTypeInt 32 0
|
||||
%v2uint = OpTypeVector %uint 2
|
||||
%uint_10 = OpConstant %uint 10
|
||||
%25 = OpConstantComposite %v2uint %uint_10 %uint_10
|
||||
%uint_30 = OpConstant %uint 30
|
||||
%30 = OpConstantComposite %v2uint %uint_30 %uint_30
|
||||
%32 = OpTypeImage %float Buffer 0 0 0 2 Rgba32f
|
||||
%_ptr_UniformConstant_32 = OpTypePointer UniformConstant %32
|
||||
%RWBuf = OpVariable %_ptr_UniformConstant_32 UniformConstant
|
||||
%uint_80 = OpConstant %uint 80
|
||||
%38 = OpTypeImage %float 2D 0 0 0 1 Unknown
|
||||
%SampledImage = OpTypeSampledImage %38
|
||||
%_ptr_UniformConstant_38 = OpTypePointer UniformConstant %SampledImage
|
||||
%ROIm = OpVariable %_ptr_UniformConstant_38 UniformConstant
|
||||
%uint_50 = OpConstant %uint 50
|
||||
%uint_60 = OpConstant %uint 60
|
||||
%44 = OpConstantComposite %v2uint %uint_50 %uint_60
|
||||
%int = OpTypeInt 32 1
|
||||
%int_0 = OpConstant %int 0
|
||||
%50 = OpTypeImage %float Buffer 0 0 0 1 Rgba32f
|
||||
%_ptr_UniformConstant_50 = OpTypePointer UniformConstant %50
|
||||
%ROBuf = OpVariable %_ptr_UniformConstant_50 UniformConstant
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%_entryPointOutput = OpVariable %_ptr_Output_v4float Output
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%62 = OpFunctionCall %v4float %_main_
|
||||
OpStore %_entryPointOutput %62
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%_main_ = OpFunction %v4float None %8
|
||||
%10 = OpLabel
|
||||
%storeTemp = OpVariable %_ptr_Function_v4float Function
|
||||
%v = OpVariable %_ptr_Function_v4float Function
|
||||
OpStore %storeTemp %17
|
||||
%21 = OpLoad %18 %RWIm
|
||||
%26 = OpLoad %v4float %storeTemp
|
||||
OpImageWrite %21 %25 %26
|
||||
%28 = OpLoad %18 %RWIm
|
||||
%31 = OpImageRead %v4float %28 %30
|
||||
OpStore %v %31
|
||||
%35 = OpLoad %32 %RWBuf
|
||||
%37 = OpLoad %v4float %v
|
||||
OpImageWrite %35 %uint_80 %37
|
||||
%41 = OpLoad %SampledImage %ROIm
|
||||
%ROImage = OpImage %38 %41
|
||||
%47 = OpImageFetch %v4float %ROImage %44 Lod %int_0
|
||||
%48 = OpLoad %v4float %v
|
||||
%49 = OpFAdd %v4float %48 %47
|
||||
OpStore %v %49
|
||||
%53 = OpLoad %50 %ROBuf
|
||||
%54 = OpImageFetch %v4float %53 %uint_80
|
||||
%55 = OpLoad %v4float %v
|
||||
%56 = OpFAdd %v4float %55 %54
|
||||
OpStore %v %56
|
||||
%57 = OpLoad %v4float %v
|
||||
OpReturnValue %57
|
||||
OpFunctionEnd
|
|
@ -3451,6 +3451,15 @@ string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &imgtype, boo
|
|||
// Only enclose the UV expression if needed.
|
||||
auto coord_expr = (*swizzle_expr == '\0') ? to_expression(coord) : (to_enclosed_expression(coord) + swizzle_expr);
|
||||
|
||||
// texelFetch only takes int, not uint.
|
||||
auto &coord_type = expression_type(coord);
|
||||
if (coord_type.basetype == SPIRType::UInt)
|
||||
{
|
||||
auto expected_type = coord_type;
|
||||
expected_type.basetype = SPIRType::Int;
|
||||
coord_expr = bitcast_expression(expected_type, coord_type.basetype, coord_expr);
|
||||
}
|
||||
|
||||
// textureLod on sampler2DArrayShadow and samplerCubeShadow does not exist in GLSL for some reason.
|
||||
// To emulate this, we will have to use textureGrad with a constant gradient of 0.
|
||||
// The workaround will assert that the LOD is in fact constant 0, or we cannot emit correct code.
|
||||
|
@ -6366,6 +6375,12 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
|||
}
|
||||
else
|
||||
{
|
||||
// imageLoad only accepts int coords, not uint.
|
||||
auto coord_expr = to_expression(ops[3]);
|
||||
auto target_coord_type = expression_type(ops[3]);
|
||||
target_coord_type.basetype = SPIRType::Int;
|
||||
coord_expr = bitcast_expression(target_coord_type, expression_type(ops[3]).basetype, coord_expr);
|
||||
|
||||
// Plain image load/store.
|
||||
if (type.image.ms)
|
||||
{
|
||||
|
@ -6374,11 +6389,11 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
|||
SPIRV_CROSS_THROW("Multisampled image used in OpImageRead, but unexpected operand mask was used.");
|
||||
|
||||
uint32_t samples = ops[5];
|
||||
imgexpr = join("imageLoad(", to_expression(ops[2]), ", ", to_expression(ops[3]), ", ",
|
||||
to_expression(samples), ")");
|
||||
imgexpr =
|
||||
join("imageLoad(", to_expression(ops[2]), ", ", coord_expr, ", ", to_expression(samples), ")");
|
||||
}
|
||||
else
|
||||
imgexpr = join("imageLoad(", to_expression(ops[2]), ", ", to_expression(ops[3]), ")");
|
||||
imgexpr = join("imageLoad(", to_expression(ops[2]), ", ", coord_expr, ")");
|
||||
|
||||
imgexpr = remap_swizzle(get<SPIRType>(result_type), 4, imgexpr);
|
||||
pure = false;
|
||||
|
@ -6435,17 +6450,23 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
|||
auto store_type = value_type;
|
||||
store_type.vecsize = 4;
|
||||
|
||||
// imageStore only accepts int coords, not uint.
|
||||
auto coord_expr = to_expression(ops[1]);
|
||||
auto target_coord_type = expression_type(ops[1]);
|
||||
target_coord_type.basetype = SPIRType::Int;
|
||||
coord_expr = bitcast_expression(target_coord_type, expression_type(ops[1]).basetype, coord_expr);
|
||||
|
||||
if (type.image.ms)
|
||||
{
|
||||
uint32_t operands = ops[3];
|
||||
if (operands != ImageOperandsSampleMask || length != 5)
|
||||
SPIRV_CROSS_THROW("Multisampled image used in OpImageWrite, but unexpected operand mask was used.");
|
||||
uint32_t samples = ops[4];
|
||||
statement("imageStore(", to_expression(ops[0]), ", ", to_expression(ops[1]), ", ", to_expression(samples),
|
||||
", ", remap_swizzle(store_type, value_type.vecsize, to_expression(ops[2])), ");");
|
||||
statement("imageStore(", to_expression(ops[0]), ", ", coord_expr, ", ", to_expression(samples), ", ",
|
||||
remap_swizzle(store_type, value_type.vecsize, to_expression(ops[2])), ");");
|
||||
}
|
||||
else
|
||||
statement("imageStore(", to_expression(ops[0]), ", ", to_expression(ops[1]), ", ",
|
||||
statement("imageStore(", to_expression(ops[0]), ", ", coord_expr, ", ",
|
||||
remap_swizzle(store_type, value_type.vecsize, to_expression(ops[2])), ");");
|
||||
|
||||
if (var && variable_storage_is_aliased(*var))
|
||||
|
|
Загрузка…
Ссылка в новой задаче