Skip to content

Commit

Permalink
Split const-exprs.rs test into separate functions.
Browse files Browse the repository at this point in the history
Also, just use a single out variable for each type. rather than
introducing a new output variable for every test we add.
  • Loading branch information
jimblandy authored and teoxoy committed Sep 22, 2023
1 parent 3ca68d6 commit f6d8127
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 64 deletions.
22 changes: 18 additions & 4 deletions tests/in/const-exprs.wgsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
@group(0) @binding(0) var<storage, read_write> out: vec4<i32>;
@group(0) @binding(1) var<storage, read_write> out2: i32;
@group(0) @binding(2) var<storage, read_write> out3: i32;

@compute @workgroup_size(1)
fn main() {
swizzle_of_compose();
index_of_compose();
compose_three_deep();
}

// Swizzle the value of nested Compose expressions.
fn swizzle_of_compose() {
let a = vec2(1, 2);
let b = vec2(3, 4);
out = vec4(a, b).wzyx;
out = vec4(a, b).wzyx; // should assign vec4(4, 3, 2, 1);
}

out2 = vec4(a, b)[1];
// Index the value of nested Compose expressions.
fn index_of_compose() {
let a = vec2(1, 2);
let b = vec2(3, 4);
out2 += vec4(a, b)[1]; // should assign 2
}

out3 = vec4(vec3(vec2(6, 7), 8), 9)[0];
// Index the value of Compose expressions nested three deep
fn compose_three_deep() {
out2 += vec4(vec3(vec2(6, 7), 8), 9)[0]; // should assign 6
}
27 changes: 22 additions & 5 deletions tests/out/glsl/const-exprs.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,32 @@ layout(std430) buffer type_block_0Compute { ivec4 _group_0_binding_0_cs; };

layout(std430) buffer type_1_block_1Compute { int _group_0_binding_1_cs; };

layout(std430) buffer type_1_block_2Compute { int _group_0_binding_2_cs; };


