-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getBindGroupLayout #446
Comments
Proposal 2: GPUPipelineBase.getBindGroupLayoutThe only change compared to the first proposal is the addition of const computeShaderCode = `#version 450
layout(std430, set = 0, binding = 0) readonly buffer FirstMatrix {
} firstMatrix;
layout(std430, set = 0, binding = 1) readonly buffer SecondMatrix {
} secondMatrix;
layout(std430, set = 0, binding = 2) buffer ResultMatrix {
} resultMatrix;`;
const computePipeline = device.createComputePipeline({
computeStage: {
module: device.createShaderModule({code: theCode}),
entryPoint: "main"
}
});
const bindGroup = device.createBindGroup({
layout: computePipeline.getBindGroupLayout(0),
bindings: [
{binding: 0, resource: {buffer: gpuBufferFirstMatrix}},
{binding: 1, resource: {buffer: gpuBufferSecondMatrix}},
{binding: 2, resource: {buffer: resultMatrixBuffer}}
]
}); The partial interface GPUPipelineBase {
GPUBindGroupLayout getBindGroupLayout(unsigned int groupIndex);
}; Open question: The only difficulty seems to be whether the returned Deduplication of equivalent BGLs in the client side would make multiprocess implementations of WebGPU extremely sad. For the rest, making JS objects the same as the one in |
This is much better, thank you! So the only "guessing" (or deriving) of the BGL entries would be from the shader at the pipeline creation. I do wonder though, how would this play with WSL shaders? Overall, since we have to write down in the specification the deriving rules from the shading language, this PR might be blocked until we settle on what that language is.
Can we just return the same object without de-duplication? |
* Loosen precision in multisample resolve operation test Some platforms produce 0x7f and others 0x80 when a pixel is half-covered. * rebase / address comment
Motivation
Today
GPUBindGroupLayout
andGPUPipelineLayout
are the most complicated part of the API. How about we add some defaults to them?Namely it would change this sample code:
into
which is much easier to understand for people getting started with WebGPU, and almost 50% less code to type for experienced WebGPU developers hacking with the API.
How would this work
It makes the
layout
member ofGPUPipelineDescriptorBase
andGPUBindGroupDescriptor
optional and if not present deduces them using the following algorithms.For
GPUBindGroupDescriptor
it implicitly creates aGPUBindGroupLayout
that one binding (with the samebinding
number) for each binding in theGPUBindGroupDescriptor
.visibility
is always all the stage and other member are set like so (if not described, they get their default value):resource
is aGPUSampler
,type
is"sampler"
resource
is aGPUTextureView
, if the texture has not exactly one of theSAMPLED
andSTORAGE
usages, an error is produced.type
is"sampled-texture"
if the texture has theSAMPLED
usage,"storage-texture"
otherwise.textureDimension
is set to the texture view dimension of the view, andtextureComponentType
set to the component type of the texture's format. If the texture has asampleCount
larger than 1,multisampled
is set sotrue
.resource
is aGPUBufferBinding
, if the buffer has not exactly one of theUNIFORM
andSTORAGE
usages, an error is produced.type
is"uniform-buffer"
if the buffer has theUNIFORM
usage,"storage-buffer"
otherwise.For
GPUComputePipeline
andGPURenderPipeline
we would deduce an implicitGPUPipelineLayout
that has implicitGPUBindGroupLayouts
for each set used by the pipeline.visibility
is set to all shader stages. Then for each binding of the shader modules of the pipeline a binding is inserted in the correctGPUBindGroupLayout
with the matchingbinding
like the following (members not mentioned get their default value):type
is set to"sampler"
.type
is set to"uniform-buffer"
.type
is set to"storage-buffer"
.type
is set tostorage-texture
,sampled-texture
otherwise.textureViewDimension
is set to match the texture binding declaration, as ismultisampled
andtextureComponentType
.Note that for render pipeline this would also require checking no two bindings conflict.
The text was updated successfully, but these errors were encountered: