Sitelet https://github.com/gpuweb/gpuweb/pull/4989
Skip to content

Compat: Limit the number of texture+sampler combinations - #4989

Merged
greggman merged 5 commits into
gpuweb:mainfrom
greggman:limit-texture-sampler-combinations
Nov 27, 2024
Merged

greggman merged 5 commits into
gpuweb:mainfrom
greggman:limit-texture-sampler-combinations

Conversation

@greggman

@greggman greggman commented Nov 22, 2024 •

Copy link
Copy Markdown
Member

Resolves #4986

@github-actions

github-actions Bot commented Nov 22, 2024 •

Copy link
Copy Markdown
Contributor

Previews, as seen when this build job started (a9a0f02):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt


## 20. Limit the number of texture+sampler combinations in a pipeline.

If the number of texture+sampler combinations used a in single stage in a pipeline exceeds

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we clarify that combinations includes textures without samplers as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. That's an interesting issue. A texture used without a sampler counts as 1 but only if it's not used somewhere else? Or do we keep it simple? In other words, if you have

@group(0) @binding(0) var t: texture_2d<f32>;
@group(0) @binding(1) var s: sampler;

   x = textureLoad(t);
   y = textureSampler(t, s);

That's seems like it only counts as 1 combo

I'm not sure the easiest way to state that.

The number of texture+sampler combinations is counted by first counting the number of texture+sampler combinations, then adding 1 for every texture used without a sampler that's not already counted.

or something like that?

Or do we count the example above as 2 combos? [(t+s), (t)]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking dawn with the code above it only created 1 uniform sampler2D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be 1 combo. Probably can be stated as essentially max(used without sampler ? 1 : 0, number of texture sampler combos)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@greggman greggman Nov 26, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also complicated by external texture? It seems like it is like maybe it should be min(maxSampledTexturesPerShaderStage - numExternalTexturesUsedInStage * 4, maxSamplersPerShaderStage - numExternalTexturesUsageInStage * 2)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure max(used without sampler ? 1 : 0, number of texture sampler combos) is correct. I reverted it back to how it was before for now

max(used without sampler ? 1 : 0, number of texture sampler combos) would make sense if it said something like,

The number of texture+sampler combinations is counted as follows:

sum = 0;
for each texture used in entry point
   sum += max(texture+sampler combos for texture, texture used without sampler ? 1 :  0)

or something like that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is what I had in mind, I didn't sketch it very carefully. Though just realizing, the 0/1 is accounted for by the bind group layouts, and it doesn't matter if it's actually used with textureLoad? So:

for each stage of the pipeline:
  sum = 0
  for each texture binding in the pipeline layout which is visible to that stage:
    sum += max(1, number of texture sampler combos for that texture binding)

Good point about external texture, that definitely needs to be explicit about how it interacts with this limit. The internal resources of an external texture are explained in the note here: https://gpuweb.github.io/gpuweb/#gpuexternaltexture

So the accounting (https://gpuweb.github.io/gpuweb/#exceeds-the-binding-slot-limits) would add something like this, via the logic above:

    sum += 1 // for LUT texture + LUT sampler
    sum += 3 * max(1, number of external_texture sampler combos) // for Y+U+V

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, added, ptal

greggman added a commit to greggman/cts that referenced this pull request Nov 27, 2024
greggman added a commit to greggman/cts that referenced this pull request Nov 27, 2024
Note: this test would have surfaced a compat issue if it already existed.

The issue gpuweb/gpuweb#4989 was raised
and this test tests in both compat and core that an implemation
can use all the texture and sample combinations it is supposed to.
@greggman greggman mentioned this pull request Nov 27, 2024
4 of 8 tasks
@greggman
greggman force-pushed the limit-texture-sampler-combinations branch from ec4ef7d to a9a0f02 Compare November 27, 2024 16:31
@greggman
greggman enabled auto-merge (squash) November 27, 2024 16:31
@greggman
greggman merged commit bfd7d1d into gpuweb:main Nov 27, 2024
greggman added a commit to greggman/cts that referenced this pull request Nov 27, 2024
greggman added a commit to greggman/cts that referenced this pull request Nov 27, 2024
greggman added a commit to gpuweb/cts that referenced this pull request Nov 27, 2024
greggman added a commit to greggman/cts that referenced this pull request Nov 28, 2024
Note: this test would have surfaced a compat issue if it already existed.

The issue gpuweb/gpuweb#4989 was raised
and this test tests in both compat and core that an implemation
can use all the texture and sample combinations it is supposed to.
greggman added a commit to gpuweb/cts that referenced this pull request Nov 28, 2024
Note: this test would have surfaced a compat issue if it already existed.

The issue gpuweb/gpuweb#4989 was raised
and this test tests in both compat and core that an implemation
can use all the texture and sample combinations it is supposed to.
@kainino0x kainino0x added the compat WebGPU Compatibility Mode label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compat WebGPU Compatibility Mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compat: Limit the number of sample/texture combinations

3 participants