@@ -4,7 +4,7 @@ import type { TgpuRoot } from '../../core/root/rootTypes.ts';
44import { shaderStageSlot } from '../../core/slot/internalSlots.ts' ;
55import { arrayOf } from '../../data/array.ts' ;
66import { atomic } from '../../data/atomic.ts' ;
7- import { UnknownData } from '../../data/dataTypes.ts' ;
7+ import { UnknownData , unptr } from '../../data/dataTypes.ts' ;
88import { u32 } from '../../data/numeric.ts' ;
99import { snip , type Snippet } from '../../data/snippet.ts' ;
1010import { struct } from '../../data/struct.ts' ;
@@ -15,8 +15,10 @@ import {
1515 Void ,
1616 type WgslArray ,
1717} from '../../data/wgslTypes.ts' ;
18+ import { invariant } from '../../errors.ts' ;
1819import { $internal } from '../../shared/symbols.ts' ;
19- import { concretizeSnippets , type GenerationCtx } from '../generationHelpers.ts' ;
20+ import { convertToCommonType } from '../conversion.ts' ;
21+ import { concretizeSnippet , type GenerationCtx } from '../generationHelpers.ts' ;
2022import { createLoggingFunction } from './serializers.ts' ;
2123import {
2224 type LogGenerator ,
@@ -87,30 +89,46 @@ export class LogGeneratorImpl implements LogGenerator {
8789 return fallbackSnippet ;
8890 }
8991
90- const concreteArgs = concretizeSnippets ( args ) ;
9192 const id = this . #firstUnusedId++ ;
9293
93- const nonStringArgs = concreteArgs . filter ( ( e ) => e . dataType !== UnknownData ) ;
94+ const concreteArgsWithStrings = args
95+ . map ( ( arg ) => {
96+ if ( arg . dataType === UnknownData ) {
97+ return arg ;
98+ }
99+ const converted = convertToCommonType ( ctx , [ arg ] , [ unptr ( arg . dataType ) ] ) ?. [ 0 ] ;
100+ invariant (
101+ converted ,
102+ `Internal error. Expected type ${ arg . dataType } to be convertible to ${ unptr ( arg . dataType ) } ` ,
103+ ) ;
104+ return converted ;
105+ } )
106+ . map ( concretizeSnippet ) ;
107+
108+ const concreteArgs = concreteArgsWithStrings . filter ( ( arg ) => arg . dataType !== UnknownData ) ;
94109
95110 const logFn = createLoggingFunction (
96111 id ,
97- nonStringArgs . map ( ( e ) => e . dataType as AnyWgslData ) ,
112+ concreteArgs . map ( ( e ) => e . dataType as AnyWgslData ) ,
98113 this . #dataBuffer,
99114 this . #indexBuffer,
100115 this . #options,
101116 ) ;
102117
103- const argTypes = concreteArgs . map ( ( e ) =>
104- e . dataType === UnknownData ? ( e . value as string ) : ( e . dataType as AnyWgslData ) ,
105- ) ;
106-
107- this . #logIdToMeta. set ( id , { op : op as SupportedLogOps , argTypes } ) ;
108-
109- return snip (
110- stitch `${ ctx . resolve ( logFn ) . value } (${ nonStringArgs } )` ,
118+ const functionSnippet = snip (
119+ stitch `${ ctx . resolve ( logFn ) . value } (${ concreteArgs } )` ,
111120 Void ,
112121 /* origin */ 'runtime' ,
113122 ) ;
123+
124+ this . #logIdToMeta. set ( id , {
125+ op : op as SupportedLogOps ,
126+ argTypes : concreteArgsWithStrings . map ( ( e ) =>
127+ e ?. dataType === UnknownData ? ( e ?. value as string ) : ( e ?. dataType as AnyWgslData ) ,
128+ ) ,
129+ } ) ;
130+
131+ return functionSnippet ;
114132 }
115133
116134 get logResources ( ) : LogResources | undefined {
0 commit comments