mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-19 09:55:26 +00:00
Factor EncodingContext out of CommandEncoderBase.
This patch factors the CommandAllocator, CommandIterator, and error handling out of CommandEncoderBase so it can later be used by the RenderBundleEncoder. Bug: dawn:154 Change-Id: Ia4f8c3ce7f432f0887b619bd8090aa9bec7330fc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9181 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
8944f0205b
commit
fde94905fe
@@ -23,70 +23,76 @@
|
||||
namespace dawn_native {
|
||||
|
||||
ComputePassEncoderBase::ComputePassEncoderBase(DeviceBase* device,
|
||||
CommandEncoderBase* topLevelEncoder,
|
||||
CommandAllocator* allocator)
|
||||
: ProgrammablePassEncoder(device, topLevelEncoder, allocator) {
|
||||
CommandEncoderBase* commandEncoder,
|
||||
EncodingContext* encodingContext)
|
||||
: ProgrammablePassEncoder(device, encodingContext), mCommandEncoder(commandEncoder) {
|
||||
}
|
||||
|
||||
ComputePassEncoderBase::ComputePassEncoderBase(DeviceBase* device,
|
||||
CommandEncoderBase* topLevelEncoder,
|
||||
CommandEncoderBase* commandEncoder,
|
||||
EncodingContext* encodingContext,
|
||||
ErrorTag errorTag)
|
||||
: ProgrammablePassEncoder(device, topLevelEncoder, errorTag) {
|
||||
: ProgrammablePassEncoder(device, encodingContext, errorTag),
|
||||
mCommandEncoder(commandEncoder) {
|
||||
}
|
||||
|
||||
ComputePassEncoderBase* ComputePassEncoderBase::MakeError(DeviceBase* device,
|
||||
CommandEncoderBase* topLevelEncoder) {
|
||||
return new ComputePassEncoderBase(device, topLevelEncoder, ObjectBase::kError);
|
||||
CommandEncoderBase* commandEncoder,
|
||||
EncodingContext* encodingContext) {
|
||||
return new ComputePassEncoderBase(device, commandEncoder, encodingContext,
|
||||
ObjectBase::kError);
|
||||
}
|
||||
|
||||
void ComputePassEncoderBase::EndPass() {
|
||||
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
if (mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
||||
allocator->Allocate<EndComputePassCmd>(Command::EndComputePass);
|
||||
|
||||
mTopLevelEncoder->PassEnded();
|
||||
mAllocator = nullptr;
|
||||
return {};
|
||||
})) {
|
||||
mEncodingContext->ExitPass(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ComputePassEncoderBase::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
|
||||
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
||||
return;
|
||||
}
|
||||
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
||||
DispatchCmd* dispatch = allocator->Allocate<DispatchCmd>(Command::Dispatch);
|
||||
dispatch->x = x;
|
||||
dispatch->y = y;
|
||||
dispatch->z = z;
|
||||
|
||||
DispatchCmd* dispatch = mAllocator->Allocate<DispatchCmd>(Command::Dispatch);
|
||||
dispatch->x = x;
|
||||
dispatch->y = y;
|
||||
dispatch->z = z;
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
void ComputePassEncoderBase::DispatchIndirect(BufferBase* indirectBuffer,
|
||||
uint64_t indirectOffset) {
|
||||
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands()) ||
|
||||
mTopLevelEncoder->ConsumedError(GetDevice()->ValidateObject(indirectBuffer))) {
|
||||
return;
|
||||
}
|
||||
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
||||
DAWN_TRY(GetDevice()->ValidateObject(indirectBuffer));
|
||||
|
||||
if (indirectOffset >= indirectBuffer->GetSize() ||
|
||||
indirectOffset + kDispatchIndirectSize > indirectBuffer->GetSize()) {
|
||||
mTopLevelEncoder->HandleError("Indirect offset out of bounds");
|
||||
return;
|
||||
}
|
||||
if (indirectOffset >= indirectBuffer->GetSize() ||
|
||||
indirectOffset + kDispatchIndirectSize > indirectBuffer->GetSize()) {
|
||||
return DAWN_VALIDATION_ERROR("Indirect offset out of bounds");
|
||||
}
|
||||
|
||||
DispatchIndirectCmd* dispatch =
|
||||
mAllocator->Allocate<DispatchIndirectCmd>(Command::DispatchIndirect);
|
||||
dispatch->indirectBuffer = indirectBuffer;
|
||||
dispatch->indirectOffset = indirectOffset;
|
||||
DispatchIndirectCmd* dispatch =
|
||||
allocator->Allocate<DispatchIndirectCmd>(Command::DispatchIndirect);
|
||||
dispatch->indirectBuffer = indirectBuffer;
|
||||
dispatch->indirectOffset = indirectOffset;
|
||||
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
void ComputePassEncoderBase::SetPipeline(ComputePipelineBase* pipeline) {
|
||||
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands()) ||
|
||||
mTopLevelEncoder->ConsumedError(GetDevice()->ValidateObject(pipeline))) {
|
||||
return;
|
||||
}
|
||||
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
||||
DAWN_TRY(GetDevice()->ValidateObject(pipeline));
|
||||
|
||||
SetComputePipelineCmd* cmd =
|
||||
mAllocator->Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
|
||||
cmd->pipeline = pipeline;
|
||||
SetComputePipelineCmd* cmd =
|
||||
allocator->Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
|
||||
cmd->pipeline = pipeline;
|
||||
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace dawn_native
|
||||
|
||||
Reference in New Issue
Block a user