Bug 1617086 - Keep WebGPU pass dependencies alive while recording r=jgilbert

Since we switched to "software" pass recording,
`wgpu` no longer keeps references to the objects used when recording a pass.
This means Gecko needs to keep them alive up until the encoding is done.

Differential Revision: https://phabricator.services.mozilla.com/D65319

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dzmitry Malyshau 2020-03-05 03:30:41 +00:00
Родитель 2baf261d29
Коммит 7eb1434fa4
4 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -38,6 +38,7 @@ void ComputePassEncoder::SetBindGroup(
uint32_t aSlot, const BindGroup& aBindGroup,
const dom::Sequence<uint32_t>& aDynamicOffsets) {
if (mValid) {
mUsedBindGroups.push_back(&aBindGroup);
ffi::wgpu_compute_pass_set_bind_group(&mRaw, aSlot, aBindGroup.mId,
aDynamicOffsets.Elements(),
aDynamicOffsets.Length());
@ -46,6 +47,7 @@ void ComputePassEncoder::SetBindGroup(
void ComputePassEncoder::SetPipeline(const ComputePipeline& aPipeline) {
if (mValid) {
mUsedPipelines.push_back(&aPipeline);
ffi::wgpu_compute_pass_set_pipeline(&mRaw, aPipeline.mId);
}
}

Просмотреть файл

@ -14,6 +14,7 @@
namespace mozilla {
namespace webgpu {
class BindGroup;
class Buffer;
class CommandEncoder;
class ComputePipeline;
@ -32,6 +33,9 @@ class ComputePassEncoder final : public ObjectBase,
void Cleanup() {}
ffi::WGPURawPass mRaw;
// keep all the used objects alive while the pass is recorded
std::vector<RefPtr<const BindGroup>> mUsedBindGroups;
std::vector<RefPtr<const ComputePipeline>> mUsedPipelines;
public:
void SetBindGroup(uint32_t aSlot, const BindGroup& aBindGroup,

Просмотреть файл

@ -117,7 +117,15 @@ ffi::WGPURawPass BeginRenderPass(RawId aEncoderId,
RenderPassEncoder::RenderPassEncoder(CommandEncoder* const aParent,
const dom::GPURenderPassDescriptor& aDesc)
: ChildOf(aParent), mRaw(BeginRenderPass(aParent->mId, aDesc)) {}
: ChildOf(aParent), mRaw(BeginRenderPass(aParent->mId, aDesc)) {
for (const auto& at : aDesc.mColorAttachments) {
mUsedTextureViews.push_back(at.mAttachment);
}
if (aDesc.mDepthStencilAttachment.WasPassed()) {
mUsedTextureViews.push_back(
aDesc.mDepthStencilAttachment.Value().mAttachment);
}
}
RenderPassEncoder::~RenderPassEncoder() {
if (mValid) {
@ -130,6 +138,7 @@ void RenderPassEncoder::SetBindGroup(
uint32_t aSlot, const BindGroup& aBindGroup,
const dom::Sequence<uint32_t>& aDynamicOffsets) {
if (mValid) {
mUsedBindGroups.push_back(&aBindGroup);
ffi::wgpu_render_pass_set_bind_group(&mRaw, aSlot, aBindGroup.mId,
aDynamicOffsets.Elements(),
aDynamicOffsets.Length());
@ -138,6 +147,7 @@ void RenderPassEncoder::SetBindGroup(
void RenderPassEncoder::SetPipeline(const RenderPipeline& aPipeline) {
if (mValid) {
mUsedPipelines.push_back(&aPipeline);
ffi::wgpu_render_pass_set_pipeline(&mRaw, aPipeline.mId);
}
}
@ -145,6 +155,7 @@ void RenderPassEncoder::SetPipeline(const RenderPipeline& aPipeline) {
void RenderPassEncoder::SetIndexBuffer(const Buffer& aBuffer,
uint64_t aOffset) {
if (mValid) {
mUsedBuffers.push_back(&aBuffer);
ffi::wgpu_render_pass_set_index_buffer(&mRaw, aBuffer.mId, aOffset);
}
}
@ -152,6 +163,7 @@ void RenderPassEncoder::SetIndexBuffer(const Buffer& aBuffer,
void RenderPassEncoder::SetVertexBuffer(uint32_t aSlot, const Buffer& aBuffer,
uint64_t aOffset) {
if (mValid) {
mUsedBuffers.push_back(&aBuffer);
// TODO: change the Rust API to use a single vertex buffer?
ffi::wgpu_render_pass_set_vertex_buffers(&mRaw, aSlot, &aBuffer.mId,
&aOffset, 1);

Просмотреть файл

@ -38,6 +38,11 @@ class RenderPassEncoder final : public ObjectBase,
void Cleanup() {}
ffi::WGPURawPass mRaw;
// keep all the used objects alive while the pass is recorded
std::vector<RefPtr<const BindGroup>> mUsedBindGroups;
std::vector<RefPtr<const Buffer>> mUsedBuffers;
std::vector<RefPtr<const RenderPipeline>> mUsedPipelines;
std::vector<RefPtr<const TextureView>> mUsedTextureViews;
public:
void SetBindGroup(uint32_t aSlot, const BindGroup& aBindGroup,