Skip to content

Commit 35a38e7

Browse files
authored
impr: Do not pack entry-point variables (#2303)
1 parent a28d796 commit 35a38e7

File tree

74 files changed

+1165
-1675
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1165
-1675
lines changed

apps/typegpu-docs/tests/individual-example-tests/3d-fish.test.ts

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,11 @@ describe('3d fish example', () => {
7777
fish_data_1[x] = data;
7878
}
7979
80-
struct mainCompute_Input {
81-
@builtin(global_invocation_id) id: vec3u,
82-
}
83-
84-
@compute @workgroup_size(256, 1, 1) fn mainCompute(in: mainCompute_Input) {
85-
if (any(in.id >= sizeUniform)) {
80+
@compute @workgroup_size(256, 1, 1) fn mainCompute(@builtin(global_invocation_id) id: vec3u) {
81+
if (any(id >= sizeUniform)) {
8682
return;
8783
}
88-
wrappedCallback(in.id.x, in.id.y, in.id.z);
84+
wrappedCallback(id.x, id.y, id.z);
8985
}
9086
9187
@group(0) @binding(0) var<uniform> sizeUniform: vec3u;
@@ -229,15 +225,11 @@ describe('3d fish example', () => {
229225
(*nextFishData_1).direction = direction;
230226
}
231227
232-
struct mainCompute_Input {
233-
@builtin(global_invocation_id) id: vec3u,
234-
}
235-
236-
@compute @workgroup_size(256, 1, 1) fn mainCompute(in: mainCompute_Input) {
237-
if (any(in.id >= sizeUniform)) {
228+
@compute @workgroup_size(256, 1, 1) fn mainCompute(@builtin(global_invocation_id) id: vec3u) {
229+
if (any(id >= sizeUniform)) {
238230
return;
239231
}
240-
simulate(in.id.x, in.id.y, in.id.z);
232+
simulate(id.x, id.y, id.z);
241233
}
242234
243235
struct ModelData {
@@ -293,18 +285,11 @@ describe('3d fish example', () => {
293285
@location(5) @interpolate(flat) applySeaDesaturation: u32,
294286
}
295287
296-
struct vertexShader_Input {
297-
@location(0) modelPosition: vec3f,
298-
@location(1) modelNormal: vec3f,
299-
@location(2) textureUV: vec2f,
300-
@builtin(instance_index) instanceIndex: u32,
301-
}
302-
303-
@vertex fn vertexShader(input: vertexShader_Input) -> vertexShader_Output {
304-
let currentModelData = (&modelData[input.instanceIndex]);
305-
var wavedVertex = PosAndNormal(input.modelPosition, input.modelNormal);
288+
@vertex fn vertexShader(@location(0) _arg_modelPosition: vec3f, @location(1) _arg_modelNormal: vec3f, @location(2) _arg_textureUV: vec2f, @builtin(instance_index) _arg_instanceIndex: u32) -> vertexShader_Output {
289+
let currentModelData = (&modelData[_arg_instanceIndex]);
290+
var wavedVertex = PosAndNormal(_arg_modelPosition, _arg_modelNormal);
306291
if (((*currentModelData).applySinWave == 1u)) {
307-
wavedVertex = applySinWave(input.instanceIndex, PosAndNormal(input.modelPosition, input.modelNormal), currentTime);
292+
wavedVertex = applySinWave(_arg_instanceIndex, PosAndNormal(_arg_modelPosition, _arg_modelNormal), currentTime);
308293
}
309294
var direction = normalize((*currentModelData).direction);
310295
let yaw = (-(atan2(direction.z, direction.x)) + 3.141592653589793f);
@@ -317,7 +302,16 @@ describe('3d fish example', () => {
317302
var worldNormal = normalize(((yawMatrix * pitchMatrix) * vec4f(wavedVertex.normal, 1f)).xyz);
318303
let worldPositionUniform = (&worldPosition);
319304
var canvasPosition = ((camera.projection * camera.view) * (*worldPositionUniform));
320-
return vertexShader_Output(worldPosition.xyz, worldNormal, canvasPosition, (*currentModelData).variant, input.textureUV, (*currentModelData).applySeaFog, (*currentModelData).applySeaDesaturation);
305+
return vertexShader_Output(worldPosition.xyz, worldNormal, canvasPosition, (*currentModelData).variant, _arg_textureUV, (*currentModelData).applySeaFog, (*currentModelData).applySeaDesaturation);
306+
}
307+
308+
struct fragmentShader_Input {
309+
@location(0) worldPosition: vec3f,
310+
@location(1) worldNormal: vec3f,
311+
@location(2) variant: f32,
312+
@location(3) textureUV: vec2f,
313+
@location(4) @interpolate(flat) applySeaFog: u32,
314+
@location(5) @interpolate(flat) applySeaDesaturation: u32,
321315
}
322316
323317
@group(0) @binding(1) var modelTexture: texture_2d<f32>;
@@ -424,39 +418,29 @@ describe('3d fish example', () => {
424418
return vec3f(r, g, b);
425419
}
426420
427-
struct fragmentShader_Input {
428-
@location(0) worldPosition: vec3f,
429-
@location(1) worldNormal: vec3f,
430-
@builtin(position) canvasPosition: vec4f,
431-
@location(2) variant: f32,
432-
@location(3) textureUV: vec2f,
433-
@location(4) @interpolate(flat) applySeaFog: u32,
434-
@location(5) @interpolate(flat) applySeaDesaturation: u32,
435-
}
436-
437-
@fragment fn fragmentShader(input: fragmentShader_Input) -> @location(0) vec4f {
438-
var textureColorWithAlpha = textureSample(modelTexture, sampler_1, input.textureUV);
421+
@fragment fn fragmentShader(_arg_0: fragmentShader_Input) -> @location(0) vec4f {
422+
var textureColorWithAlpha = textureSample(modelTexture, sampler_1, _arg_0.textureUV);
439423
var textureColor = textureColorWithAlpha.rgb;
440424
var ambient = ((0.5f * textureColor) * vec3f(0.800000011920929, 0.800000011920929, 1));
441-
let cosTheta = dot(input.worldNormal, vec3f(-0.2357022613286972, 0.9428090453147888, -0.2357022613286972));
425+
let cosTheta = dot(_arg_0.worldNormal, vec3f(-0.2357022613286972, 0.9428090453147888, -0.2357022613286972));
442426
var diffuse = ((max(0f, cosTheta) * textureColor) * vec3f(0.800000011920929, 0.800000011920929, 1));
443-
var viewSource = normalize((camera.position.xyz - input.worldPosition));
444-
var reflectSource = normalize(reflect(vec3f(0.2357022613286972, -0.9428090453147888, 0.2357022613286972), input.worldNormal));
427+
var viewSource = normalize((camera.position.xyz - _arg_0.worldPosition));
428+
var reflectSource = normalize(reflect(vec3f(0.2357022613286972, -0.9428090453147888, 0.2357022613286972), _arg_0.worldNormal));
445429
let specularStrength = pow(max(0f, dot(viewSource, reflectSource)), 16f);
446430
var specular = (specularStrength * vec3f(0.800000011920929, 0.800000011920929, 1));
447431
var lightedColor = ((ambient + diffuse) + specular);
448-
let distanceFromCamera = length((camera.position.xyz - input.worldPosition));
432+
let distanceFromCamera = length((camera.position.xyz - _arg_0.worldPosition));
449433
var desaturatedColor = lightedColor;
450-
if ((input.applySeaDesaturation == 1u)) {
434+
if ((_arg_0.applySeaDesaturation == 1u)) {
451435
let desaturationFactor = (-(atan2(((distanceFromCamera - 5f) / 10f), 1f)) / 3f);
452436
var hsv = rgbToHsv(desaturatedColor);
453437
hsv.y += (desaturationFactor / 2f);
454438
hsv.z += desaturationFactor;
455-
hsv.x += ((input.variant - 0.5f) * 0.2f);
439+
hsv.x += ((_arg_0.variant - 0.5f) * 0.2f);
456440
desaturatedColor = hsvToRgb(hsv);
457441
}
458442
var foggedColor = desaturatedColor;
459-
if ((input.applySeaFog == 1u)) {
443+
if ((_arg_0.applySeaFog == 1u)) {
460444
let fogParameter = max(0f, ((distanceFromCamera - 1.5f) * 0.2f));
461445
let fogFactor = (fogParameter / (1f + fogParameter));
462446
foggedColor = mix(foggedColor, vec3f(0, 0.47843137383461, 0.800000011920929), fogFactor);

apps/typegpu-docs/tests/individual-example-tests/ascii-filter.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ describe('ascii filter example', () => {
2020
);
2121

2222
expect(shaderCodes).toMatchInlineSnapshot(`
23-
"struct fullScreenTriangle_Input {
24-
@builtin(vertex_index) vertexIndex: u32,
25-
}
26-
27-
struct fullScreenTriangle_Output {
23+
"struct fullScreenTriangle_Output {
2824
@builtin(position) pos: vec4f,
2925
@location(0) uv: vec2f,
3026
}
3127
32-
@vertex fn fullScreenTriangle(in: fullScreenTriangle_Input) -> fullScreenTriangle_Output {
28+
@vertex fn fullScreenTriangle(@builtin(vertex_index) vertexIndex: u32) -> fullScreenTriangle_Output {
3329
const pos = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
3430
const uv = array<vec2f, 3>(vec2f(0, 1), vec2f(2, 1), vec2f(0, -1));
3531
36-
return fullScreenTriangle_Output(vec4f(pos[in.vertexIndex], 0, 1), uv[in.vertexIndex]);
32+
return fullScreenTriangle_Output(vec4f(pos[vertexIndex], 0, 1), uv[vertexIndex]);
3733
}
3834
3935
@group(0) @binding(0) var<uniform> uvTransformBuffer: mat2x2f;

apps/typegpu-docs/tests/individual-example-tests/bitonic-sort.test.ts

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ describe('bitonic sort example', () => {
3333
3434
@group(0) @binding(0) var<storage, read> src: array<u32>;
3535
36-
struct copyPadKernel_Input {
37-
@builtin(global_invocation_id) gid: vec3u,
38-
@builtin(num_workgroups) numWorkgroups: vec3u,
39-
}
40-
41-
@compute @workgroup_size(256) fn copyPadKernel(input: copyPadKernel_Input) {
42-
let spanX = (input.numWorkgroups.x * 256u);
43-
let spanY = (input.numWorkgroups.y * spanX);
44-
let idx = ((input.gid.x + (input.gid.y * spanX)) + (input.gid.z * spanY));
36+
@compute @workgroup_size(256) fn copyPadKernel(@builtin(global_invocation_id) _arg_gid: vec3u, @builtin(num_workgroups) _arg_numWorkgroups: vec3u) {
37+
let spanX = (_arg_numWorkgroups.x * 256u);
38+
let spanY = (_arg_numWorkgroups.y * spanX);
39+
let idx = ((_arg_gid.x + (_arg_gid.y * spanX)) + (_arg_gid.z * spanY));
4540
let dstLength = params.dstLength;
4641
let srcLength = params.srcLength;
4742
if ((idx >= dstLength)) {
@@ -63,15 +58,10 @@ describe('bitonic sort example', () => {
6358
return (a < b);
6459
}
6560
66-
struct bitonicStepKernel_Input {
67-
@builtin(global_invocation_id) gid: vec3u,
68-
@builtin(num_workgroups) numWorkgroups: vec3u,
69-
}
70-
71-
@compute @workgroup_size(256) fn bitonicStepKernel(input: bitonicStepKernel_Input) {
72-
let spanX = (input.numWorkgroups.x * 256u);
73-
let spanY = (input.numWorkgroups.y * spanX);
74-
let tid = ((input.gid.x + (input.gid.y * spanX)) + (input.gid.z * spanY));
61+
@compute @workgroup_size(256) fn bitonicStepKernel(@builtin(global_invocation_id) _arg_gid: vec3u, @builtin(num_workgroups) _arg_numWorkgroups: vec3u) {
62+
let spanX = (_arg_numWorkgroups.x * 256u);
63+
let spanY = (_arg_numWorkgroups.y * spanX);
64+
let tid = ((_arg_gid.x + (_arg_gid.y * spanX)) + (_arg_gid.z * spanY));
7565
let k = uniforms.k;
7666
let shift = uniforms.jShift;
7767
let dataLength = arrayLength(&data);
@@ -107,49 +97,40 @@ describe('bitonic sort example', () => {
10797
10898
@group(0) @binding(0) var<storage, read> src: array<u32>;
10999
110-
struct copyBackKernel_Input {
111-
@builtin(global_invocation_id) gid: vec3u,
112-
@builtin(num_workgroups) numWorkgroups: vec3u,
113-
}
114-
115-
@compute @workgroup_size(256) fn copyBackKernel(input: copyBackKernel_Input) {
116-
let spanX = (input.numWorkgroups.x * 256u);
117-
let spanY = (input.numWorkgroups.y * spanX);
118-
let idx = ((input.gid.x + (input.gid.y * spanX)) + (input.gid.z * spanY));
100+
@compute @workgroup_size(256) fn copyBackKernel(@builtin(global_invocation_id) _arg_gid: vec3u, @builtin(num_workgroups) _arg_numWorkgroups: vec3u) {
101+
let spanX = (_arg_numWorkgroups.x * 256u);
102+
let spanY = (_arg_numWorkgroups.y * spanX);
103+
let idx = ((_arg_gid.x + (_arg_gid.y * spanX)) + (_arg_gid.z * spanY));
119104
if ((idx < params.srcLength)) {
120105
dst[idx] = src[idx];
121106
}
122107
}
123108
124-
struct fullScreenTriangle_Input {
125-
@builtin(vertex_index) vertexIndex: u32,
126-
}
127-
128109
struct fullScreenTriangle_Output {
129110
@builtin(position) pos: vec4f,
130111
@location(0) uv: vec2f,
131112
}
132113
133-
@vertex fn fullScreenTriangle(in: fullScreenTriangle_Input) -> fullScreenTriangle_Output {
114+
@vertex fn fullScreenTriangle(@builtin(vertex_index) vertexIndex: u32) -> fullScreenTriangle_Output {
134115
const pos = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
135116
const uv = array<vec2f, 3>(vec2f(0, 1), vec2f(2, 1), vec2f(0, -1));
136117
137-
return fullScreenTriangle_Output(vec4f(pos[in.vertexIndex], 0, 1), uv[in.vertexIndex]);
118+
return fullScreenTriangle_Output(vec4f(pos[vertexIndex], 0, 1), uv[vertexIndex]);
138119
}
139120
140-
@group(0) @binding(0) var<storage, read> data_1: array<u32>;
141-
142121
struct fragmentFn_Input {
143122
@location(0) uv: vec2f,
144123
}
145124
146-
@fragment fn fragmentFn(input: fragmentFn_Input) -> @location(0) vec4f {
125+
@group(0) @binding(0) var<storage, read> data_1: array<u32>;
126+
127+
@fragment fn fragmentFn(_arg_0: fragmentFn_Input) -> @location(0) vec4f {
147128
let data = (&data_1);
148129
let arrayLength_1 = arrayLength(&(*data));
149130
let cols = u32(round(sqrt(f32(arrayLength_1))));
150131
let rows = u32(round((f32(arrayLength_1) / f32(cols))));
151-
let col = u32(floor((input.uv.x * f32(cols))));
152-
let row = u32(floor((input.uv.y * f32(rows))));
132+
let col = u32(floor((_arg_0.uv.x * f32(cols))));
133+
let row = u32(floor((_arg_0.uv.y * f32(rows))));
153134
let idx = ((row * cols) + col);
154135
if ((idx >= arrayLength_1)) {
155136
return vec4f(0.10000000149011612, 0.10000000149011612, 0.10000000149011612, 1);

0 commit comments

Comments
 (0)