@@ -8,6 +8,7 @@ import type {
8
8
ResolutionCtx ,
9
9
SelfResolvable ,
10
10
} from '../../types' ;
11
+ import { valueProxyHandler } from '../valueProxyUtils' ;
11
12
import { type TgpuBuffer , type Uniform , isUsableAsUniform } from './buffer' ;
12
13
13
14
// ----------
@@ -37,15 +38,6 @@ export interface TgpuBufferReadonly<TData extends BaseWgslData>
37
38
export interface TgpuBufferMutable < TData extends BaseWgslData >
38
39
extends TgpuBufferUsage < TData , 'mutable' > { }
39
40
40
- export function isBufferUsage <
41
- T extends
42
- | TgpuBufferUniform < BaseWgslData >
43
- | TgpuBufferReadonly < BaseWgslData >
44
- | TgpuBufferMutable < BaseWgslData > ,
45
- > ( value : T | unknown ) : value is T {
46
- return ( value as T ) ?. resourceType === 'buffer-usage' ;
47
- }
48
-
49
41
// --------------
50
42
// Implementation
51
43
// --------------
@@ -89,7 +81,9 @@ class TgpuFixedBufferImpl<
89
81
const usage = usageToVarTemplateMap [ this . usage ] ;
90
82
91
83
ctx . addDeclaration (
92
- `@group(${ group } ) @binding(${ binding } ) var<${ usage } > ${ id } : ${ ctx . resolve ( this . buffer . dataType ) } ;` ,
84
+ `@group(${ group } ) @binding(${ binding } ) var<${ usage } > ${ id } : ${ ctx . resolve (
85
+ this . buffer . dataType ,
86
+ ) } ;`,
93
87
) ;
94
88
95
89
return id ;
@@ -103,10 +97,16 @@ class TgpuFixedBufferImpl<
103
97
if ( ! inGPUMode ( ) ) {
104
98
throw new Error ( `Cannot access buffer's value directly in JS.` ) ;
105
99
}
106
- return this as Infer < TData > ;
100
+
101
+ return new Proxy (
102
+ {
103
+ '~resolve' : ( ctx : ResolutionCtx ) => ctx . resolve ( this ) ,
104
+ toString : ( ) => `.value:${ this . label ?? '<unnamed>' } ` ,
105
+ } ,
106
+ valueProxyHandler ,
107
+ ) as Infer < TData > ;
107
108
}
108
109
}
109
-
110
110
export class TgpuLaidOutBufferImpl <
111
111
TData extends BaseWgslData ,
112
112
TUsage extends BindableBufferUsage ,
@@ -132,7 +132,9 @@ export class TgpuLaidOutBufferImpl<
132
132
const usage = usageToVarTemplateMap [ this . usage ] ;
133
133
134
134
ctx . addDeclaration (
135
- `@group(${ group } ) @binding(${ this . _membership . idx } ) var<${ usage } > ${ id } : ${ ctx . resolve ( this . dataType as AnyWgslData ) } ;` ,
135
+ `@group(${ group } ) @binding(${
136
+ this . _membership . idx
137
+ } ) var<${ usage } > ${ id } : ${ ctx . resolve ( this . dataType as AnyWgslData ) } ;`,
136
138
) ;
137
139
138
140
return id ;
@@ -146,7 +148,14 @@ export class TgpuLaidOutBufferImpl<
146
148
if ( ! inGPUMode ( ) ) {
147
149
throw new Error ( `Cannot access buffer's value directly in JS.` ) ;
148
150
}
149
- return this as Infer < TData > ;
151
+
152
+ return new Proxy (
153
+ {
154
+ '~resolve' : ( ctx : ResolutionCtx ) => ctx . resolve ( this ) ,
155
+ toString : ( ) => `.value:${ this . label ?? '<unnamed>' } ` ,
156
+ } ,
157
+ valueProxyHandler ,
158
+ ) as Infer < TData > ;
150
159
}
151
160
}
152
161
0 commit comments