Skip to content

Make minBufferBindingSize optional - #874

Merged
kainino0x merged 5 commits into
gpuweb:mainfrom
litherum:minBufferBindingSize
Jul 21, 2020
Merged

kainino0x merged 5 commits into
gpuweb:mainfrom
litherum:minBufferBindingSize

Conversation

@litherum

@litherum litherum commented Jun 22, 2020 •

Copy link
Copy Markdown
Contributor

When the author opt-in to using minBufferBindingSize, this enables two checks:

  1. The appropriate buffer in any bind groups created with this bind group layout is larger than minBufferBindingSize
  2. minBufferBindingSize is larger than is necessary given the shader

If the author opts in to these requirements, we can do bounds checking at bind group creation / shader compilation time. However, if the author does not opt in to these requirements, we must do bounds checking at draw call time.

Rather than using a sentinel 0 for the second check, we should have the author explicit enable them via out-of-band messaging. This doesn't matter for the first check (since any buffer length is greater-than-or-equal-to 0), but it does matter for the second check.

This patch doesn't change any defaults; it just makes makes the opt-in to earlier bounds checking more explicit.


Preview | Diff

When the author opt-in to using minBufferBindingSize, this enables two checks:
1. The appropriate buffer in any bind groups created with this bind group layout is larger than minBufferBindingSize
2. minBufferBindingSize is larger than is necessary given the shader

If the author opts in to these requirements, we can do bounds checking at bind group creation / shader compilation time.

However, if the author does not opt in to these requirements, we must do bounds checking at draw call time.

Rather than using a sentinel 0 for the second check, we should have the author explicit enable them via out-of-band messaging.
This doesn't matter for the first check (since any buffer length is greater-than-or-equal-to 0), but it does matter for the
second check.

This patch doesn't change any defaults; it just makes makes the opt-in to earlier bounds checking more explicit.
Comment thread spec/index.bs Resolved
@Kangz

Kangz commented Jun 22, 2020

Copy link
Copy Markdown
Contributor

I have slight concerns about using minBufferBindingSize not being present as the signal it shouldn't be used because WASM doesn't have optional dictionary members. So far the spec doesn't have optional numbers that cannot be replaced just by 0, except GPUBufferBinding.size which is already slightly unfortunate to use from WASM and requires a UINT64_MAX sentinel value or a similar mechanism.

@kvark

kvark commented Jun 22, 2020

Copy link
Copy Markdown
Contributor

@Kangz I share the concern about WASM :) Also:

except GPUBufferBinding.size which is already slightly unfortunate to use from WASM and requires a UINT64_MAX sentinel value or a similar mechanism.

Note that with minBufferBindingSize agreed in CG, it does no longer make sense to support zero-sized buffer bindings: they have to be larger or equal to the non-zero minBufferBindingSize anyway. So making size=0 to mean "rest of the buffer" is an option on the able for WASM.

@kainino0x

Copy link
Copy Markdown
Contributor

Rather than using a sentinel 0 for the second check, we should have the author explicit enable them via out-of-band messaging. This doesn't matter for the first check (since any buffer length is greater-than-or-equal-to 0), but it does matter for the second check.

I argued against this already somewhere. It's one thing to use 0 as a sentinel value. But in this case we really do literally mean "the minimum buffer binding size is 0". So in terms of the local semantics, it matches the name and I think we should keep that, despite the fact that no-minimum-buffer-binding-size does become special later.

@kvark
kvark changed the base branch from master to main June 23, 2020 13:13
Comment thread spec/index.bs Resolved
Co-authored-by: Kai Ninomiya <[email protected]>
@litherum

Copy link
Copy Markdown
Contributor Author

Right now, the spec has two situations:

  1. Passing a value that is greater than 0 as minBufferBindingSize, which enables ahead-of-time bounds checking
  2. Either passing 0 or not passing anything as minBufferBindingSize, which enables draw-call bounds checking

This patch moves the "passing 0" into the first situation.

The reason for this change is that it's totally reasonable for a shader to have no resources bound other than a big array. In this situation, you don't want draw-call bounds checking, but the value to check against is 0.

The switch between "do ahead-of-time bounds checking" and "do draw-call bounds checking" should be an explicit switch, not implied by a sentinel 0.

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved

@kainino0x kainino0x left a comment •

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.

LGTM with suggestions above; I'm on the fence so Myles definitely feels more strongly :)

@kvark

kvark commented Jul 17, 2020

Copy link
Copy Markdown
Contributor

The reason for this change is that it's totally reasonable for a shader to have no resources bound other than a big array. In this situation, you don't want draw-call bounds checking, but the value to check against is 0.

On the call we clarified that this is impossible today, as we agreed to require the buffer binding to include at least one element of an unsized array. So there is never a case where you'd want to specify 0 there while not wanting draw-call bounds checks.

I assumed that you were going to revise this proposal with that aspect clarified, but it appears to be unchanged.

@kainino0x

Copy link
Copy Markdown
Contributor

What needs clarification? That 0 is not a valid value?

@kvark

kvark commented Jul 17, 2020

Copy link
Copy Markdown
Contributor

Nothing needs clarification, it was provided on the call and that's what I wrote in the comment.
It just seems to me that clarification removes one of the concerns that this PR is trying to solve, and therefore I expected the PR to be reconsidered.

@kainino0x

kainino0x commented Jul 17, 2020 •

Copy link
Copy Markdown
Contributor

Right, I see now that Myles hasn't come back to this issue since the meeting. Doesn't change that I'm still fine with this if Myles wants to push it forward though.

0 would never be a valid minBufferBindingSize because it would fail to validate against any shader during pipeline creation. So if we accept this, we might want to add validation in BGL creation saying minBufferBindingSize cannot be 0.

litherum and others added 2 commits July 20, 2020 11:18
Co-authored-by: Kai Ninomiya <[email protected]>
Co-authored-by: Kai Ninomiya <[email protected]>
@litherum

Copy link
Copy Markdown
Contributor Author

Presumably the set of resources attached to the shader (via bindgroups) is allowed to be a superset of the resources that the shader actually uses. For the resources which are bound but not used, 0 seems like a reasonable value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants