Skip to content

Commit

Permalink
[hlsl] Fix DecomposeUniformAccess to cast index to u32 for LoadVector…
Browse files Browse the repository at this point in the history
…Element

Bug: 42251045
Change-Id: Ib81df95cd9cc7c7068b07ff7ff33c9d1b0c08d0b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/203655
Commit-Queue: Antonio Maiorano <[email protected]>
Reviewed-by: James Price <[email protected]>
  • Loading branch information
amaiorano authored and Dawn LUCI CQ committed Aug 23, 2024
1 parent 9ec014c commit 8c1014e
Show file tree
Hide file tree
Showing 32 changed files with 2,092 additions and 6,291 deletions.
2 changes: 1 addition & 1 deletion src/tint/lang/hlsl/writer/access_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ void foo() {
uint x = 1u;
vector<float16_t, 4> a = tint_bitcast_to_f16(v[0u]);
float16_t b = float16_t(f16tof32(v[0u].x));
uint v_4 = (min(x, 3u) * 2u);
uint v_4 = (uint(min(x, 3u)) * 2u);
uint v_5 = v[(v_4 / 16u)][((v_4 % 16u) / 4u)];
float16_t c = float16_t(f16tof32((v_5 >> ((((v_4 % 4u) == 0u)) ? (0u) : (16u)))));
float16_t d = float16_t(f16tof32(v[0u].y));
Expand Down
3 changes: 2 additions & 1 deletion src/tint/lang/hlsl/writer/raise/decompose_uniform_access.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ struct State {
offset.byte_offset += (cnst->Value()->ValueAs<uint32_t>() * elem_byte_size);
} else {
offset.byte_offset_expr.Push(
b.Multiply(ty.u32(), lve->Index(), u32(elem_byte_size))->Result(0));
b.Multiply(ty.u32(), b.Convert(ty.u32(), lve->Index()), u32(elem_byte_size))
->Result(0));
}

auto* byte_idx = OffsetToValue(offset);
Expand Down
49 changes: 25 additions & 24 deletions src/tint/lang/hlsl/writer/raise/decompose_uniform_access_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,30 +406,31 @@ TEST_F(HlslWriterDecomposeUniformAccessTest, UniformAccessVectorF16) {
%10:f32 = hlsl.f16tof32 %9
%11:f16 = convert %10
%b:f16 = let %11
%13:u32 = mul %x, 2u
%14:u32 = div %13, 16u
%15:ptr<uniform, vec4<u32>, read> = access %v, %14
%16:u32 = mod %13, 16u
%17:u32 = div %16, 4u
%18:u32 = load_vector_element %15, %17
%19:u32 = mod %13, 4u
%20:bool = eq %19, 0u
%21:u32 = hlsl.ternary 16u, 0u, %20
%22:u32 = shr %18, %21
%23:f32 = hlsl.f16tof32 %22
%24:f16 = convert %23
%c:f16 = let %24
%26:ptr<uniform, vec4<u32>, read> = access %v, 0u
%27:u32 = load_vector_element %26, 1u
%28:f32 = hlsl.f16tof32 %27
%29:f16 = convert %28
%d:f16 = let %29
%31:ptr<uniform, vec4<u32>, read> = access %v, 0u
%32:u32 = load_vector_element %31, 1u
%33:u32 = shr %32, 16u
%34:f32 = hlsl.f16tof32 %33
%35:f16 = convert %34
%e:f16 = let %35
%13:u32 = convert %x
%14:u32 = mul %13, 2u
%15:u32 = div %14, 16u
%16:ptr<uniform, vec4<u32>, read> = access %v, %15
%17:u32 = mod %14, 16u
%18:u32 = div %17, 4u
%19:u32 = load_vector_element %16, %18
%20:u32 = mod %14, 4u
%21:bool = eq %20, 0u
%22:u32 = hlsl.ternary 16u, 0u, %21
%23:u32 = shr %19, %22
%24:f32 = hlsl.f16tof32 %23
%25:f16 = convert %24
%c:f16 = let %25
%27:ptr<uniform, vec4<u32>, read> = access %v, 0u
%28:u32 = load_vector_element %27, 1u
%29:f32 = hlsl.f16tof32 %28
%30:f16 = convert %29
%d:f16 = let %30
%32:ptr<uniform, vec4<u32>, read> = access %v, 0u
%33:u32 = load_vector_element %32, 1u
%34:u32 = shr %33, 16u
%35:f32 = hlsl.f16tof32 %34
%36:f16 = convert %35
%e:f16 = let %36
ret
}
}
Expand Down
Loading

0 comments on commit 8c1014e

Please sign in to comment.