Skip to content

Commit

Permalink
[hlsl] Update DecomposeStorageAccess to conditionalize Convert creation.
Browse files Browse the repository at this point in the history
When generating the decomposed indices we only need to create a
`Convert` instruction if the types don't match.

Bug: 379684039
Change-Id: Iac61a657c55239387b37528327bb76a2d3690a87
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/215634
Commit-Queue: James Price <[email protected]>
Reviewed-by: James Price <[email protected]>
  • Loading branch information
dj2 authored and Dawn LUCI CQ committed Nov 19, 2024
1 parent 3d64565 commit a1ee883
Show file tree
Hide file tree
Showing 73 changed files with 866 additions and 609 deletions.
9 changes: 3 additions & 6 deletions src/tint/lang/hlsl/writer/access_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,8 @@ void foo() {
uint v_2 = 0u;
sb.GetDimensions(v_2);
uint v_3 = (((v_2 - 16u) / 128u) - 1u);
uint v_4 = (uint(min(uint(i), v_3)) * 128u);
uint v_5 = (uint(min(v, 2u)) * 32u);
float x = asfloat(sb.Load((((48u + v_4) + v_5) + (uint(min(uint(v_1), 2u)) * 4u))));
uint v_4 = (min(uint(i), v_3) * 128u);
float x = asfloat(sb.Load((((48u + v_4) + (min(v, 2u) * 32u)) + (min(uint(v_1), 2u) * 4u))));
}
)");
Expand Down Expand Up @@ -763,9 +762,7 @@ void foo() {
uint j = 1u;
uint v = 0u;
sb.GetDimensions(v);
uint v_1 = min(j, 2u);
uint v_2 = (uint(min(4u, (((v - 16u) / 128u) - 1u))) * 128u);
float x = asfloat(sb.Load(((56u + v_2) + (uint(v_1) * 32u))));
float x = asfloat(sb.Load(((56u + (min(4u, (((v - 16u) / 128u) - 1u)) * 128u)) + (min(j, 2u) * 32u))));
}
)");
Expand Down
4 changes: 2 additions & 2 deletions src/tint/lang/hlsl/writer/arraylength_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ RWByteAddressBuffer dst : register(u1);
void foo() {
uint v = 0u;
dst.GetDimensions(v);
dst.Store((0u + (uint(min(0u, ((v / 4u) - 1u))) * 4u)), 123u);
dst.Store((0u + (min(0u, ((v / 4u) - 1u)) * 4u)), 123u);
}
)");
Expand Down Expand Up @@ -275,7 +275,7 @@ cbuffer cbuffer_tint_storage_buffer_sizes : register(b0, space30) {
uint4 tint_storage_buffer_sizes[1];
};
void foo() {
dst.Store((0u + (uint(min(0u, ((tint_storage_buffer_sizes[0u].x / 4u) - 1u))) * 4u)), 123u);
dst.Store((0u + (min(0u, ((tint_storage_buffer_sizes[0u].x / 4u) - 1u)) * 4u)), 123u);
}
)");
Expand Down
7 changes: 5 additions & 2 deletions src/tint/lang/hlsl/writer/raise/decompose_storage_access.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,11 @@ struct State {
offset->byte_offset += idx_value->Value()->ValueAs<uint32_t>() * elm_size;
},
[&](core::ir::Value* val) {
offset->expr.Push(
b.Multiply(ty.u32(), b.Convert(ty.u32(), val), u32(elm_size))->Result(0));
auto* idx = val;
if (val->Type() != ty.u32()) {
idx = b.Convert(ty.u32(), val)->Result(0);
}
offset->expr.Push(b.Multiply(ty.u32(), idx, u32(elm_size))->Result(0));
},
TINT_ICE_ON_NO_MATCH);
}
Expand Down
134 changes: 61 additions & 73 deletions src/tint/lang/hlsl/writer/raise/decompose_storage_access_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1183,16 +1183,15 @@ SB = struct @align(16) {
%8:i32 = load %k
%9:u32 = convert %4
%10:u32 = mul %9, 128u
%11:u32 = convert %6
%12:u32 = mul %11, 32u
%13:u32 = convert %8
%14:u32 = mul %13, 4u
%15:u32 = add 48u, %10
%16:u32 = add %15, %12
%17:u32 = add %16, %14
%18:u32 = %sb.Load %17
%19:f32 = bitcast %18
%x:f32 = let %19
%11:u32 = mul %6, 32u
%12:u32 = convert %8
%13:u32 = mul %12, 4u
%14:u32 = add 48u, %10
%15:u32 = add %14, %11
%16:u32 = add %15, %13
%17:u32 = %sb.Load %16
%18:f32 = bitcast %17
%x:f32 = let %18
ret
}
}
Expand Down Expand Up @@ -1294,12 +1293,11 @@ SB = struct @align(16) {
$B2: {
%j:ptr<function, u32, read_write> = var, 1u
%4:u32 = load %j
%5:u32 = convert %4
%6:u32 = mul %5, 32u
%7:u32 = add 568u, %6
%8:u32 = %sb.Load %7
%9:f32 = bitcast %8
%x:f32 = let %9
%5:u32 = mul %4, 32u
%6:u32 = add 568u, %5
%7:u32 = %sb.Load %6
%8:f32 = bitcast %7
%x:f32 = let %8
ret
}
}
Expand Down Expand Up @@ -1436,15 +1434,13 @@ S2 = struct @align(16) {
%foo = @fragment func(%3:u32):void {
$B2: {
%4:u32 = convert %3
%5:u32 = mul %4, 32u
%6:u32 = convert %3
%7:u32 = mul %6, 4u
%8:ptr<function, i32, read_write> = var, 0i
%9:u32 = add 16u, %5
%10:u32 = add %9, %7
%11:i32 = convert %10
%12:void = %v.InterlockedExchange %11, 123i, %8
%4:u32 = mul %3, 32u
%5:u32 = mul %3, 4u
%6:ptr<function, i32, read_write> = var, 0i
%7:u32 = add 16u, %4
%8:u32 = add %7, %5
%9:i32 = convert %8
%10:void = %v.InterlockedExchange %9, 123i, %6
ret
}
}
Expand Down Expand Up @@ -1629,17 +1625,15 @@ S2 = struct @align(16) {
%foo = @fragment func(%3:u32):void {
$B2: {
%4:u32 = convert %3
%5:u32 = mul %4, 32u
%6:u32 = convert %3
%7:u32 = mul %6, 4u
%8:ptr<function, i32, read_write> = var, 0i
%9:u32 = add 16u, %5
%10:u32 = add %9, %7
%11:i32 = convert %10
%12:void = %v.InterlockedOr %11, 0i, %8
%13:i32 = load %8
%x:i32 = let %13
%4:u32 = mul %3, 32u
%5:u32 = mul %3, 4u
%6:ptr<function, i32, read_write> = var, 0i
%7:u32 = add 16u, %4
%8:u32 = add %7, %5
%9:i32 = convert %8
%10:void = %v.InterlockedOr %9, 0i, %6
%11:i32 = load %6
%x:i32 = let %11
ret
}
}
Expand Down Expand Up @@ -1828,18 +1822,16 @@ S2 = struct @align(16) {
%foo = @fragment func(%3:u32):void {
$B2: {
%4:u32 = convert %3
%5:u32 = mul %4, 32u
%6:u32 = convert %3
%7:u32 = mul %6, 4u
%8:ptr<function, i32, read_write> = var, 0i
%9:i32 = sub 0i, 123i
%10:u32 = add 16u, %5
%11:u32 = add %10, %7
%12:i32 = convert %11
%13:void = %v.InterlockedAdd %12, %9, %8
%14:i32 = load %8
%x:i32 = let %14
%4:u32 = mul %3, 32u
%5:u32 = mul %3, 4u
%6:ptr<function, i32, read_write> = var, 0i
%7:i32 = sub 0i, 123i
%8:u32 = add 16u, %4
%9:u32 = add %8, %5
%10:i32 = convert %9
%11:void = %v.InterlockedAdd %10, %7, %6
%12:i32 = load %6
%x:i32 = let %12
ret
}
}
Expand Down Expand Up @@ -2053,19 +2045,17 @@ __atomic_compare_exchange_result_i32 = struct @align(4) {
%foo = @fragment func(%3:u32):void {
$B2: {
%4:u32 = convert %3
%5:u32 = mul %4, 32u
%6:u32 = convert %3
%7:u32 = mul %6, 4u
%8:ptr<function, i32, read_write> = var, 0i
%9:u32 = add 16u, %5
%10:u32 = add %9, %7
%11:i32 = convert %10
%12:void = %v.InterlockedCompareExchange %11, 123i, 345i, %8
%13:i32 = load %8
%14:bool = eq %13, 123i
%15:__atomic_compare_exchange_result_i32 = construct %13, %14
%x:__atomic_compare_exchange_result_i32 = let %15
%4:u32 = mul %3, 32u
%5:u32 = mul %3, 4u
%6:ptr<function, i32, read_write> = var, 0i
%7:u32 = add 16u, %4
%8:u32 = add %7, %5
%9:i32 = convert %8
%10:void = %v.InterlockedCompareExchange %9, 123i, 345i, %6
%11:i32 = load %6
%12:bool = eq %11, 123i
%13:__atomic_compare_exchange_result_i32 = construct %11, %12
%x:__atomic_compare_exchange_result_i32 = let %13
ret
}
}
Expand Down Expand Up @@ -2331,18 +2321,16 @@ S2 = struct @align(4) {
%foo = @fragment func(%3:u32):void {
$B2: {
%4:u32 = convert %3
%5:u32 = mul %4, 12u
%6:u32 = convert %3
%7:u32 = mul %6, 4u
%8:ptr<function, u32, read_write> = var, 0u
%9:u32 = add 0u, %5
%10:u32 = add %9, %7
%11:u32 = convert %10
%12:void = %v.)" +
std::string(param.interlock) + R"( %11, 123u, %8
%13:u32 = load %8
%x:u32 = let %13
%4:u32 = mul %3, 12u
%5:u32 = mul %3, 4u
%6:ptr<function, u32, read_write> = var, 0u
%7:u32 = add 0u, %4
%8:u32 = add %7, %5
%9:u32 = convert %8
%10:void = %v.)" +
std::string(param.interlock) + R"( %9, 123u, %6
%11:u32 = load %6
%x:u32 = let %11
ret
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ float2x2 v_12(uint offset) {
}

void main_inner(uint idx) {
float scalar_f32 = asfloat(sb.Load((0u + (uint(idx) * 544u))));
int scalar_i32 = asint(sb.Load((4u + (uint(idx) * 544u))));
uint scalar_u32 = sb.Load((8u + (uint(idx) * 544u)));
float2 vec2_f32 = asfloat(sb.Load2((16u + (uint(idx) * 544u))));
int2 vec2_i32 = asint(sb.Load2((24u + (uint(idx) * 544u))));
uint2 vec2_u32 = sb.Load2((32u + (uint(idx) * 544u)));
float3 vec3_f32 = asfloat(sb.Load3((48u + (uint(idx) * 544u))));
int3 vec3_i32 = asint(sb.Load3((64u + (uint(idx) * 544u))));
uint3 vec3_u32 = sb.Load3((80u + (uint(idx) * 544u)));
float4 vec4_f32 = asfloat(sb.Load4((96u + (uint(idx) * 544u))));
int4 vec4_i32 = asint(sb.Load4((112u + (uint(idx) * 544u))));
uint4 vec4_u32 = sb.Load4((128u + (uint(idx) * 544u)));
float2x2 mat2x2_f32 = v_12((144u + (uint(idx) * 544u)));
float2x3 mat2x3_f32 = v_11((160u + (uint(idx) * 544u)));
float2x4 mat2x4_f32 = v_10((192u + (uint(idx) * 544u)));
float3x2 mat3x2_f32 = v_9((224u + (uint(idx) * 544u)));
float3x3 mat3x3_f32 = v_8((256u + (uint(idx) * 544u)));
float3x4 mat3x4_f32 = v_7((304u + (uint(idx) * 544u)));
float4x2 mat4x2_f32 = v_6((352u + (uint(idx) * 544u)));
float4x3 mat4x3_f32 = v_5((384u + (uint(idx) * 544u)));
float4x4 mat4x4_f32 = v_4((448u + (uint(idx) * 544u)));
float3 arr2_vec3_f32[2] = v((512u + (uint(idx) * 544u)));
float scalar_f32 = asfloat(sb.Load((0u + (idx * 544u))));
int scalar_i32 = asint(sb.Load((4u + (idx * 544u))));
uint scalar_u32 = sb.Load((8u + (idx * 544u)));
float2 vec2_f32 = asfloat(sb.Load2((16u + (idx * 544u))));
int2 vec2_i32 = asint(sb.Load2((24u + (idx * 544u))));
uint2 vec2_u32 = sb.Load2((32u + (idx * 544u)));
float3 vec3_f32 = asfloat(sb.Load3((48u + (idx * 544u))));
int3 vec3_i32 = asint(sb.Load3((64u + (idx * 544u))));
uint3 vec3_u32 = sb.Load3((80u + (idx * 544u)));
float4 vec4_f32 = asfloat(sb.Load4((96u + (idx * 544u))));
int4 vec4_i32 = asint(sb.Load4((112u + (idx * 544u))));
uint4 vec4_u32 = sb.Load4((128u + (idx * 544u)));
float2x2 mat2x2_f32 = v_12((144u + (idx * 544u)));
float2x3 mat2x3_f32 = v_11((160u + (idx * 544u)));
float2x4 mat2x4_f32 = v_10((192u + (idx * 544u)));
float3x2 mat3x2_f32 = v_9((224u + (idx * 544u)));
float3x3 mat3x3_f32 = v_8((256u + (idx * 544u)));
float3x4 mat3x4_f32 = v_7((304u + (idx * 544u)));
float4x2 mat4x2_f32 = v_6((352u + (idx * 544u)));
float4x3 mat4x3_f32 = v_5((384u + (idx * 544u)));
float4x4 mat4x4_f32 = v_4((448u + (idx * 544u)));
float3 arr2_vec3_f32[2] = v((512u + (idx * 544u)));
int v_13 = (tint_f32_to_i32(scalar_f32) + scalar_i32);
int v_14 = (v_13 + int(scalar_u32));
int v_15 = ((v_14 + tint_f32_to_i32(vec2_f32.x)) + vec2_i32.x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ float2x2 v_12(uint offset) {
}

void main_inner(uint idx) {
float scalar_f32 = asfloat(sb.Load((0u + (uint(idx) * 544u))));
int scalar_i32 = asint(sb.Load((4u + (uint(idx) * 544u))));
uint scalar_u32 = sb.Load((8u + (uint(idx) * 544u)));
float2 vec2_f32 = asfloat(sb.Load2((16u + (uint(idx) * 544u))));
int2 vec2_i32 = asint(sb.Load2((24u + (uint(idx) * 544u))));
uint2 vec2_u32 = sb.Load2((32u + (uint(idx) * 544u)));
float3 vec3_f32 = asfloat(sb.Load3((48u + (uint(idx) * 544u))));
int3 vec3_i32 = asint(sb.Load3((64u + (uint(idx) * 544u))));
uint3 vec3_u32 = sb.Load3((80u + (uint(idx) * 544u)));
float4 vec4_f32 = asfloat(sb.Load4((96u + (uint(idx) * 544u))));
int4 vec4_i32 = asint(sb.Load4((112u + (uint(idx) * 544u))));
uint4 vec4_u32 = sb.Load4((128u + (uint(idx) * 544u)));
float2x2 mat2x2_f32 = v_12((144u + (uint(idx) * 544u)));
float2x3 mat2x3_f32 = v_11((160u + (uint(idx) * 544u)));
float2x4 mat2x4_f32 = v_10((192u + (uint(idx) * 544u)));
float3x2 mat3x2_f32 = v_9((224u + (uint(idx) * 544u)));
float3x3 mat3x3_f32 = v_8((256u + (uint(idx) * 544u)));
float3x4 mat3x4_f32 = v_7((304u + (uint(idx) * 544u)));
float4x2 mat4x2_f32 = v_6((352u + (uint(idx) * 544u)));
float4x3 mat4x3_f32 = v_5((384u + (uint(idx) * 544u)));
float4x4 mat4x4_f32 = v_4((448u + (uint(idx) * 544u)));
float3 arr2_vec3_f32[2] = v((512u + (uint(idx) * 544u)));
float scalar_f32 = asfloat(sb.Load((0u + (idx * 544u))));
int scalar_i32 = asint(sb.Load((4u + (idx * 544u))));
uint scalar_u32 = sb.Load((8u + (idx * 544u)));
float2 vec2_f32 = asfloat(sb.Load2((16u + (idx * 544u))));
int2 vec2_i32 = asint(sb.Load2((24u + (idx * 544u))));
uint2 vec2_u32 = sb.Load2((32u + (idx * 544u)));
float3 vec3_f32 = asfloat(sb.Load3((48u + (idx * 544u))));
int3 vec3_i32 = asint(sb.Load3((64u + (idx * 544u))));
uint3 vec3_u32 = sb.Load3((80u + (idx * 544u)));
float4 vec4_f32 = asfloat(sb.Load4((96u + (idx * 544u))));
int4 vec4_i32 = asint(sb.Load4((112u + (idx * 544u))));
uint4 vec4_u32 = sb.Load4((128u + (idx * 544u)));
float2x2 mat2x2_f32 = v_12((144u + (idx * 544u)));
float2x3 mat2x3_f32 = v_11((160u + (idx * 544u)));
float2x4 mat2x4_f32 = v_10((192u + (idx * 544u)));
float3x2 mat3x2_f32 = v_9((224u + (idx * 544u)));
float3x3 mat3x3_f32 = v_8((256u + (idx * 544u)));
float3x4 mat3x4_f32 = v_7((304u + (idx * 544u)));
float4x2 mat4x2_f32 = v_6((352u + (idx * 544u)));
float4x3 mat4x3_f32 = v_5((384u + (idx * 544u)));
float4x4 mat4x4_f32 = v_4((448u + (idx * 544u)));
float3 arr2_vec3_f32[2] = v((512u + (idx * 544u)));
int v_13 = (tint_f32_to_i32(scalar_f32) + scalar_i32);
int v_14 = (v_13 + int(scalar_u32));
int v_15 = ((v_14 + tint_f32_to_i32(vec2_f32.x)) + vec2_i32.x);
Expand Down
Loading

0 comments on commit a1ee883

Please sign in to comment.