diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index bea22ce0bb..a03f4a6115 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -1663,7 +1663,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, if (!EmitExpression(out, texture)) return false; - bool pack_mip_in_coords = false; + bool pack_level_in_coords = false; uint32_t hlsl_ret_width = 4u; switch (intrinsic->Type()) { @@ -1689,7 +1689,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, break; case sem::IntrinsicType::kTextureLoad: out << ".Load("; - pack_mip_in_coords = true; + if (!texture_type->Is()) { + pack_level_in_coords = true; + } break; case sem::IntrinsicType::kTextureStore: out << "["; @@ -1723,11 +1725,20 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, return EmitExpression(out, packed); }; + auto emit_vector_appended_with_level = [&](tint::ast::Expression* vector) { + if (auto* level = arg(Usage::kLevel)) { + auto* packed = AppendVector(&builder_, vector, level); + return EmitExpression(out, packed); + } + return emit_vector_appended_with_i32_zero(vector); + }; + if (auto* array_index = arg(Usage::kArrayIndex)) { // Array index needs to be appended to the coordinates. auto* packed = AppendVector(&builder_, param_coords, array_index); - if (pack_mip_in_coords) { - if (!emit_vector_appended_with_i32_zero(packed)) { + if (pack_level_in_coords) { + // Then mip level needs to be appended to the coordinates. + if (!emit_vector_appended_with_level(packed)) { return false; } } else { @@ -1735,9 +1746,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, return false; } } - } else if (pack_mip_in_coords) { - // Mip level needs to be appended to the coordinates, but is always zero. - if (!emit_vector_appended_with_i32_zero(param_coords)) { + } else if (pack_level_in_coords) { + // Mip level needs to be appended to the coordinates. + if (!emit_vector_appended_with_level(param_coords)) { return false; } } else { @@ -1748,6 +1759,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, for (auto usage : {Usage::kDepthRef, Usage::kBias, Usage::kLevel, Usage::kDdx, Usage::kDdy, Usage::kSampleIndex, Usage::kOffset}) { + if (usage == Usage::kLevel && pack_level_in_coords) { + continue; // mip level already packed in coordinates. + } if (auto* e = arg(usage)) { out << ", "; if (!EmitExpression(out, e)) { diff --git a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc index b868e74f10..e898665daa 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc @@ -292,39 +292,39 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kSampleCompareLevelDepthCubeArrayF32: return R"(tint_symbol.SampleCmpLevelZero(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)"; case ValidTextureOverload::kLoad1dLevelF32: - return R"(tint_symbol.Load(int2(1, 0), 3);)"; + return R"(tint_symbol.Load(int2(1, 3));)"; case ValidTextureOverload::kLoad1dLevelU32: - return R"(tint_symbol.Load(int2(1, 0), 3);)"; + return R"(tint_symbol.Load(int2(1, 3));)"; case ValidTextureOverload::kLoad1dLevelI32: - return R"(tint_symbol.Load(int2(1, 0), 3);)"; + return R"(tint_symbol.Load(int2(1, 3));)"; case ValidTextureOverload::kLoad2dLevelF32: - return R"(tint_symbol.Load(int3(1, 2, 0), 3);)"; + return R"(tint_symbol.Load(int3(1, 2, 3));)"; case ValidTextureOverload::kLoad2dLevelU32: - return R"(tint_symbol.Load(int3(1, 2, 0), 3);)"; + return R"(tint_symbol.Load(int3(1, 2, 3));)"; case ValidTextureOverload::kLoad2dLevelI32: - return R"(tint_symbol.Load(int3(1, 2, 0), 3);)"; + return R"(tint_symbol.Load(int3(1, 2, 3));)"; case ValidTextureOverload::kLoad2dArrayLevelF32: - return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4);)"; + return R"(tint_symbol.Load(int4(1, 2, 3, 4));)"; case ValidTextureOverload::kLoad2dArrayLevelU32: - return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4);)"; + return R"(tint_symbol.Load(int4(1, 2, 3, 4));)"; case ValidTextureOverload::kLoad2dArrayLevelI32: - return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4);)"; + return R"(tint_symbol.Load(int4(1, 2, 3, 4));)"; case ValidTextureOverload::kLoad3dLevelF32: - return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4);)"; + return R"(tint_symbol.Load(int4(1, 2, 3, 4));)"; case ValidTextureOverload::kLoad3dLevelU32: - return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4);)"; + return R"(tint_symbol.Load(int4(1, 2, 3, 4));)"; case ValidTextureOverload::kLoad3dLevelI32: - return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4);)"; + return R"(tint_symbol.Load(int4(1, 2, 3, 4));)"; case ValidTextureOverload::kLoadMultisampled2dF32: - return R"(tint_symbol.Load(int3(1, 2, 0), 3);)"; + return R"(tint_symbol.Load(int2(1, 2), 3);)"; case ValidTextureOverload::kLoadMultisampled2dU32: - return R"(tint_symbol.Load(int3(1, 2, 0), 3);)"; + return R"(tint_symbol.Load(int2(1, 2), 3);)"; case ValidTextureOverload::kLoadMultisampled2dI32: - return R"(tint_symbol.Load(int3(1, 2, 0), 3);)"; + return R"(tint_symbol.Load(int2(1, 2), 3);)"; case ValidTextureOverload::kLoadDepth2dLevelF32: - return R"(tint_symbol.Load(int3(1, 2, 0), 3).x;)"; + return R"(tint_symbol.Load(int3(1, 2, 3)).x;)"; case ValidTextureOverload::kLoadDepth2dArrayLevelF32: - return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4).x;)"; + return R"(tint_symbol.Load(int4(1, 2, 3, 4)).x;)"; case ValidTextureOverload::kLoadStorageRO1dRgba32float: return R"(tint_symbol.Load(int2(1, 0));)"; case ValidTextureOverload::kLoadStorageRO2dRgba8unorm: diff --git a/test/bug/tint/757.wgsl.expected.hlsl b/test/bug/tint/757.wgsl.expected.hlsl index 52433846d7..67bbffb65a 100644 --- a/test/bug/tint/757.wgsl.expected.hlsl +++ b/test/bug/tint/757.wgsl.expected.hlsl @@ -14,7 +14,7 @@ void main(tint_symbol_1 tint_symbol) { const uint3 GlobalInvocationID = tint_symbol.GlobalInvocationID; uint flatIndex = ((((2u * 2u) * GlobalInvocationID.z) + (2u * GlobalInvocationID.y)) + GlobalInvocationID.x); flatIndex = (flatIndex * 1u); - float4 texel = myTexture.Load(int4(GlobalInvocationID.xy, 0, 0), 0); + float4 texel = myTexture.Load(int4(GlobalInvocationID.xy, 0, 0)); { uint i = 0u; while (true) { diff --git a/test/bug/tint/827.wgsl.expected.hlsl b/test/bug/tint/827.wgsl.expected.hlsl index b3581d6196..81a67c2cca 100644 --- a/test/bug/tint/827.wgsl.expected.hlsl +++ b/test/bug/tint/827.wgsl.expected.hlsl @@ -9,6 +9,6 @@ struct tint_symbol_1 { [numthreads(1, 1, 1)] void main(tint_symbol_1 tint_symbol) { const uint3 GlobalInvocationId = tint_symbol.GlobalInvocationId; - result.Store((4u * ((GlobalInvocationId.y * width) + GlobalInvocationId.x)), asuint(tex.Load(int3(int(GlobalInvocationId.x), int(GlobalInvocationId.y), 0), 0).x)); + result.Store((4u * ((GlobalInvocationId.y * width) + GlobalInvocationId.x)), asuint(tex.Load(int3(int(GlobalInvocationId.x), int(GlobalInvocationId.y), 0)).x)); return; } diff --git a/test/bug/tint/913.wgsl.expected.hlsl b/test/bug/tint/913.wgsl.expected.hlsl index 1ad9ee7770..a39e60e6c1 100644 --- a/test/bug/tint/913.wgsl.expected.hlsl +++ b/test/bug/tint/913.wgsl.expected.hlsl @@ -46,7 +46,7 @@ void main(tint_symbol_2 tint_symbol_1) { if ((tint_tmp_2)) { bool tint_tmp_5 = success; if (tint_tmp_5) { - tint_tmp_5 = all((tint_symbol.Load(int3(dstTexCoord, 0), 0) == nonCoveredColor)); + tint_tmp_5 = all((tint_symbol.Load(int3(dstTexCoord, 0)) == nonCoveredColor)); } success = (tint_tmp_5); } else { @@ -59,8 +59,8 @@ void main(tint_symbol_2 tint_symbol_1) { if ((uniforms[scalar_offset_8 / 4][scalar_offset_8 % 4] == 1u)) { srcTexCoord.y = ((uint(srcSize.y) - srcTexCoord.y) - 1u); } - const float4 srcColor = src.Load(int3(srcTexCoord, 0), 0); - const float4 dstColor = tint_symbol.Load(int3(dstTexCoord, 0), 0); + const float4 srcColor = src.Load(int3(srcTexCoord, 0)); + const float4 dstColor = tint_symbol.Load(int3(dstTexCoord, 0)); const int scalar_offset_9 = (4u) / 4; if ((uniforms[scalar_offset_9 / 4][scalar_offset_9 % 4] == 2u)) { bool tint_tmp_7 = success; diff --git a/test/intrinsics/gen/textureLoad/19cf87.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/19cf87.wgsl.expected.hlsl index b4d522185c..6430b2c737 100644 --- a/test/intrinsics/gen/textureLoad/19cf87.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/19cf87.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2D arg_0 : register(t0, space1); void textureLoad_19cf87() { - float res = arg_0.Load(int3(0, 0, 0), 1).x; + float res = arg_0.Load(int3(0, 0, 1)).x; } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/1b8588.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/1b8588.wgsl.expected.hlsl index be00fcfd5a..ec7997dc21 100644 --- a/test/intrinsics/gen/textureLoad/1b8588.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/1b8588.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture1D arg_0 : register(t0, space1); void textureLoad_1b8588() { - uint4 res = arg_0.Load(int2(1, 0), 1); + uint4 res = arg_0.Load(int2(1, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/1f2016.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/1f2016.wgsl.expected.hlsl index 84a611dd3c..a165236b39 100644 --- a/test/intrinsics/gen/textureLoad/1f2016.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/1f2016.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture3D arg_0 : register(t0, space1); void textureLoad_1f2016() { - float4 res = arg_0.Load(int4(0, 0, 0, 0), 1); + float4 res = arg_0.Load(int4(0, 0, 0, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/484344.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/484344.wgsl.expected.hlsl index 7afc56ae8a..5a2bb89cc6 100644 --- a/test/intrinsics/gen/textureLoad/484344.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/484344.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2D arg_0 : register(t0, space1); void textureLoad_484344() { - float4 res = arg_0.Load(int3(0, 0, 0), 1); + float4 res = arg_0.Load(int3(0, 0, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/4fd803.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/4fd803.wgsl.expected.hlsl index d686909ba3..1579b35550 100644 --- a/test/intrinsics/gen/textureLoad/4fd803.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/4fd803.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture3D arg_0 : register(t0, space1); void textureLoad_4fd803() { - int4 res = arg_0.Load(int4(0, 0, 0, 0), 1); + int4 res = arg_0.Load(int4(0, 0, 0, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/5a2f9d.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/5a2f9d.wgsl.expected.hlsl index c26d43f36d..34c04afee6 100644 --- a/test/intrinsics/gen/textureLoad/5a2f9d.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/5a2f9d.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture1D arg_0 : register(t0, space1); void textureLoad_5a2f9d() { - int4 res = arg_0.Load(int2(1, 0), 1); + int4 res = arg_0.Load(int2(1, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/6154d4.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/6154d4.wgsl.expected.hlsl index 9cba1a79d8..6e07c0716c 100644 --- a/test/intrinsics/gen/textureLoad/6154d4.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/6154d4.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2D arg_0 : register(t0, space1); void textureLoad_6154d4() { - uint4 res = arg_0.Load(int3(0, 0, 0), 1); + uint4 res = arg_0.Load(int3(0, 0, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/79e697.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/79e697.wgsl.expected.hlsl index 041fa85cf7..53a8b2a10d 100644 --- a/test/intrinsics/gen/textureLoad/79e697.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/79e697.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2DArray arg_0 : register(t0, space1); void textureLoad_79e697() { - int4 res = arg_0.Load(int4(0, 0, 1, 0), 1); + int4 res = arg_0.Load(int4(0, 0, 1, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/7c90e5.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/7c90e5.wgsl.expected.hlsl index 262be4968b..01721d08a9 100644 --- a/test/intrinsics/gen/textureLoad/7c90e5.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/7c90e5.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2DArray arg_0 : register(t0, space1); void textureLoad_7c90e5() { - uint4 res = arg_0.Load(int4(0, 0, 1, 0), 1); + uint4 res = arg_0.Load(int4(0, 0, 1, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/81c381.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/81c381.wgsl.expected.hlsl index 577804d8cc..b0549a904c 100644 --- a/test/intrinsics/gen/textureLoad/81c381.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/81c381.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture1D arg_0 : register(t0, space1); void textureLoad_81c381() { - float4 res = arg_0.Load(int2(1, 0), 1); + float4 res = arg_0.Load(int2(1, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/87be85.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/87be85.wgsl.expected.hlsl index 5a67763e7e..22ff303d6b 100644 --- a/test/intrinsics/gen/textureLoad/87be85.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/87be85.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2DArray arg_0 : register(t0, space1); void textureLoad_87be85() { - float4 res = arg_0.Load(int4(0, 0, 1, 0), 1); + float4 res = arg_0.Load(int4(0, 0, 1, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/8acf41.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/8acf41.wgsl.expected.hlsl index f11e717b11..3e21a826bc 100644 --- a/test/intrinsics/gen/textureLoad/8acf41.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/8acf41.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2D arg_0 : register(t0, space1); void textureLoad_8acf41() { - float4 res = arg_0.Load(int3(0, 0, 0), 0); + float4 res = arg_0.Load(int3(0, 0, 0)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/9b2667.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/9b2667.wgsl.expected.hlsl index e513119df2..0a448f008a 100644 --- a/test/intrinsics/gen/textureLoad/9b2667.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/9b2667.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2DArray arg_0 : register(t0, space1); void textureLoad_9b2667() { - float res = arg_0.Load(int4(0, 0, 1, 0), 1).x; + float res = arg_0.Load(int4(0, 0, 1, 1)).x; } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/a583c9.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/a583c9.wgsl.expected.hlsl index df3f8edc67..cfeed505de 100644 --- a/test/intrinsics/gen/textureLoad/a583c9.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/a583c9.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2DMS arg_0 : register(t0, space1); void textureLoad_a583c9() { - float4 res = arg_0.Load(int3(0, 0, 0), 1); + float4 res = arg_0.Load(int2(0, 0), 1); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/a9a9f5.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/a9a9f5.wgsl.expected.hlsl index 31ea021fa7..74b4671b33 100644 --- a/test/intrinsics/gen/textureLoad/a9a9f5.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/a9a9f5.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture3D arg_0 : register(t0, space1); void textureLoad_a9a9f5() { - uint4 res = arg_0.Load(int4(0, 0, 0, 0), 1); + uint4 res = arg_0.Load(int4(0, 0, 0, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/c2a480.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/c2a480.wgsl.expected.hlsl index cc25969773..b1eabd4e24 100644 --- a/test/intrinsics/gen/textureLoad/c2a480.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/c2a480.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2D arg_0 : register(t0, space1); void textureLoad_c2a480() { - int4 res = arg_0.Load(int3(0, 0, 0), 1); + int4 res = arg_0.Load(int3(0, 0, 1)); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/c378ee.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/c378ee.wgsl.expected.hlsl index f866c1d805..d1da070779 100644 --- a/test/intrinsics/gen/textureLoad/c378ee.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/c378ee.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2DMS arg_0 : register(t0, space1); void textureLoad_c378ee() { - uint4 res = arg_0.Load(int3(0, 0, 0), 1); + uint4 res = arg_0.Load(int2(0, 0), 1); } struct tint_symbol { diff --git a/test/intrinsics/gen/textureLoad/e3d2cc.wgsl.expected.hlsl b/test/intrinsics/gen/textureLoad/e3d2cc.wgsl.expected.hlsl index 512b7a96ff..977c75fd4f 100644 --- a/test/intrinsics/gen/textureLoad/e3d2cc.wgsl.expected.hlsl +++ b/test/intrinsics/gen/textureLoad/e3d2cc.wgsl.expected.hlsl @@ -1,7 +1,7 @@ Texture2DMS arg_0 : register(t0, space1); void textureLoad_e3d2cc() { - int4 res = arg_0.Load(int3(0, 0, 0), 1); + int4 res = arg_0.Load(int2(0, 0), 1); } struct tint_symbol {