diff --git a/test/bug/fxc/gradient_in_varying_loop/1112.wgsl b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl new file mode 100644 index 0000000000..b4dff54cd5 --- /dev/null +++ b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl @@ -0,0 +1,28 @@ +// 1112.wgsl +[[group(0), binding(0)]] var Sampler: sampler; +[[group(0), binding(1)]] var randomTexture: texture_2d; +[[group(0), binding(2)]] var depthTexture: texture_2d; + +[[stage(fragment)]] +fn main([[location(0)]] vUV : vec2) -> [[location(0)]] vec4 { + let random: vec3 = textureSample(randomTexture, Sampler, vUV).rgb; + + var i = 0; + loop { + if (i < 1) { + } else { + break; + } + let offset : vec3 = vec3(random.x); + + if (offset.x < 0.0 || offset.y < 0.0 || offset.x > 1.0 || offset.y > 1.0) { + i = i + 1; + continue; + } + + let sampleDepth : f32 = textureSample(depthTexture, Sampler, offset.xy).r; + i = i + 1; + } + + return vec4(1.0); +} diff --git a/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.hlsl b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.hlsl new file mode 100644 index 0000000000..4c8362a02a --- /dev/null +++ b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.hlsl @@ -0,0 +1,48 @@ +SamplerState tint_symbol : register(s0, space0); +Texture2D randomTexture : register(t1, space0); +Texture2D depthTexture : register(t2, space0); + +struct tint_symbol_2 { + float2 vUV : TEXCOORD0; +}; +struct tint_symbol_3 { + float4 value : SV_Target0; +}; + +float4 main_inner(float2 vUV) { + const float3 random = randomTexture.Sample(tint_symbol, vUV).rgb; + int i = 0; + [loop] while (true) { + if ((i < 1)) { + } else { + break; + } + const float3 offset = float3((random.x).xxx); + bool tint_tmp_2 = (offset.x < 0.0f); + if (!tint_tmp_2) { + tint_tmp_2 = (offset.y < 0.0f); + } + bool tint_tmp_1 = (tint_tmp_2); + if (!tint_tmp_1) { + tint_tmp_1 = (offset.x > 1.0f); + } + bool tint_tmp = (tint_tmp_1); + if (!tint_tmp) { + tint_tmp = (offset.y > 1.0f); + } + if ((tint_tmp)) { + i = (i + 1); + continue; + } + const float sampleDepth = depthTexture.Sample(tint_symbol, offset.xy).r; + i = (i + 1); + } + return float4((1.0f).xxxx); +} + +tint_symbol_3 main(tint_symbol_2 tint_symbol_1) { + const float4 inner_result = main_inner(tint_symbol_1.vUV); + tint_symbol_3 wrapper_result = (tint_symbol_3)0; + wrapper_result.value = inner_result; + return wrapper_result; +} diff --git a/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.msl b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.msl new file mode 100644 index 0000000000..7ac38ae396 --- /dev/null +++ b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.msl @@ -0,0 +1,36 @@ +#include + +using namespace metal; +struct tint_symbol_2 { + float2 vUV [[user(locn0)]]; +}; +struct tint_symbol_3 { + float4 value [[color(0)]]; +}; + +float4 tint_symbol_inner(float2 vUV, texture2d tint_symbol_4, sampler tint_symbol_5, texture2d tint_symbol_6) { + float3 const random = float4(tint_symbol_4.sample(tint_symbol_5, vUV)).rgb; + int i = 0; + while (true) { + if ((i < 1)) { + } else { + break; + } + float3 const offset = float3(random[0]); + if (((((offset[0] < 0.0f) || (offset[1] < 0.0f)) || (offset[0] > 1.0f)) || (offset[1] > 1.0f))) { + i = as_type((as_type(i) + as_type(1))); + continue; + } + float const sampleDepth = tint_symbol_6.sample(tint_symbol_5, float3(offset).xy)[0]; + i = as_type((as_type(i) + as_type(1))); + } + return float4(1.0f); +} + +fragment tint_symbol_3 tint_symbol(texture2d tint_symbol_7 [[texture(0)]], sampler tint_symbol_8 [[sampler(0)]], texture2d tint_symbol_9 [[texture(1)]], tint_symbol_2 tint_symbol_1 [[stage_in]]) { + float4 const inner_result = tint_symbol_inner(tint_symbol_1.vUV, tint_symbol_7, tint_symbol_8, tint_symbol_9); + tint_symbol_3 wrapper_result = {}; + wrapper_result.value = inner_result; + return wrapper_result; +} + diff --git a/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.spvasm b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.spvasm new file mode 100644 index 0000000000..49aff3ba86 --- /dev/null +++ b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.spvasm @@ -0,0 +1,137 @@ +; SPIR-V +; Version: 1.3 +; Generator: Google Tint Compiler; 0 +; Bound: 83 +; Schema: 0 + OpCapability Shader + OpMemoryModel Logical GLSL450 + OpEntryPoint Fragment %main "main" %vUV_1 %value + OpExecutionMode %main OriginUpperLeft + OpName %vUV_1 "vUV_1" + OpName %value "value" + OpName %Sampler "Sampler" + OpName %randomTexture "randomTexture" + OpName %depthTexture "depthTexture" + OpName %main_inner "main_inner" + OpName %vUV "vUV" + OpName %i "i" + OpName %main "main" + OpDecorate %vUV_1 Location 0 + OpDecorate %value Location 0 + OpDecorate %Sampler DescriptorSet 0 + OpDecorate %Sampler Binding 0 + OpDecorate %randomTexture DescriptorSet 0 + OpDecorate %randomTexture Binding 1 + OpDecorate %depthTexture DescriptorSet 0 + OpDecorate %depthTexture Binding 2 + %float = OpTypeFloat 32 + %v2float = OpTypeVector %float 2 +%_ptr_Input_v2float = OpTypePointer Input %v2float + %vUV_1 = OpVariable %_ptr_Input_v2float Input + %v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float + %8 = OpConstantNull %v4float + %value = OpVariable %_ptr_Output_v4float Output %8 + %11 = OpTypeSampler +%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11 + %Sampler = OpVariable %_ptr_UniformConstant_11 UniformConstant + %14 = OpTypeImage %float 2D 0 0 0 1 Unknown +%_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14 +%randomTexture = OpVariable %_ptr_UniformConstant_14 UniformConstant +%depthTexture = OpVariable %_ptr_UniformConstant_14 UniformConstant + %16 = OpTypeFunction %v4float %v2float + %23 = OpTypeSampledImage %14 + %v3float = OpTypeVector %float 3 + %int = OpTypeInt 32 1 + %int_0 = OpConstant %int 0 +%_ptr_Function_int = OpTypePointer Function %int + %31 = OpConstantNull %int + %int_1 = OpConstant %int 1 + %bool = OpTypeBool + %float_0 = OpConstant %float 0 + %float_1 = OpConstant %float 1 + %76 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1 + %void = OpTypeVoid + %77 = OpTypeFunction %void + %main_inner = OpFunction %v4float None %16 + %vUV = OpFunctionParameter %v2float + %19 = OpLabel + %i = OpVariable %_ptr_Function_int Function %31 + %21 = OpLoad %11 %Sampler + %22 = OpLoad %14 %randomTexture + %24 = OpSampledImage %23 %22 %21 + %20 = OpImageSampleImplicitLod %v4float %24 %vUV + %26 = OpVectorShuffle %v3float %20 %20 0 1 2 + OpStore %i %int_0 + OpBranch %32 + %32 = OpLabel + OpLoopMerge %33 %34 None + OpBranch %35 + %35 = OpLabel + %36 = OpLoad %int %i + %38 = OpSLessThan %bool %36 %int_1 + OpSelectionMerge %40 None + OpBranchConditional %38 %41 %42 + %41 = OpLabel + OpBranch %40 + %42 = OpLabel + OpBranch %33 + %40 = OpLabel + %43 = OpCompositeExtract %float %26 0 + %44 = OpCompositeConstruct %v3float %43 %43 %43 + %45 = OpCompositeExtract %float %44 0 + %47 = OpFOrdLessThan %bool %45 %float_0 + OpSelectionMerge %48 None + OpBranchConditional %47 %48 %49 + %49 = OpLabel + %50 = OpCompositeExtract %float %44 1 + %51 = OpFOrdLessThan %bool %50 %float_0 + OpBranch %48 + %48 = OpLabel + %52 = OpPhi %bool %47 %40 %51 %49 + OpSelectionMerge %53 None + OpBranchConditional %52 %53 %54 + %54 = OpLabel + %55 = OpCompositeExtract %float %44 0 + %57 = OpFOrdGreaterThan %bool %55 %float_1 + OpBranch %53 + %53 = OpLabel + %58 = OpPhi %bool %52 %48 %57 %54 + OpSelectionMerge %59 None + OpBranchConditional %58 %59 %60 + %60 = OpLabel + %61 = OpCompositeExtract %float %44 1 + %62 = OpFOrdGreaterThan %bool %61 %float_1 + OpBranch %59 + %59 = OpLabel + %63 = OpPhi %bool %58 %53 %62 %60 + OpSelectionMerge %64 None + OpBranchConditional %63 %65 %64 + %65 = OpLabel + %66 = OpLoad %int %i + %67 = OpIAdd %int %66 %int_1 + OpStore %i %67 + OpBranch %34 + %64 = OpLabel + %69 = OpLoad %11 %Sampler + %70 = OpLoad %14 %depthTexture + %71 = OpSampledImage %23 %70 %69 + %72 = OpVectorShuffle %v2float %44 %44 0 1 + %68 = OpImageSampleImplicitLod %v4float %71 %72 + %73 = OpCompositeExtract %float %68 0 + %74 = OpLoad %int %i + %75 = OpIAdd %int %74 %int_1 + OpStore %i %75 + OpBranch %34 + %34 = OpLabel + OpBranch %32 + %33 = OpLabel + OpReturnValue %76 + OpFunctionEnd + %main = OpFunction %void None %77 + %80 = OpLabel + %82 = OpLoad %v2float %vUV_1 + %81 = OpFunctionCall %v4float %main_inner %82 + OpStore %value %81 + OpReturn + OpFunctionEnd diff --git a/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.wgsl b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.wgsl new file mode 100644 index 0000000000..6728e4e74e --- /dev/null +++ b/test/bug/fxc/gradient_in_varying_loop/1112.wgsl.expected.wgsl @@ -0,0 +1,25 @@ +[[group(0), binding(0)]] var Sampler : sampler; + +[[group(0), binding(1)]] var randomTexture : texture_2d; + +[[group(0), binding(2)]] var depthTexture : texture_2d; + +[[stage(fragment)]] +fn main([[location(0)]] vUV : vec2) -> [[location(0)]] vec4 { + let random : vec3 = textureSample(randomTexture, Sampler, vUV).rgb; + var i = 0; + loop { + if ((i < 1)) { + } else { + break; + } + let offset : vec3 = vec3(random.x); + if (((((offset.x < 0.0) || (offset.y < 0.0)) || (offset.x > 1.0)) || (offset.y > 1.0))) { + i = (i + 1); + continue; + } + let sampleDepth : f32 = textureSample(depthTexture, Sampler, offset.xy).r; + i = (i + 1); + } + return vec4(1.0); +}