@@ -28,10 +28,8 @@ type Options = {
2828 targetTexture : ( ) => GPUTextureView ;
2929} ;
3030
31- const reluSlot = tgpu [ '~unstable' ] . slot < boolean > ( ) . $name ( 'relu' ) ;
32- const inputFromGBufferSlot = tgpu [ '~unstable' ]
33- . slot < boolean > ( )
34- . $name ( 'input_from_gbuffer' ) ;
31+ const reluSlot = tgpu . slot < boolean > ( ) ;
32+ const inputFromGBufferSlot = tgpu . slot < boolean > ( ) ;
3533const BLOCK_SIZE = 8 ;
3634
3735// const convolveLocalFn = wgsl.fn`(local: vec2u, result: ptr<function, array<f32, ${outChannelsSlot}>>) {
@@ -68,7 +66,7 @@ const ioLayout = tgpu.bindGroupLayout({
6866const { weights, biases } = layerLayout . bound ;
6967
7068const sampleGlobal = tgpu [ '~unstable' ] . derived ( ( ) => {
71- return tgpu [ '~unstable' ]
69+ return tgpu
7270 . fn ( [ d . i32 , d . i32 , d . ptrFn ( d . arrayOf ( d . vec4f , inChannelsQuarter . value ) ) ] ) (
7371 ( x , y , result ) => {
7472 const canvasSize = accessViewportSize . value ;
@@ -77,7 +75,7 @@ const sampleGlobal = tgpu['~unstable'].derived(() => {
7775 d . u32 ( std . max ( 0 , std . min ( y , d . i32 ( canvasSize . y ) - 1 ) ) ) ,
7876 ) ;
7977
80- if ( inputFromGBufferSlot ) {
78+ if ( inputFromGBufferSlot . $ ) {
8179 const blurred = std . textureLoad ( ioLayout . $ . blurred_tex , coord , 0 ) ;
8280
8381 const aux = std . textureLoad ( ioLayout . $ . aux_tex , coord , 0 ) ;
@@ -96,8 +94,10 @@ const sampleGlobal = tgpu['~unstable'].derived(() => {
9694 ) ;
9795 } else {
9896 for ( let i = d . u32 ( 0 ) ; i < inChannelsQuarter . value ; i ++ ) {
99- const index = ( coord . y * d . u32 ( canvasSize . x ) + coord . x ) *
100- inChannelsQuarter . value + i ;
97+ const index =
98+ ( coord . y * d . u32 ( canvasSize . x ) + coord . x ) *
99+ inChannelsQuarter . value +
100+ i ;
101101
102102 result [ i ] = ioLayout . $ . input_buffer [ index ] ;
103103 }
@@ -121,56 +121,49 @@ const applyReLU = tgpu['~unstable'].derived(() => {
121121 . $name ( 'apply_relu' ) ;
122122} ) ;
123123
124- const readKernel = tgpu [ '~unstable' ]
125- . fn (
126- [ d . u32 ] ,
127- d . vec4f ,
128- ) ( ( idx ) => weights . value [ idx ] )
129- . $name ( 'readKernel' ) ;
124+ const readKernel = tgpu . fn ( [ d . u32 ] , d . vec4f ) ( ( idx ) => weights . value [ idx ] ) ;
130125
131126const menderConvolveFn = convolveFn ( {
132127 sampleFiller : sampleGlobal ,
133128 kernelReader : readKernel ,
134129} ) ;
135130
136- const entryComputeFn = tgpu [ '~unstable' ]
137- . computeFn ( {
138- workgroupSize : [ BLOCK_SIZE , BLOCK_SIZE ] ,
139- in : {
140- gid : d . builtin . globalInvocationId ,
141- } ,
142- } ) ( /* wgsl */ `{
131+ const entryComputeFn = tgpu [ '~unstable' ] . computeFn ( {
132+ workgroupSize : [ BLOCK_SIZE , BLOCK_SIZE ] ,
133+ in : {
134+ gid : d . builtin . globalInvocationId ,
135+ } ,
136+ } ) `{
143137 var result: array<f32, OUT_CHANNELS>;
144-
138+
145139 for (var i = 0; i < OUT_CHANNELS; i += 1) {
146140 result[i] = biases[i];
147141 }
148142
149143 menderConvolveFn(in.gid.xy, &result);
150-
144+
151145 if (reluSlot) {
152146 applyReLU(&result);
153147 }
154148
155149 let canvasSize = accessViewportSize;
156-
150+
157151 let output_buffer_begin =
158152 (in.gid.y * u32(canvasSize.x) +
159153 in.gid.x) * OUT_CHANNELS;
160-
154+
161155 for (var i: u32 = 0; i < OUT_CHANNELS; i++) {
162156 output_buffer[output_buffer_begin + i] = result[i];
163157 }
164- }` )
165- . $uses ( {
166- menderConvolveFn,
167- reluSlot,
168- applyReLU,
169- biases,
170- accessViewportSize,
171- output_buffer : ioLayout . bound . output_buffer ,
172- OUT_CHANNELS : outChannelsSlot ,
173- } ) ;
158+ }` . $uses ( {
159+ menderConvolveFn,
160+ reluSlot,
161+ applyReLU,
162+ biases,
163+ accessViewportSize,
164+ output_buffer : ioLayout . bound . output_buffer ,
165+ OUT_CHANNELS : outChannelsSlot ,
166+ } ) ;
174167
175168export const MenderStep = ( { root, gBuffer, targetTexture } : Options ) => {
176169 // Resource locators
0 commit comments