Repository navigation
Replies: 1 comment
|
I think that I'd rather have these resources bound to resolution, not to function. import { tgpu, d, std } from 'typegpu';
import { track, getTrackedResources } from './track.ts';
const textureAccess = tgpu.accessor(d.texture2d(d.f32));
let arbitraryCounter = 0;
function sampleTexture(uv: d.v2f): d.v4f {
'use gpu';
if (arbitraryCounter === 0) {
track(textureAccess);
return std.textureSample(textureAccess.$, uv);
}
return d.vec4f();
}
function main() {
'use gpu';
return sampleTexture(d.vec2f());
}
// using main in a shader
arbitraryCounter++;
const resources = getTrackedResources([main]); // texture not included!!In this case, this is debugable by the user, but there could be worse cases, like using a comptime that changes its value with each call, where user will have no idea what did they do wrong. I don't recall, why didn't we want to just return the used resources from resolve? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I received a feature request, to be able to inspect whether a function itself (or transitively) used a slot/accessor/struct, etc.. The motivation is e.g. being able to determine if a shader uses a provided resource, and if not, not bothering to populate it with expensive to compute data, as an optimization trick.
It seems like it's a utility that can be constructed out of the public API surface today. Let's look at how the API of such utility could look like:
If we make
trackreturn it's input as well, then we can even write:By hiding the accessor, and only exposing it through functions or getters that call
track, we know when a shader used a particular resource.Here is how
trackandgetTrackedResourcescan be implemented:Generalizing
This mechanism can be used for determining whether any specific branch was taken during shader generation, not just to collect a set of objects.
All reactions