mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-15 20:01:22 +00:00
Separate the types for compute and render pass usage data
This change is a preparation for making the compute pass track the synchronization scope usages per dispatch instead of for the whole pass. This CL just separates the Compute and RenderPassResourceUsage types. This requires making the difference between SyncScope/ComputePass/RenderPass ResourceUsageTracker instead of having a single combined tracker. This change also duplicates SetBindGroup by removing the common handling in ProgrammablePassEncoder and putting it in ComputePassEncoder and RenderEncoderBase. This is necessary because the UsageTracker types are now split, but it will also help have different handling of SetBindGroup for compute and render in follow-up CLs. There are no functional changes. Bug: dawn:632 Change-Id: I482c04483d8b734fb10e44e717071eedcff2f15f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/49884 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
d98b3076f5
commit
ec7ea6aaaa
@ -522,7 +522,7 @@ namespace dawn_native {
|
|||||||
RenderPassEncoder* CommandEncoder::APIBeginRenderPass(const RenderPassDescriptor* descriptor) {
|
RenderPassEncoder* CommandEncoder::APIBeginRenderPass(const RenderPassDescriptor* descriptor) {
|
||||||
DeviceBase* device = GetDevice();
|
DeviceBase* device = GetDevice();
|
||||||
|
|
||||||
PassResourceUsageTracker usageTracker(PassType::Render);
|
RenderPassResourceUsageTracker usageTracker;
|
||||||
|
|
||||||
uint32_t width = 0;
|
uint32_t width = 0;
|
||||||
uint32_t height = 0;
|
uint32_t height = 0;
|
||||||
@ -946,7 +946,7 @@ namespace dawn_native {
|
|||||||
TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "CommandEncoder::ValidateFinish");
|
TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "CommandEncoder::ValidateFinish");
|
||||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||||
|
|
||||||
for (const PassResourceUsage& passUsage : mEncodingContext.GetRenderPassUsages()) {
|
for (const RenderPassResourceUsage& passUsage : mEncodingContext.GetRenderPassUsages()) {
|
||||||
DAWN_TRY(ValidateSyncScopeResourceUsage(passUsage));
|
DAWN_TRY(ValidateSyncScopeResourceUsage(passUsage));
|
||||||
}
|
}
|
||||||
// TODO(dawn:632): The synchronization scopes of compute passes should be validated here
|
// TODO(dawn:632): The synchronization scopes of compute passes should be validated here
|
||||||
|
@ -27,15 +27,14 @@ namespace dawn_native {
|
|||||||
ComputePassEncoder::ComputePassEncoder(DeviceBase* device,
|
ComputePassEncoder::ComputePassEncoder(DeviceBase* device,
|
||||||
CommandEncoder* commandEncoder,
|
CommandEncoder* commandEncoder,
|
||||||
EncodingContext* encodingContext)
|
EncodingContext* encodingContext)
|
||||||
: ProgrammablePassEncoder(device, encodingContext, PassType::Compute),
|
: ProgrammablePassEncoder(device, encodingContext), mCommandEncoder(commandEncoder) {
|
||||||
mCommandEncoder(commandEncoder) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputePassEncoder::ComputePassEncoder(DeviceBase* device,
|
ComputePassEncoder::ComputePassEncoder(DeviceBase* device,
|
||||||
CommandEncoder* commandEncoder,
|
CommandEncoder* commandEncoder,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext,
|
||||||
ErrorTag errorTag)
|
ErrorTag errorTag)
|
||||||
: ProgrammablePassEncoder(device, encodingContext, errorTag, PassType::Compute),
|
: ProgrammablePassEncoder(device, encodingContext, errorTag),
|
||||||
mCommandEncoder(commandEncoder) {
|
mCommandEncoder(commandEncoder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +54,7 @@ namespace dawn_native {
|
|||||||
|
|
||||||
return {};
|
return {};
|
||||||
})) {
|
})) {
|
||||||
mEncodingContext->ExitPass(this, mUsageTracker.AcquireResourceUsage(),
|
mEncodingContext->ExitPass(this, mUsageTracker.AcquireResourceUsage());
|
||||||
PassType::Compute);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +132,29 @@ namespace dawn_native {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComputePassEncoder::APISetBindGroup(uint32_t groupIndexIn,
|
||||||
|
BindGroupBase* group,
|
||||||
|
uint32_t dynamicOffsetCount,
|
||||||
|
const uint32_t* dynamicOffsets) {
|
||||||
|
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
||||||
|
BindGroupIndex groupIndex(groupIndexIn);
|
||||||
|
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
|
DAWN_TRY(
|
||||||
|
ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount, dynamicOffsets));
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount, dynamicOffsets);
|
||||||
|
mCommandBufferState.SetBindGroup(groupIndex, group);
|
||||||
|
|
||||||
|
// TODO(dawn:632): This doesn't match the WebGPU specification. Instead the
|
||||||
|
// synchronization scopes should be created on Dispatch().
|
||||||
|
mUsageTracker.AddBindGroup(group);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void ComputePassEncoder::APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) {
|
void ComputePassEncoder::APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) {
|
||||||
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
||||||
if (IsValidationEnabled()) {
|
if (IsValidationEnabled()) {
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
#ifndef DAWNNATIVE_COMPUTEPASSENCODER_H_
|
#ifndef DAWNNATIVE_COMPUTEPASSENCODER_H_
|
||||||
#define DAWNNATIVE_COMPUTEPASSENCODER_H_
|
#define DAWNNATIVE_COMPUTEPASSENCODER_H_
|
||||||
|
|
||||||
|
#include "dawn_native/CommandBufferStateTracker.h"
|
||||||
#include "dawn_native/Error.h"
|
#include "dawn_native/Error.h"
|
||||||
|
#include "dawn_native/PassResourceUsageTracker.h"
|
||||||
#include "dawn_native/ProgrammablePassEncoder.h"
|
#include "dawn_native/ProgrammablePassEncoder.h"
|
||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
@ -36,6 +38,11 @@ namespace dawn_native {
|
|||||||
void APIDispatchIndirect(BufferBase* indirectBuffer, uint64_t indirectOffset);
|
void APIDispatchIndirect(BufferBase* indirectBuffer, uint64_t indirectOffset);
|
||||||
void APISetPipeline(ComputePipelineBase* pipeline);
|
void APISetPipeline(ComputePipelineBase* pipeline);
|
||||||
|
|
||||||
|
void APISetBindGroup(uint32_t groupIndex,
|
||||||
|
BindGroupBase* group,
|
||||||
|
uint32_t dynamicOffsetCount = 0,
|
||||||
|
const uint32_t* dynamicOffsets = nullptr);
|
||||||
|
|
||||||
void APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex);
|
void APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -45,6 +52,9 @@ namespace dawn_native {
|
|||||||
ErrorTag errorTag);
|
ErrorTag errorTag);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CommandBufferStateTracker mCommandBufferState;
|
||||||
|
ComputePassResourceUsageTracker mUsageTracker;
|
||||||
|
|
||||||
// For render and compute passes, the encoding context is borrowed from the command encoder.
|
// For render and compute passes, the encoding context is borrowed from the command encoder.
|
||||||
// Keep a reference to the encoder to make sure the context isn't freed.
|
// Keep a reference to the encoder to make sure the context isn't freed.
|
||||||
Ref<CommandEncoder> mCommandEncoder;
|
Ref<CommandEncoder> mCommandEncoder;
|
||||||
|
@ -75,21 +75,20 @@ namespace dawn_native {
|
|||||||
mCurrentEncoder = passEncoder;
|
mCurrentEncoder = passEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncodingContext::ExitPass(const ObjectBase* passEncoder,
|
void EncodingContext::ExitPass(const ObjectBase* passEncoder, RenderPassResourceUsage usages) {
|
||||||
PassResourceUsage passUsage,
|
|
||||||
PassType type) {
|
|
||||||
// Assert we're not at the top level.
|
|
||||||
ASSERT(mCurrentEncoder != mTopLevelEncoder);
|
ASSERT(mCurrentEncoder != mTopLevelEncoder);
|
||||||
// Assert the pass encoder is current.
|
|
||||||
ASSERT(mCurrentEncoder == passEncoder);
|
ASSERT(mCurrentEncoder == passEncoder);
|
||||||
|
|
||||||
mCurrentEncoder = mTopLevelEncoder;
|
mCurrentEncoder = mTopLevelEncoder;
|
||||||
|
mRenderPassUsages.push_back(std::move(usages));
|
||||||
if (type == PassType::Render) {
|
|
||||||
mRenderPassUsages.push_back(std::move(passUsage));
|
|
||||||
} else {
|
|
||||||
mComputePassUsages.push_back(std::move(passUsage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EncodingContext::ExitPass(const ObjectBase* passEncoder, ComputePassResourceUsage usages) {
|
||||||
|
ASSERT(mCurrentEncoder != mTopLevelEncoder);
|
||||||
|
ASSERT(mCurrentEncoder == passEncoder);
|
||||||
|
|
||||||
|
mCurrentEncoder = mTopLevelEncoder;
|
||||||
|
mComputePassUsages.push_back(std::move(usages));
|
||||||
}
|
}
|
||||||
|
|
||||||
const RenderPassUsages& EncodingContext::GetRenderPassUsages() const {
|
const RenderPassUsages& EncodingContext::GetRenderPassUsages() const {
|
||||||
|
@ -74,7 +74,8 @@ namespace dawn_native {
|
|||||||
|
|
||||||
// Functions to set current encoder state
|
// Functions to set current encoder state
|
||||||
void EnterPass(const ObjectBase* passEncoder);
|
void EnterPass(const ObjectBase* passEncoder);
|
||||||
void ExitPass(const ObjectBase* passEncoder, PassResourceUsage passUsages, PassType type);
|
void ExitPass(const ObjectBase* passEncoder, RenderPassResourceUsage usages);
|
||||||
|
void ExitPass(const ObjectBase* passEncoder, ComputePassResourceUsage usages);
|
||||||
MaybeError Finish();
|
MaybeError Finish();
|
||||||
|
|
||||||
const RenderPassUsages& GetRenderPassUsages() const;
|
const RenderPassUsages& GetRenderPassUsages() const;
|
||||||
|
@ -23,12 +23,15 @@
|
|||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
|
// This file declares various "ResourceUsage" structures. They are produced by the frontend
|
||||||
|
// while recording commands to be used for later validation and also some operations in the
|
||||||
|
// backends. The are produced by the "Encoder" objects that finalize them on "EndPass" or
|
||||||
|
// "Finish". Internally the "Encoder" may use the "StateTracker" to create them.
|
||||||
|
|
||||||
class BufferBase;
|
class BufferBase;
|
||||||
class QuerySetBase;
|
class QuerySetBase;
|
||||||
class TextureBase;
|
class TextureBase;
|
||||||
|
|
||||||
enum class PassType { Render, Compute };
|
|
||||||
|
|
||||||
// The texture usage inside passes must be tracked per-subresource.
|
// The texture usage inside passes must be tracked per-subresource.
|
||||||
using TextureSubresourceUsage = SubresourceStorage<wgpu::TextureUsage>;
|
using TextureSubresourceUsage = SubresourceStorage<wgpu::TextureUsage>;
|
||||||
|
|
||||||
@ -43,18 +46,36 @@ namespace dawn_native {
|
|||||||
std::vector<TextureSubresourceUsage> textureUsages;
|
std::vector<TextureSubresourceUsage> textureUsages;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Additional data tracked per-pass.
|
// Contains all the resource usage data for a compute pass.
|
||||||
struct PassResourceUsage : public SyncScopeResourceUsage {
|
//
|
||||||
|
// TODO(dawn:632) Not now, but in the future, compute passes will contain a list of
|
||||||
|
// SyncScopeResourceUsage, one per Dispatch as required by the WebGPU specification. They will
|
||||||
|
// also store inline the set of all buffers and textures used, because some unused BindGroups
|
||||||
|
// may not be used at all in synchronization scope but their resources still need to be
|
||||||
|
// validated on Queue::Submit.
|
||||||
|
struct ComputePassResourceUsage : public SyncScopeResourceUsage {};
|
||||||
|
|
||||||
|
// Contains all the resource usage data for a render pass.
|
||||||
|
//
|
||||||
|
// In the WebGPU specification render passes are synchronization scopes but we also need to
|
||||||
|
// track additional data. It is stored for render passes used by a CommandBuffer, but also in
|
||||||
|
// RenderBundle so they can be merged into the render passes' usage on ExecuteBundles().
|
||||||
|
struct RenderPassResourceUsage : public SyncScopeResourceUsage {
|
||||||
|
// Storage to track the occlusion queries used during the pass.
|
||||||
std::vector<QuerySetBase*> querySets;
|
std::vector<QuerySetBase*> querySets;
|
||||||
std::vector<std::vector<bool>> queryAvailabilities;
|
std::vector<std::vector<bool>> queryAvailabilities;
|
||||||
};
|
};
|
||||||
|
|
||||||
using RenderPassUsages = std::vector<PassResourceUsage>;
|
using RenderPassUsages = std::vector<RenderPassResourceUsage>;
|
||||||
using ComputePassUsages = std::vector<PassResourceUsage>;
|
using ComputePassUsages = std::vector<ComputePassResourceUsage>;
|
||||||
|
|
||||||
|
// Contains a hierarchy of "ResourceUsage" that mirrors the hierarchy of the CommandBuffer and
|
||||||
|
// is used for validation and to produce barriers and lazy clears in the backends.
|
||||||
struct CommandBufferResourceUsage {
|
struct CommandBufferResourceUsage {
|
||||||
RenderPassUsages renderPasses;
|
RenderPassUsages renderPasses;
|
||||||
ComputePassUsages computePasses;
|
ComputePassUsages computePasses;
|
||||||
|
|
||||||
|
// Resources used in commands that aren't in a pass.
|
||||||
std::set<BufferBase*> topLevelBuffers;
|
std::set<BufferBase*> topLevelBuffers;
|
||||||
std::set<TextureBase*> topLevelTextures;
|
std::set<TextureBase*> topLevelTextures;
|
||||||
std::set<QuerySetBase*> usedQuerySets;
|
std::set<QuerySetBase*> usedQuerySets;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "dawn_native/PassResourceUsageTracker.h"
|
#include "dawn_native/PassResourceUsageTracker.h"
|
||||||
|
|
||||||
|
#include "dawn_native/BindGroup.h"
|
||||||
#include "dawn_native/Buffer.h"
|
#include "dawn_native/Buffer.h"
|
||||||
#include "dawn_native/EnumMaskIterator.h"
|
#include "dawn_native/EnumMaskIterator.h"
|
||||||
#include "dawn_native/Format.h"
|
#include "dawn_native/Format.h"
|
||||||
@ -23,17 +24,14 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
PassResourceUsageTracker::PassResourceUsageTracker(PassType passType) : mPassType(passType) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void PassResourceUsageTracker::BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage) {
|
void SyncScopeUsageTracker::BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage) {
|
||||||
// std::map's operator[] will create the key and return 0 if the key didn't exist
|
// std::map's operator[] will create the key and return 0 if the key didn't exist
|
||||||
// before.
|
// before.
|
||||||
mBufferUsages[buffer] |= usage;
|
mBufferUsages[buffer] |= usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassResourceUsageTracker::TextureViewUsedAs(TextureViewBase* view,
|
void SyncScopeUsageTracker::TextureViewUsedAs(TextureViewBase* view, wgpu::TextureUsage usage) {
|
||||||
wgpu::TextureUsage usage) {
|
|
||||||
TextureBase* texture = view->GetTexture();
|
TextureBase* texture = view->GetTexture();
|
||||||
const SubresourceRange& range = view->GetSubresourceRange();
|
const SubresourceRange& range = view->GetSubresourceRange();
|
||||||
|
|
||||||
@ -51,7 +49,7 @@ namespace dawn_native {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassResourceUsageTracker::AddTextureUsage(TextureBase* texture,
|
void SyncScopeUsageTracker::AddTextureUsage(TextureBase* texture,
|
||||||
const TextureSubresourceUsage& textureUsage) {
|
const TextureSubresourceUsage& textureUsage) {
|
||||||
// Get or create a new TextureSubresourceUsage for that texture (initially filled with
|
// Get or create a new TextureSubresourceUsage for that texture (initially filled with
|
||||||
// wgpu::TextureUsage::None)
|
// wgpu::TextureUsage::None)
|
||||||
@ -66,32 +64,63 @@ namespace dawn_native {
|
|||||||
const wgpu::TextureUsage& addedUsage) { *storedUsage |= addedUsage; });
|
const wgpu::TextureUsage& addedUsage) { *storedUsage |= addedUsage; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassResourceUsageTracker::TrackQueryAvailability(QuerySetBase* querySet,
|
void SyncScopeUsageTracker::AddBindGroup(BindGroupBase* group) {
|
||||||
uint32_t queryIndex) {
|
for (BindingIndex bindingIndex{0}; bindingIndex < group->GetLayout()->GetBindingCount();
|
||||||
// The query availability only need to be tracked again on render pass for checking query
|
++bindingIndex) {
|
||||||
// overwrite on render pass and resetting query set on Vulkan backend.
|
const BindingInfo& bindingInfo = group->GetLayout()->GetBindingInfo(bindingIndex);
|
||||||
DAWN_ASSERT(mPassType == PassType::Render);
|
|
||||||
DAWN_ASSERT(querySet != nullptr);
|
|
||||||
|
|
||||||
// Gets the iterator for that querySet or create a new vector of bool set to false
|
switch (bindingInfo.bindingType) {
|
||||||
// if the querySet wasn't registered.
|
case BindingInfoType::Buffer: {
|
||||||
auto it = mQueryAvailabilities.emplace(querySet, querySet->GetQueryCount()).first;
|
BufferBase* buffer = group->GetBindingAsBufferBinding(bindingIndex).buffer;
|
||||||
it->second[queryIndex] = true;
|
switch (bindingInfo.buffer.type) {
|
||||||
|
case wgpu::BufferBindingType::Uniform:
|
||||||
|
BufferUsedAs(buffer, wgpu::BufferUsage::Uniform);
|
||||||
|
break;
|
||||||
|
case wgpu::BufferBindingType::Storage:
|
||||||
|
BufferUsedAs(buffer, wgpu::BufferUsage::Storage);
|
||||||
|
break;
|
||||||
|
case wgpu::BufferBindingType::ReadOnlyStorage:
|
||||||
|
BufferUsedAs(buffer, kReadOnlyStorageBuffer);
|
||||||
|
break;
|
||||||
|
case wgpu::BufferBindingType::Undefined:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QueryAvailabilityMap& PassResourceUsageTracker::GetQueryAvailabilityMap() const {
|
case BindingInfoType::Texture: {
|
||||||
return mQueryAvailabilities;
|
TextureViewBase* view = group->GetBindingAsTextureView(bindingIndex);
|
||||||
|
TextureViewUsedAs(view, wgpu::TextureUsage::Sampled);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the per-pass usage for use by backends for APIs with explicit barriers.
|
case BindingInfoType::StorageTexture: {
|
||||||
PassResourceUsage PassResourceUsageTracker::AcquireResourceUsage() {
|
TextureViewBase* view = group->GetBindingAsTextureView(bindingIndex);
|
||||||
PassResourceUsage result;
|
switch (bindingInfo.storageTexture.access) {
|
||||||
|
case wgpu::StorageTextureAccess::ReadOnly:
|
||||||
|
TextureViewUsedAs(view, kReadOnlyStorageTexture);
|
||||||
|
break;
|
||||||
|
case wgpu::StorageTextureAccess::WriteOnly:
|
||||||
|
TextureViewUsedAs(view, wgpu::TextureUsage::Storage);
|
||||||
|
break;
|
||||||
|
case wgpu::StorageTextureAccess::Undefined:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BindingInfoType::Sampler:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncScopeResourceUsage SyncScopeUsageTracker::AcquireSyncScopeUsage() {
|
||||||
|
SyncScopeResourceUsage result;
|
||||||
result.buffers.reserve(mBufferUsages.size());
|
result.buffers.reserve(mBufferUsages.size());
|
||||||
result.bufferUsages.reserve(mBufferUsages.size());
|
result.bufferUsages.reserve(mBufferUsages.size());
|
||||||
result.textures.reserve(mTextureUsages.size());
|
result.textures.reserve(mTextureUsages.size());
|
||||||
result.textureUsages.reserve(mTextureUsages.size());
|
result.textureUsages.reserve(mTextureUsages.size());
|
||||||
result.querySets.reserve(mQueryAvailabilities.size());
|
|
||||||
result.queryAvailabilities.reserve(mQueryAvailabilities.size());
|
|
||||||
|
|
||||||
for (auto& it : mBufferUsages) {
|
for (auto& it : mBufferUsages) {
|
||||||
result.buffers.push_back(it.first);
|
result.buffers.push_back(it.first);
|
||||||
@ -103,16 +132,49 @@ namespace dawn_native {
|
|||||||
result.textureUsages.push_back(std::move(it.second));
|
result.textureUsages.push_back(std::move(it.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mBufferUsages.clear();
|
||||||
|
mTextureUsages.clear();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ComputePassResourceUsage ComputePassResourceUsageTracker::AcquireResourceUsage() {
|
||||||
|
ComputePassResourceUsage result;
|
||||||
|
*static_cast<SyncScopeResourceUsage*>(&result) = AcquireSyncScopeUsage();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderPassResourceUsage RenderPassResourceUsageTracker::AcquireResourceUsage() {
|
||||||
|
RenderPassResourceUsage result;
|
||||||
|
*static_cast<SyncScopeResourceUsage*>(&result) = AcquireSyncScopeUsage();
|
||||||
|
|
||||||
|
result.querySets.reserve(mQueryAvailabilities.size());
|
||||||
|
result.queryAvailabilities.reserve(mQueryAvailabilities.size());
|
||||||
|
|
||||||
for (auto& it : mQueryAvailabilities) {
|
for (auto& it : mQueryAvailabilities) {
|
||||||
result.querySets.push_back(it.first);
|
result.querySets.push_back(it.first);
|
||||||
result.queryAvailabilities.push_back(std::move(it.second));
|
result.queryAvailabilities.push_back(std::move(it.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
mBufferUsages.clear();
|
|
||||||
mTextureUsages.clear();
|
|
||||||
mQueryAvailabilities.clear();
|
mQueryAvailabilities.clear();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderPassResourceUsageTracker::TrackQueryAvailability(QuerySetBase* querySet,
|
||||||
|
uint32_t queryIndex) {
|
||||||
|
// The query availability only needs to be tracked again on render passes for checking
|
||||||
|
// query overwrite on render pass and resetting query sets on the Vulkan backend.
|
||||||
|
DAWN_ASSERT(querySet != nullptr);
|
||||||
|
|
||||||
|
// Gets the iterator for that querySet or create a new vector of bool set to false
|
||||||
|
// if the querySet wasn't registered.
|
||||||
|
auto it = mQueryAvailabilities.emplace(querySet, querySet->GetQueryCount()).first;
|
||||||
|
it->second[queryIndex] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QueryAvailabilityMap& RenderPassResourceUsageTracker::GetQueryAvailabilityMap() const {
|
||||||
|
return mQueryAvailabilities;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace dawn_native
|
||||||
|
@ -23,35 +23,56 @@
|
|||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
|
class BindGroupBase;
|
||||||
class BufferBase;
|
class BufferBase;
|
||||||
class QuerySetBase;
|
class QuerySetBase;
|
||||||
class TextureBase;
|
class TextureBase;
|
||||||
|
|
||||||
using QueryAvailabilityMap = std::map<QuerySetBase*, std::vector<bool>>;
|
using QueryAvailabilityMap = std::map<QuerySetBase*, std::vector<bool>>;
|
||||||
|
|
||||||
// Helper class to encapsulate the logic of tracking per-resource usage during the
|
// Helper class to build SyncScopeResourceUsages
|
||||||
// validation of command buffer passes. It is used both to know if there are validation
|
class SyncScopeUsageTracker {
|
||||||
// errors, and to get a list of resources used per pass for backends that need the
|
|
||||||
// information.
|
|
||||||
class PassResourceUsageTracker {
|
|
||||||
public:
|
public:
|
||||||
PassResourceUsageTracker(PassType passType);
|
|
||||||
void BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage);
|
void BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage);
|
||||||
void TextureViewUsedAs(TextureViewBase* texture, wgpu::TextureUsage usage);
|
void TextureViewUsedAs(TextureViewBase* texture, wgpu::TextureUsage usage);
|
||||||
void AddTextureUsage(TextureBase* texture, const TextureSubresourceUsage& textureUsage);
|
void AddTextureUsage(TextureBase* texture, const TextureSubresourceUsage& textureUsage);
|
||||||
|
|
||||||
|
// Walks the bind groups and tracks all its resources.
|
||||||
|
void AddBindGroup(BindGroupBase* group);
|
||||||
|
|
||||||
|
// Returns the per-pass usage for use by backends for APIs with explicit barriers.
|
||||||
|
SyncScopeResourceUsage AcquireSyncScopeUsage();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<BufferBase*, wgpu::BufferUsage> mBufferUsages;
|
||||||
|
std::map<TextureBase*, TextureSubresourceUsage> mTextureUsages;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper class to build ComputePassResourceUsages
|
||||||
|
class ComputePassResourceUsageTracker : public SyncScopeUsageTracker {
|
||||||
|
public:
|
||||||
|
ComputePassResourceUsage AcquireResourceUsage();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Hide AcquireSyncScopeUsage since users of this class should use AcquireResourceUsage
|
||||||
|
// instead.
|
||||||
|
using SyncScopeUsageTracker::AcquireSyncScopeUsage;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper class to build RenderPassResourceUsages
|
||||||
|
class RenderPassResourceUsageTracker : public SyncScopeUsageTracker {
|
||||||
|
public:
|
||||||
void TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex);
|
void TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex);
|
||||||
const QueryAvailabilityMap& GetQueryAvailabilityMap() const;
|
const QueryAvailabilityMap& GetQueryAvailabilityMap() const;
|
||||||
|
|
||||||
// Returns the per-pass usage for use by backends for APIs with explicit barriers.
|
RenderPassResourceUsage AcquireResourceUsage();
|
||||||
PassResourceUsage AcquireResourceUsage();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PassType mPassType;
|
// Hide AcquireSyncScopeUsage since users of this class should use AcquireResourceUsage
|
||||||
std::map<BufferBase*, wgpu::BufferUsage> mBufferUsages;
|
// instead.
|
||||||
std::map<TextureBase*, TextureSubresourceUsage> mTextureUsages;
|
using SyncScopeUsageTracker::AcquireSyncScopeUsage;
|
||||||
// Dedicated to track the availability of the queries used on render pass. The same query
|
|
||||||
// cannot be written twice in same render pass, so each render pass also need to have its
|
// Tracks queries used in the render pass to validate that they aren't written twice.
|
||||||
// own query availability map for validation.
|
|
||||||
QueryAvailabilityMap mQueryAvailabilities;
|
QueryAvailabilityMap mQueryAvailabilities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,76 +27,18 @@
|
|||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
|
|
||||||
namespace {
|
|
||||||
void TrackBindGroupResourceUsage(PassResourceUsageTracker* usageTracker,
|
|
||||||
BindGroupBase* group) {
|
|
||||||
for (BindingIndex bindingIndex{0}; bindingIndex < group->GetLayout()->GetBindingCount();
|
|
||||||
++bindingIndex) {
|
|
||||||
const BindingInfo& bindingInfo = group->GetLayout()->GetBindingInfo(bindingIndex);
|
|
||||||
|
|
||||||
switch (bindingInfo.bindingType) {
|
|
||||||
case BindingInfoType::Buffer: {
|
|
||||||
BufferBase* buffer = group->GetBindingAsBufferBinding(bindingIndex).buffer;
|
|
||||||
switch (bindingInfo.buffer.type) {
|
|
||||||
case wgpu::BufferBindingType::Uniform:
|
|
||||||
usageTracker->BufferUsedAs(buffer, wgpu::BufferUsage::Uniform);
|
|
||||||
break;
|
|
||||||
case wgpu::BufferBindingType::Storage:
|
|
||||||
usageTracker->BufferUsedAs(buffer, wgpu::BufferUsage::Storage);
|
|
||||||
break;
|
|
||||||
case wgpu::BufferBindingType::ReadOnlyStorage:
|
|
||||||
usageTracker->BufferUsedAs(buffer, kReadOnlyStorageBuffer);
|
|
||||||
break;
|
|
||||||
case wgpu::BufferBindingType::Undefined:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BindingInfoType::Texture: {
|
|
||||||
TextureViewBase* view = group->GetBindingAsTextureView(bindingIndex);
|
|
||||||
usageTracker->TextureViewUsedAs(view, wgpu::TextureUsage::Sampled);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BindingInfoType::StorageTexture: {
|
|
||||||
TextureViewBase* view = group->GetBindingAsTextureView(bindingIndex);
|
|
||||||
switch (bindingInfo.storageTexture.access) {
|
|
||||||
case wgpu::StorageTextureAccess::ReadOnly:
|
|
||||||
usageTracker->TextureViewUsedAs(view, kReadOnlyStorageTexture);
|
|
||||||
break;
|
|
||||||
case wgpu::StorageTextureAccess::WriteOnly:
|
|
||||||
usageTracker->TextureViewUsedAs(view, wgpu::TextureUsage::Storage);
|
|
||||||
break;
|
|
||||||
case wgpu::StorageTextureAccess::Undefined:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case BindingInfoType::Sampler:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
|
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext)
|
||||||
PassType passType)
|
|
||||||
: ObjectBase(device),
|
: ObjectBase(device),
|
||||||
mEncodingContext(encodingContext),
|
mEncodingContext(encodingContext),
|
||||||
mUsageTracker(passType),
|
|
||||||
mValidationEnabled(device->IsValidationEnabled()) {
|
mValidationEnabled(device->IsValidationEnabled()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
|
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext,
|
||||||
ErrorTag errorTag,
|
ErrorTag errorTag)
|
||||||
PassType passType)
|
|
||||||
: ObjectBase(device, errorTag),
|
: ObjectBase(device, errorTag),
|
||||||
mEncodingContext(encodingContext),
|
mEncodingContext(encodingContext),
|
||||||
mUsageTracker(passType),
|
|
||||||
mValidationEnabled(device->IsValidationEnabled()) {
|
mValidationEnabled(device->IsValidationEnabled()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,22 +95,19 @@ namespace dawn_native {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgrammablePassEncoder::APISetBindGroup(uint32_t groupIndexIn,
|
MaybeError ProgrammablePassEncoder::ValidateSetBindGroup(
|
||||||
|
BindGroupIndex index,
|
||||||
BindGroupBase* group,
|
BindGroupBase* group,
|
||||||
uint32_t dynamicOffsetCountIn,
|
uint32_t dynamicOffsetCountIn,
|
||||||
const uint32_t* dynamicOffsetsIn) {
|
const uint32_t* dynamicOffsetsIn) const {
|
||||||
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
|
||||||
BindGroupIndex groupIndex(groupIndexIn);
|
|
||||||
|
|
||||||
if (IsValidationEnabled()) {
|
|
||||||
DAWN_TRY(GetDevice()->ValidateObject(group));
|
DAWN_TRY(GetDevice()->ValidateObject(group));
|
||||||
|
|
||||||
if (groupIndex >= kMaxBindGroupsTyped) {
|
if (index >= kMaxBindGroupsTyped) {
|
||||||
return DAWN_VALIDATION_ERROR("Setting bind group over the max");
|
return DAWN_VALIDATION_ERROR("Setting bind group over the max");
|
||||||
}
|
}
|
||||||
|
|
||||||
ityp::span<BindingIndex, const uint32_t> dynamicOffsets(
|
ityp::span<BindingIndex, const uint32_t> dynamicOffsets(dynamicOffsetsIn,
|
||||||
dynamicOffsetsIn, BindingIndex(dynamicOffsetCountIn));
|
BindingIndex(dynamicOffsetCountIn));
|
||||||
|
|
||||||
// Dynamic offsets count must match the number required by the layout perfectly.
|
// Dynamic offsets count must match the number required by the layout perfectly.
|
||||||
const BindGroupLayoutBase* layout = group->GetLayout();
|
const BindGroupLayoutBase* layout = group->GetLayout();
|
||||||
@ -193,11 +132,10 @@ namespace dawn_native {
|
|||||||
// During BindGroup creation, validation ensures binding offset + binding size
|
// During BindGroup creation, validation ensures binding offset + binding size
|
||||||
// <= buffer size.
|
// <= buffer size.
|
||||||
ASSERT(bufferBinding.buffer->GetSize() >= bufferBinding.size);
|
ASSERT(bufferBinding.buffer->GetSize() >= bufferBinding.size);
|
||||||
ASSERT(bufferBinding.buffer->GetSize() - bufferBinding.size >=
|
ASSERT(bufferBinding.buffer->GetSize() - bufferBinding.size >= bufferBinding.offset);
|
||||||
bufferBinding.offset);
|
|
||||||
|
|
||||||
if ((dynamicOffsets[i] > bufferBinding.buffer->GetSize() -
|
if ((dynamicOffsets[i] >
|
||||||
bufferBinding.offset - bufferBinding.size)) {
|
bufferBinding.buffer->GetSize() - bufferBinding.offset - bufferBinding.size)) {
|
||||||
if ((bufferBinding.buffer->GetSize() - bufferBinding.offset) ==
|
if ((bufferBinding.buffer->GetSize() - bufferBinding.offset) ==
|
||||||
bufferBinding.size) {
|
bufferBinding.size) {
|
||||||
return DAWN_VALIDATION_ERROR(
|
return DAWN_VALIDATION_ERROR(
|
||||||
@ -209,23 +147,23 @@ namespace dawn_native {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mCommandBufferState.SetBindGroup(groupIndex, group);
|
|
||||||
|
|
||||||
SetBindGroupCmd* cmd = allocator->Allocate<SetBindGroupCmd>(Command::SetBindGroup);
|
|
||||||
cmd->index = groupIndex;
|
|
||||||
cmd->group = group;
|
|
||||||
cmd->dynamicOffsetCount = dynamicOffsetCountIn;
|
|
||||||
if (dynamicOffsetCountIn > 0) {
|
|
||||||
uint32_t* offsets = allocator->AllocateData<uint32_t>(cmd->dynamicOffsetCount);
|
|
||||||
memcpy(offsets, dynamicOffsetsIn, dynamicOffsetCountIn * sizeof(uint32_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
TrackBindGroupResourceUsage(&mUsageTracker, group);
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
}
|
||||||
|
|
||||||
|
void ProgrammablePassEncoder::RecordSetBindGroup(CommandAllocator* allocator,
|
||||||
|
BindGroupIndex index,
|
||||||
|
BindGroupBase* group,
|
||||||
|
uint32_t dynamicOffsetCount,
|
||||||
|
const uint32_t* dynamicOffsets) const {
|
||||||
|
SetBindGroupCmd* cmd = allocator->Allocate<SetBindGroupCmd>(Command::SetBindGroup);
|
||||||
|
cmd->index = index;
|
||||||
|
cmd->group = group;
|
||||||
|
cmd->dynamicOffsetCount = dynamicOffsetCount;
|
||||||
|
if (dynamicOffsetCount > 0) {
|
||||||
|
uint32_t* offsets = allocator->AllocateData<uint32_t>(cmd->dynamicOffsetCount);
|
||||||
|
memcpy(offsets, dynamicOffsets, dynamicOffsetCount * sizeof(uint32_t));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace dawn_native
|
||||||
|
@ -15,11 +15,10 @@
|
|||||||
#ifndef DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
|
#ifndef DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
|
||||||
#define DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
|
#define DAWNNATIVE_PROGRAMMABLEPASSENCODER_H_
|
||||||
|
|
||||||
#include "dawn_native/CommandBufferStateTracker.h"
|
|
||||||
#include "dawn_native/CommandEncoder.h"
|
#include "dawn_native/CommandEncoder.h"
|
||||||
#include "dawn_native/Error.h"
|
#include "dawn_native/Error.h"
|
||||||
|
#include "dawn_native/IntegerTypes.h"
|
||||||
#include "dawn_native/ObjectBase.h"
|
#include "dawn_native/ObjectBase.h"
|
||||||
#include "dawn_native/PassResourceUsageTracker.h"
|
|
||||||
|
|
||||||
#include "dawn_native/dawn_platform.h"
|
#include "dawn_native/dawn_platform.h"
|
||||||
|
|
||||||
@ -30,34 +29,36 @@ namespace dawn_native {
|
|||||||
// Base class for shared functionality between ComputePassEncoder and RenderPassEncoder.
|
// Base class for shared functionality between ComputePassEncoder and RenderPassEncoder.
|
||||||
class ProgrammablePassEncoder : public ObjectBase {
|
class ProgrammablePassEncoder : public ObjectBase {
|
||||||
public:
|
public:
|
||||||
ProgrammablePassEncoder(DeviceBase* device,
|
ProgrammablePassEncoder(DeviceBase* device, EncodingContext* encodingContext);
|
||||||
EncodingContext* encodingContext,
|
|
||||||
PassType passType);
|
|
||||||
|
|
||||||
void APIInsertDebugMarker(const char* groupLabel);
|
void APIInsertDebugMarker(const char* groupLabel);
|
||||||
void APIPopDebugGroup();
|
void APIPopDebugGroup();
|
||||||
void APIPushDebugGroup(const char* groupLabel);
|
void APIPushDebugGroup(const char* groupLabel);
|
||||||
|
|
||||||
void APISetBindGroup(uint32_t groupIndex,
|
|
||||||
BindGroupBase* group,
|
|
||||||
uint32_t dynamicOffsetCount = 0,
|
|
||||||
const uint32_t* dynamicOffsets = nullptr);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool IsValidationEnabled() const;
|
bool IsValidationEnabled() const;
|
||||||
MaybeError ValidateProgrammableEncoderEnd() const;
|
MaybeError ValidateProgrammableEncoderEnd() const;
|
||||||
|
|
||||||
|
// Compute and render passes do different things on SetBindGroup. These are helper functions
|
||||||
|
// for the logic they have in common.
|
||||||
|
MaybeError ValidateSetBindGroup(BindGroupIndex index,
|
||||||
|
BindGroupBase* group,
|
||||||
|
uint32_t dynamicOffsetCountIn,
|
||||||
|
const uint32_t* dynamicOffsetsIn) const;
|
||||||
|
void RecordSetBindGroup(CommandAllocator* allocator,
|
||||||
|
BindGroupIndex index,
|
||||||
|
BindGroupBase* group,
|
||||||
|
uint32_t dynamicOffsetCount,
|
||||||
|
const uint32_t* dynamicOffsets) const;
|
||||||
|
|
||||||
// Construct an "error" programmable pass encoder.
|
// Construct an "error" programmable pass encoder.
|
||||||
ProgrammablePassEncoder(DeviceBase* device,
|
ProgrammablePassEncoder(DeviceBase* device,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext,
|
||||||
ErrorTag errorTag,
|
ErrorTag errorTag);
|
||||||
PassType passType);
|
|
||||||
|
|
||||||
EncodingContext* mEncodingContext = nullptr;
|
EncodingContext* mEncodingContext = nullptr;
|
||||||
PassResourceUsageTracker mUsageTracker;
|
|
||||||
|
|
||||||
uint64_t mDebugGroupStackSize = 0;
|
uint64_t mDebugGroupStackSize = 0;
|
||||||
CommandBufferStateTracker mCommandBufferState;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const bool mValidationEnabled;
|
const bool mValidationEnabled;
|
||||||
|
@ -24,7 +24,7 @@ namespace dawn_native {
|
|||||||
RenderBundleBase::RenderBundleBase(RenderBundleEncoder* encoder,
|
RenderBundleBase::RenderBundleBase(RenderBundleEncoder* encoder,
|
||||||
const RenderBundleDescriptor* descriptor,
|
const RenderBundleDescriptor* descriptor,
|
||||||
Ref<AttachmentState> attachmentState,
|
Ref<AttachmentState> attachmentState,
|
||||||
PassResourceUsage resourceUsage)
|
RenderPassResourceUsage resourceUsage)
|
||||||
: ObjectBase(encoder->GetDevice()),
|
: ObjectBase(encoder->GetDevice()),
|
||||||
mCommands(encoder->AcquireCommands()),
|
mCommands(encoder->AcquireCommands()),
|
||||||
mAttachmentState(std::move(attachmentState)),
|
mAttachmentState(std::move(attachmentState)),
|
||||||
@ -53,7 +53,7 @@ namespace dawn_native {
|
|||||||
return mAttachmentState.Get();
|
return mAttachmentState.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const PassResourceUsage& RenderBundleBase::GetResourceUsage() const {
|
const RenderPassResourceUsage& RenderBundleBase::GetResourceUsage() const {
|
||||||
ASSERT(!IsError());
|
ASSERT(!IsError());
|
||||||
return mResourceUsage;
|
return mResourceUsage;
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,14 @@ namespace dawn_native {
|
|||||||
RenderBundleBase(RenderBundleEncoder* encoder,
|
RenderBundleBase(RenderBundleEncoder* encoder,
|
||||||
const RenderBundleDescriptor* descriptor,
|
const RenderBundleDescriptor* descriptor,
|
||||||
Ref<AttachmentState> attachmentState,
|
Ref<AttachmentState> attachmentState,
|
||||||
PassResourceUsage resourceUsage);
|
RenderPassResourceUsage resourceUsage);
|
||||||
|
|
||||||
static RenderBundleBase* MakeError(DeviceBase* device);
|
static RenderBundleBase* MakeError(DeviceBase* device);
|
||||||
|
|
||||||
CommandIterator* GetCommands();
|
CommandIterator* GetCommands();
|
||||||
|
|
||||||
const AttachmentState* GetAttachmentState() const;
|
const AttachmentState* GetAttachmentState() const;
|
||||||
const PassResourceUsage& GetResourceUsage() const;
|
const RenderPassResourceUsage& GetResourceUsage() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~RenderBundleBase() override;
|
~RenderBundleBase() override;
|
||||||
@ -53,7 +53,7 @@ namespace dawn_native {
|
|||||||
|
|
||||||
CommandIterator mCommands;
|
CommandIterator mCommands;
|
||||||
Ref<AttachmentState> mAttachmentState;
|
Ref<AttachmentState> mAttachmentState;
|
||||||
PassResourceUsage mResourceUsage;
|
RenderPassResourceUsage mResourceUsage;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace dawn_native
|
||||||
|
@ -123,18 +123,17 @@ namespace dawn_native {
|
|||||||
// errors.
|
// errors.
|
||||||
DAWN_TRY(mBundleEncodingContext.Finish());
|
DAWN_TRY(mBundleEncodingContext.Finish());
|
||||||
|
|
||||||
PassResourceUsage usages = mUsageTracker.AcquireResourceUsage();
|
RenderPassResourceUsage usages = mUsageTracker.AcquireResourceUsage();
|
||||||
if (IsValidationEnabled()) {
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||||
DAWN_TRY(ValidateProgrammableEncoderEnd());
|
DAWN_TRY(ValidateProgrammableEncoderEnd());
|
||||||
DAWN_TRY(ValidateFinish(mBundleEncodingContext.GetIterator(), usages));
|
DAWN_TRY(ValidateFinish(usages));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RenderBundleBase(this, descriptor, AcquireAttachmentState(), std::move(usages));
|
return new RenderBundleBase(this, descriptor, AcquireAttachmentState(), std::move(usages));
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError RenderBundleEncoder::ValidateFinish(CommandIterator* commands,
|
MaybeError RenderBundleEncoder::ValidateFinish(const RenderPassResourceUsage& usages) const {
|
||||||
const PassResourceUsage& usages) const {
|
|
||||||
TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "RenderBundleEncoder::ValidateFinish");
|
TRACE_EVENT0(GetDevice()->GetPlatform(), Validation, "RenderBundleEncoder::ValidateFinish");
|
||||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||||
DAWN_TRY(ValidateSyncScopeResourceUsage(usages));
|
DAWN_TRY(ValidateSyncScopeResourceUsage(usages));
|
||||||
|
@ -41,7 +41,7 @@ namespace dawn_native {
|
|||||||
RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag);
|
RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag);
|
||||||
|
|
||||||
ResultOrError<RenderBundleBase*> FinishImpl(const RenderBundleDescriptor* descriptor);
|
ResultOrError<RenderBundleBase*> FinishImpl(const RenderBundleDescriptor* descriptor);
|
||||||
MaybeError ValidateFinish(CommandIterator* commands, const PassResourceUsage& usages) const;
|
MaybeError ValidateFinish(const RenderPassResourceUsage& usages) const;
|
||||||
|
|
||||||
EncodingContext mBundleEncodingContext;
|
EncodingContext mBundleEncodingContext;
|
||||||
};
|
};
|
||||||
|
@ -32,7 +32,7 @@ namespace dawn_native {
|
|||||||
RenderEncoderBase::RenderEncoderBase(DeviceBase* device,
|
RenderEncoderBase::RenderEncoderBase(DeviceBase* device,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext,
|
||||||
Ref<AttachmentState> attachmentState)
|
Ref<AttachmentState> attachmentState)
|
||||||
: ProgrammablePassEncoder(device, encodingContext, PassType::Render),
|
: ProgrammablePassEncoder(device, encodingContext),
|
||||||
mAttachmentState(std::move(attachmentState)),
|
mAttachmentState(std::move(attachmentState)),
|
||||||
mDisableBaseVertex(device->IsToggleEnabled(Toggle::DisableBaseVertex)),
|
mDisableBaseVertex(device->IsToggleEnabled(Toggle::DisableBaseVertex)),
|
||||||
mDisableBaseInstance(device->IsToggleEnabled(Toggle::DisableBaseInstance)) {
|
mDisableBaseInstance(device->IsToggleEnabled(Toggle::DisableBaseInstance)) {
|
||||||
@ -41,7 +41,7 @@ namespace dawn_native {
|
|||||||
RenderEncoderBase::RenderEncoderBase(DeviceBase* device,
|
RenderEncoderBase::RenderEncoderBase(DeviceBase* device,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext,
|
||||||
ErrorTag errorTag)
|
ErrorTag errorTag)
|
||||||
: ProgrammablePassEncoder(device, encodingContext, errorTag, PassType::Render),
|
: ProgrammablePassEncoder(device, encodingContext, errorTag),
|
||||||
mDisableBaseVertex(device->IsToggleEnabled(Toggle::DisableBaseVertex)),
|
mDisableBaseVertex(device->IsToggleEnabled(Toggle::DisableBaseVertex)),
|
||||||
mDisableBaseInstance(device->IsToggleEnabled(Toggle::DisableBaseInstance)) {
|
mDisableBaseInstance(device->IsToggleEnabled(Toggle::DisableBaseInstance)) {
|
||||||
}
|
}
|
||||||
@ -308,4 +308,24 @@ namespace dawn_native {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderEncoderBase::APISetBindGroup(uint32_t groupIndexIn,
|
||||||
|
BindGroupBase* group,
|
||||||
|
uint32_t dynamicOffsetCount,
|
||||||
|
const uint32_t* dynamicOffsets) {
|
||||||
|
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
||||||
|
BindGroupIndex groupIndex(groupIndexIn);
|
||||||
|
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
|
DAWN_TRY(
|
||||||
|
ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount, dynamicOffsets));
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount, dynamicOffsets);
|
||||||
|
mCommandBufferState.SetBindGroup(groupIndex, group);
|
||||||
|
mUsageTracker.AddBindGroup(group);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace dawn_native
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
#define DAWNNATIVE_RENDERENCODERBASE_H_
|
#define DAWNNATIVE_RENDERENCODERBASE_H_
|
||||||
|
|
||||||
#include "dawn_native/AttachmentState.h"
|
#include "dawn_native/AttachmentState.h"
|
||||||
|
#include "dawn_native/CommandBufferStateTracker.h"
|
||||||
#include "dawn_native/Error.h"
|
#include "dawn_native/Error.h"
|
||||||
|
#include "dawn_native/PassResourceUsageTracker.h"
|
||||||
#include "dawn_native/ProgrammablePassEncoder.h"
|
#include "dawn_native/ProgrammablePassEncoder.h"
|
||||||
|
|
||||||
namespace dawn_native {
|
namespace dawn_native {
|
||||||
@ -52,6 +54,11 @@ namespace dawn_native {
|
|||||||
uint64_t offset,
|
uint64_t offset,
|
||||||
uint64_t size);
|
uint64_t size);
|
||||||
|
|
||||||
|
void APISetBindGroup(uint32_t groupIndex,
|
||||||
|
BindGroupBase* group,
|
||||||
|
uint32_t dynamicOffsetCount = 0,
|
||||||
|
const uint32_t* dynamicOffsets = nullptr);
|
||||||
|
|
||||||
const AttachmentState* GetAttachmentState() const;
|
const AttachmentState* GetAttachmentState() const;
|
||||||
Ref<AttachmentState> AcquireAttachmentState();
|
Ref<AttachmentState> AcquireAttachmentState();
|
||||||
|
|
||||||
@ -59,6 +66,9 @@ namespace dawn_native {
|
|||||||
// Construct an "error" render encoder base.
|
// Construct an "error" render encoder base.
|
||||||
RenderEncoderBase(DeviceBase* device, EncodingContext* encodingContext, ErrorTag errorTag);
|
RenderEncoderBase(DeviceBase* device, EncodingContext* encodingContext, ErrorTag errorTag);
|
||||||
|
|
||||||
|
CommandBufferStateTracker mCommandBufferState;
|
||||||
|
RenderPassResourceUsageTracker mUsageTracker;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ref<AttachmentState> mAttachmentState;
|
Ref<AttachmentState> mAttachmentState;
|
||||||
const bool mDisableBaseVertex;
|
const bool mDisableBaseVertex;
|
||||||
|
@ -51,7 +51,7 @@ namespace dawn_native {
|
|||||||
RenderPassEncoder::RenderPassEncoder(DeviceBase* device,
|
RenderPassEncoder::RenderPassEncoder(DeviceBase* device,
|
||||||
CommandEncoder* commandEncoder,
|
CommandEncoder* commandEncoder,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext,
|
||||||
PassResourceUsageTracker usageTracker,
|
RenderPassResourceUsageTracker usageTracker,
|
||||||
Ref<AttachmentState> attachmentState,
|
Ref<AttachmentState> attachmentState,
|
||||||
QuerySetBase* occlusionQuerySet,
|
QuerySetBase* occlusionQuerySet,
|
||||||
uint32_t renderTargetWidth,
|
uint32_t renderTargetWidth,
|
||||||
@ -101,8 +101,7 @@ namespace dawn_native {
|
|||||||
allocator->Allocate<EndRenderPassCmd>(Command::EndRenderPass);
|
allocator->Allocate<EndRenderPassCmd>(Command::EndRenderPass);
|
||||||
return {};
|
return {};
|
||||||
})) {
|
})) {
|
||||||
mEncodingContext->ExitPass(this, mUsageTracker.AcquireResourceUsage(),
|
mEncodingContext->ExitPass(this, mUsageTracker.AcquireResourceUsage());
|
||||||
PassType::Render);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +221,7 @@ namespace dawn_native {
|
|||||||
for (uint32_t i = 0; i < count; ++i) {
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
bundles[i] = renderBundles[i];
|
bundles[i] = renderBundles[i];
|
||||||
|
|
||||||
const PassResourceUsage& usages = bundles[i]->GetResourceUsage();
|
const RenderPassResourceUsage& usages = bundles[i]->GetResourceUsage();
|
||||||
for (uint32_t i = 0; i < usages.buffers.size(); ++i) {
|
for (uint32_t i = 0; i < usages.buffers.size(); ++i) {
|
||||||
mUsageTracker.BufferUsedAs(usages.buffers[i], usages.bufferUsages[i]);
|
mUsageTracker.BufferUsedAs(usages.buffers[i], usages.bufferUsages[i]);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace dawn_native {
|
|||||||
RenderPassEncoder(DeviceBase* device,
|
RenderPassEncoder(DeviceBase* device,
|
||||||
CommandEncoder* commandEncoder,
|
CommandEncoder* commandEncoder,
|
||||||
EncodingContext* encodingContext,
|
EncodingContext* encodingContext,
|
||||||
PassResourceUsageTracker usageTracker,
|
RenderPassResourceUsageTracker usageTracker,
|
||||||
Ref<AttachmentState> attachmentState,
|
Ref<AttachmentState> attachmentState,
|
||||||
QuerySetBase* occlusionQuerySet,
|
QuerySetBase* occlusionQuerySet,
|
||||||
uint32_t renderTargetWidth,
|
uint32_t renderTargetWidth,
|
||||||
|
@ -612,7 +612,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
// Records the necessary barriers for the resource usage pre-computed by the frontend
|
// Records the necessary barriers for the resource usage pre-computed by the frontend
|
||||||
auto PrepareResourcesForRenderPass = [](CommandRecordingContext* commandContext,
|
auto PrepareResourcesForRenderPass = [](CommandRecordingContext* commandContext,
|
||||||
const PassResourceUsage& usages) -> bool {
|
const RenderPassResourceUsage& usages) -> bool {
|
||||||
std::vector<D3D12_RESOURCE_BARRIER> barriers;
|
std::vector<D3D12_RESOURCE_BARRIER> barriers;
|
||||||
|
|
||||||
ID3D12GraphicsCommandList* commandList = commandContext->GetCommandList();
|
ID3D12GraphicsCommandList* commandList = commandContext->GetCommandList();
|
||||||
@ -666,7 +666,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
// TODO(jiawei.shao@intel.com): move the resource lazy clearing inside the barrier tracking
|
// TODO(jiawei.shao@intel.com): move the resource lazy clearing inside the barrier tracking
|
||||||
// for compute passes.
|
// for compute passes.
|
||||||
auto PrepareResourcesForComputePass = [](CommandRecordingContext* commandContext,
|
auto PrepareResourcesForComputePass = [](CommandRecordingContext* commandContext,
|
||||||
const PassResourceUsage& usages) {
|
const ComputePassResourceUsage& usages) {
|
||||||
for (size_t i = 0; i < usages.buffers.size(); ++i) {
|
for (size_t i = 0; i < usages.buffers.size(); ++i) {
|
||||||
Buffer* buffer = ToBackend(usages.buffers[i]);
|
Buffer* buffer = ToBackend(usages.buffers[i]);
|
||||||
|
|
||||||
|
@ -531,7 +531,7 @@ namespace dawn_native { namespace vulkan {
|
|||||||
// And resets the used query sets which are rewritten on the render pass.
|
// And resets the used query sets which are rewritten on the render pass.
|
||||||
auto PrepareResourcesForRenderPass = [](Device* device,
|
auto PrepareResourcesForRenderPass = [](Device* device,
|
||||||
CommandRecordingContext* recordingContext,
|
CommandRecordingContext* recordingContext,
|
||||||
const PassResourceUsage& usages) {
|
const RenderPassResourceUsage& usages) {
|
||||||
std::vector<VkBufferMemoryBarrier> bufferBarriers;
|
std::vector<VkBufferMemoryBarrier> bufferBarriers;
|
||||||
std::vector<VkImageMemoryBarrier> imageBarriers;
|
std::vector<VkImageMemoryBarrier> imageBarriers;
|
||||||
VkPipelineStageFlags srcStages = 0;
|
VkPipelineStageFlags srcStages = 0;
|
||||||
@ -583,7 +583,7 @@ namespace dawn_native { namespace vulkan {
|
|||||||
// for compute passes.
|
// for compute passes.
|
||||||
auto PrepareResourcesForComputePass = [](Device* device,
|
auto PrepareResourcesForComputePass = [](Device* device,
|
||||||
CommandRecordingContext* recordingContext,
|
CommandRecordingContext* recordingContext,
|
||||||
const PassResourceUsage& usages) {
|
const ComputePassResourceUsage& usages) {
|
||||||
for (size_t i = 0; i < usages.buffers.size(); ++i) {
|
for (size_t i = 0; i < usages.buffers.size(); ++i) {
|
||||||
Buffer* buffer = ToBackend(usages.buffers[i]);
|
Buffer* buffer = ToBackend(usages.buffers[i]);
|
||||||
buffer->EnsureDataInitialized(recordingContext);
|
buffer->EnsureDataInitialized(recordingContext);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user