-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[WebGPU] Implement dynamic buffer offsets for render bundles #19025
[WebGPU] Implement dynamic buffer offsets for render bundles #19025
Conversation
EWS run on previous version of this PR (hash 8edcd4c) |
8edcd4c
to
a31d465
Compare
EWS run on previous version of this PR (hash a31d465) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
m_bindGroupDynamicOffsets.clear(); | ||
} | ||
|
||
void RenderBundleEncoder::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) | ||
{ | ||
if (id<MTLIndirectRenderCommand> icbCommand = currentRenderCommand()) { | ||
executePreDrawCommands(); | ||
executePreDrawCommands(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be computed for every draw, or can the calculations be cached?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs to happen before every draw because the vertex buffers can change between draws.
And Metal ICBs appear to require all buffers in use to call setVertexBuffer: for each command, whereas WebGPU maintains a persistent state across commands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which is best illustrated through https://webgpu.github.io/webgpu-samples/samples/renderBundles
passEncoder.setPipeline(pipeline);
passEncoder.setBindGroup(0, frameBindGroup);
// Loop through every renderable object and draw them individually.
// (Because many of these meshes are repeated, with only the transforms
// differing, instancing would be highly effective here. This sample
// intentionally avoids using instancing in order to emulate a more complex
// scene, which helps demonstrate the potential time savings a render bundle
// can provide.)
let count = 0;
for (const renderable of renderables) {
passEncoder.setBindGroup(1, renderable.bindGroup);
passEncoder.setVertexBuffer(0, renderable.vertices);
passEncoder.setIndexBuffer(renderable.indices, 'uint16');
passEncoder.drawIndexed(renderable.indexCount);
if (++count > settings.asteroidCount) {
break;
}
}
setBindGroup(0
is only called once and the expectation is that bind group is persistent throughout the draw calls
auto commandCount = m_currentCommandIndex; | ||
m_currentCommandIndex = 0; | ||
|
||
if (!m_indirectCommandBuffer) { | ||
m_icbDescriptor.maxVertexBufferBindCount = m_device->maxBuffersPlusVertexBuffersForVertexStage(); | ||
m_icbDescriptor.maxVertexBufferBindCount = m_device->maxBuffersPlusVertexBuffersForVertexStage() + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you a comment here why + 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh because the dynamic offsets get set to index = m_device->maxBuffersPlusVertexBuffersForVertexStage()
and if I set them to m_device->maxBuffersPlusVertexBuffersForVertexStage() - 1
then I need to change the WGSL compiler.
But that is kind of ugly, maybe I can clean that up
a31d465
to
99a537c
Compare
EWS run on current version of this PR (hash 99a537c) |
https://bugs.webkit.org/show_bug.cgi?id=262208 <radar://116137950> Reviewed by Dan Glastonbury. Support dynamic offsets in RenderBundles / ICBs like they are supported in the RenderPassEncoder and ComputePassEncoder. * Source/WebCore/Modules/WebGPU/Implementation/WebGPURenderBundleEncoderImpl.cpp: (WebCore::WebGPU::RenderBundleEncoderImpl::setBindGroup): * Source/WebGPU/WebGPU/RenderBundleEncoder.h: * Source/WebGPU/WebGPU/RenderBundleEncoder.mm: (WebGPU::addResource): (WebGPU::RenderBundleEncoder::executePreDrawCommands): (WebGPU::RenderBundleEncoder::draw): (WebGPU::RenderBundleEncoder::drawIndexed): (WebGPU::RenderBundleEncoder::drawIndexedIndirect): (WebGPU::RenderBundleEncoder::drawIndirect): (WebGPU::RenderBundleEncoder::finish): (WebGPU::RenderBundleEncoder::setBindGroup): (WebGPU::RenderBundleEncoder::setPipeline): (wgpuRenderBundleEncoderSetBindGroup): (wgpuRenderBundleEncoderSetBindGroupWithDynamicOffsets): * Source/WebGPU/WebGPU/WebGPUExt.h: Canonical link: https://commits.webkit.org/269548@main
99a537c
to
32f0226
Compare
Committed 269548@main (32f0226): https://commits.webkit.org/269548@main Reviewed commits have been landed. Closing PR #19025 and removing active labels. |
32f0226
99a537c