void main() {
void swizzle_of_compose() {
ivec2 a = ivec2(1, 2);
ivec2 b = ivec2(3, 4);
_group_0_binding_0_cs = ivec4(4, 3, 2, 1);
_group_0_binding_1_cs = 2;
_group_0_binding_2_cs = 6;
return;
}

void index_of_compose() {
ivec2 a_1 = ivec2(1, 2);
ivec2 b_1 = ivec2(3, 4);
int _e8 = _group_0_binding_1_cs;
_group_0_binding_1_cs = (_e8 + 2);
return;
}

void compose_three_deep() {
int _e8 = _group_0_binding_1_cs;
_group_0_binding_1_cs = (_e8 + 6);
return;
}

void main() {
swizzle_of_compose();
index_of_compose();
compose_three_deep();
return;
}

31 changes: 26 additions & 5 deletions tests/out/hlsl/const-exprs.hlsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
RWByteAddressBuffer out_ : register(u0);
RWByteAddressBuffer out2_ : register(u1);
RWByteAddressBuffer out3_ : register(u2);

[numthreads(1, 1, 1)]
void main()
void swizzle_of_compose()
{
int2 a = int2(1, 2);
int2 b = int2(3, 4);
out_.Store4(0, asuint(int4(4, 3, 2, 1)));
out2_.Store(0, asuint(2));
out3_.Store(0, asuint(6));
return;
}

void index_of_compose()
{
int2 a_1 = int2(1, 2);
int2 b_1 = int2(3, 4);
int _expr8 = asint(out2_.Load(0));
out2_.Store(0, asuint((_expr8 + 2)));
return;
}

void compose_three_deep()
{
int _expr8 = asint(out2_.Load(0));
out2_.Store(0, asuint((_expr8 + 6)));
return;
}

[numthreads(1, 1, 1)]
void main()
{
swizzle_of_compose();
index_of_compose();
compose_three_deep();
return;
}
36 changes: 30 additions & 6 deletions tests/out/msl/const-exprs.msl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,39 @@
using metal::uint;


kernel void main_(
device metal::int4& out [[user(fake0)]]
, device int& out2_ [[user(fake0)]]
, device int& out3_ [[user(fake0)]]
void swizzle_of_compose(
device metal::int4& out
) {
metal::int2 a = metal::int2(1, 2);
metal::int2 b = metal::int2(3, 4);
out = metal::int4(4, 3, 2, 1);
out2_ = 2;
out3_ = 6;
return;
}

void index_of_compose(
device int& out2_
) {
metal::int2 a_1 = metal::int2(1, 2);
metal::int2 b_1 = metal::int2(3, 4);
int _e8 = out2_;
out2_ = _e8 + 2;
return;
}

void compose_three_deep(
device int& out2_
) {
int _e8 = out2_;
out2_ = _e8 + 6;
return;
}

kernel void main_(
device metal::int4& out [[user(fake0)]]
, device int& out2_ [[user(fake0)]]
) {
swizzle_of_compose(out);
index_of_compose(out2_);
compose_three_deep(out2_);
return;
}
96 changes: 58 additions & 38 deletions tests/out/spv/const-exprs.spvasm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 40
; Bound: 55
OpCapability Shader
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %17 "main"
OpExecutionMode %17 LocalSize 1 1 1
OpEntryPoint GLCompute %48 "main"
OpExecutionMode %48 LocalSize 1 1 1
OpDecorate %7 DescriptorSet 0
OpDecorate %7 Binding 0
OpDecorate %8 Block
Expand All @@ -16,10 +16,6 @@ OpDecorate %10 DescriptorSet 0
OpDecorate %10 Binding 1
OpDecorate %11 Block
OpMemberDecorate %11 0 Offset 0
OpDecorate %13 DescriptorSet 0
OpDecorate %13 Binding 2
OpDecorate %14 Block
OpMemberDecorate %14 0 Offset 0
%2 = OpTypeVoid
%4 = OpTypeInt 32 1
%3 = OpTypeVector %4 4
Expand All @@ -31,36 +27,60 @@ OpMemberDecorate %14 0 Offset 0
%11 = OpTypeStruct %4
%12 = OpTypePointer StorageBuffer %11
%10 = OpVariable %12 StorageBuffer
%14 = OpTypeStruct %4
%15 = OpTypePointer StorageBuffer %14
%13 = OpVariable %15 StorageBuffer
%18 = OpTypeFunction %2
%19 = OpTypePointer StorageBuffer %3
%21 = OpTypeInt 32 0
%20 = OpConstant %21 0
%23 = OpTypePointer StorageBuffer %4
%26 = OpConstant %4 1
%27 = OpConstant %4 2
%28 = OpConstantComposite %5 %26 %27
%29 = OpConstant %4 3
%30 = OpConstant %4 4
%31 = OpConstantComposite %5 %29 %30
%32 = OpConstantComposite %3 %30 %29 %27 %26
%33 = OpConstant %4 6
%34 = OpConstant %4 7
%35 = OpConstantComposite %5 %33 %34
%36 = OpConstant %4 8
%37 = OpConstantComposite %6 %33 %34 %36
%38 = OpConstant %4 9
%17 = OpFunction %2 None %18
%16 = OpLabel
%22 = OpAccessChain %19 %7 %20
%24 = OpAccessChain %23 %10 %20
%25 = OpAccessChain %23 %13 %20
OpBranch %39
%39 = OpLabel
OpStore %22 %32
OpStore %24 %27
OpStore %25 %33
%15 = OpTypeFunction %2
%16 = OpTypePointer StorageBuffer %3
%18 = OpTypeInt 32 0
%17 = OpConstant %18 0
%20 = OpConstant %4 1
%21 = OpConstant %4 2
%22 = OpConstantComposite %5 %20 %21
%23 = OpConstant %4 3
%24 = OpConstant %4 4
%25 = OpConstantComposite %5 %23 %24
%26 = OpConstantComposite %3 %24 %23 %21 %20
%30 = OpTypePointer StorageBuffer %4
%38 = OpConstant %4 6
%39 = OpConstant %4 7
%40 = OpConstantComposite %5 %38 %39
%41 = OpConstant %4 8
%42 = OpConstantComposite %6 %38 %39 %41
%43 = OpConstant %4 9
%14 = OpFunction %2 None %15
%13 = OpLabel
%19 = OpAccessChain %16 %7 %17
OpBranch %27
%27 = OpLabel
OpStore %19 %26
OpReturn
OpFunctionEnd
%29 = OpFunction %2 None %15
%28 = OpLabel
%31 = OpAccessChain %30 %10 %17
OpBranch %32
%32 = OpLabel
%33 = OpLoad %4 %31
%34 = OpIAdd %4 %33 %21
OpStore %31 %34
OpReturn
OpFunctionEnd
%36 = OpFunction %2 None %15
%35 = OpLabel
%37 = OpAccessChain %30 %10 %17
OpBranch %44
%44 = OpLabel
%45 = OpLoad %4 %37
%46 = OpIAdd %4 %45 %38
OpStore %37 %46
OpReturn
OpFunctionEnd
%48 = OpFunction %2 None %15
%47 = OpLabel
%49 = OpAccessChain %16 %7 %17
%50 = OpAccessChain %30 %10 %17
OpBranch %51
%51 = OpLabel
%52 = OpFunctionCall %2 %14
%53 = OpFunctionCall %2 %29
%54 = OpFunctionCall %2 %36
OpReturn
OpFunctionEnd
29 changes: 23 additions & 6 deletions tests/out/wgsl/const-exprs.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@
var<storage, read_write> out: vec4<i32>;
@group(0) @binding(1)
var<storage, read_write> out2_: i32;
@group(0) @binding(2)
var<storage, read_write> out3_: i32;

@compute @workgroup_size(1, 1, 1)
fn main() {
fn swizzle_of_compose() {
let a = vec2<i32>(1, 2);
let b = vec2<i32>(3, 4);
out = vec4<i32>(4, 3, 2, 1);
out2_ = 2;
out3_ = 6;
return;
}

fn index_of_compose() {
let a_1 = vec2<i32>(1, 2);
let b_1 = vec2<i32>(3, 4);
let _e8 = out2_;
out2_ = (_e8 + 2);
return;
}

fn compose_three_deep() {
let _e8 = out2_;
out2_ = (_e8 + 6);
return;
}

@compute @workgroup_size(1, 1, 1)
fn main() {
swizzle_of_compose();
index_of_compose();
compose_three_deep();
return;
}

0 comments on commit f6d8127

Please sign in to comment.