2018-09-21 00:24:37 +00:00
|
|
|
// Copyright 2018 The Dawn Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "dawn_native/ComputePassEncoder.h"
|
|
|
|
|
2019-06-10 20:56:27 +00:00
|
|
|
#include "dawn_native/Buffer.h"
|
2019-02-20 11:46:16 +00:00
|
|
|
#include "dawn_native/CommandEncoder.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
#include "dawn_native/Commands.h"
|
|
|
|
#include "dawn_native/ComputePipeline.h"
|
2019-02-13 13:09:18 +00:00
|
|
|
#include "dawn_native/Device.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
|
|
|
|
namespace dawn_native {
|
|
|
|
|
|
|
|
ComputePassEncoderBase::ComputePassEncoderBase(DeviceBase* device,
|
2019-02-20 11:46:16 +00:00
|
|
|
CommandEncoderBase* topLevelEncoder,
|
2018-09-21 00:24:37 +00:00
|
|
|
CommandAllocator* allocator)
|
2019-02-20 11:46:16 +00:00
|
|
|
: ProgrammablePassEncoder(device, topLevelEncoder, allocator) {
|
2018-09-21 00:24:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 01:02:47 +00:00
|
|
|
ComputePassEncoderBase::ComputePassEncoderBase(DeviceBase* device,
|
|
|
|
CommandEncoderBase* topLevelEncoder,
|
|
|
|
ErrorTag errorTag)
|
|
|
|
: ProgrammablePassEncoder(device, topLevelEncoder, errorTag) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ComputePassEncoderBase* ComputePassEncoderBase::MakeError(DeviceBase* device,
|
|
|
|
CommandEncoderBase* topLevelEncoder) {
|
|
|
|
return new ComputePassEncoderBase(device, topLevelEncoder, ObjectBase::kError);
|
|
|
|
}
|
|
|
|
|
2019-07-20 01:34:56 +00:00
|
|
|
void ComputePassEncoderBase::EndPass() {
|
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTopLevelEncoder->PassEnded();
|
|
|
|
mAllocator = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
void ComputePassEncoderBase::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
|
2019-02-20 11:46:16 +00:00
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
2018-09-21 00:24:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchCmd* dispatch = mAllocator->Allocate<DispatchCmd>(Command::Dispatch);
|
|
|
|
dispatch->x = x;
|
|
|
|
dispatch->y = y;
|
|
|
|
dispatch->z = z;
|
|
|
|
}
|
|
|
|
|
2019-06-10 20:56:27 +00:00
|
|
|
void ComputePassEncoderBase::DispatchIndirect(BufferBase* indirectBuffer,
|
|
|
|
uint64_t indirectOffset) {
|
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands()) ||
|
|
|
|
mTopLevelEncoder->ConsumedError(GetDevice()->ValidateObject(indirectBuffer))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indirectOffset >= indirectBuffer->GetSize() ||
|
|
|
|
indirectOffset + kDispatchIndirectSize > indirectBuffer->GetSize()) {
|
|
|
|
mTopLevelEncoder->HandleError("Indirect offset out of bounds");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchIndirectCmd* dispatch =
|
|
|
|
mAllocator->Allocate<DispatchIndirectCmd>(Command::DispatchIndirect);
|
|
|
|
dispatch->indirectBuffer = indirectBuffer;
|
|
|
|
dispatch->indirectOffset = indirectOffset;
|
|
|
|
}
|
|
|
|
|
2018-12-21 10:40:26 +00:00
|
|
|
void ComputePassEncoderBase::SetPipeline(ComputePipelineBase* pipeline) {
|
2019-02-20 11:46:16 +00:00
|
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands()) ||
|
|
|
|
mTopLevelEncoder->ConsumedError(GetDevice()->ValidateObject(pipeline))) {
|
2018-12-10 10:03:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
SetComputePipelineCmd* cmd =
|
|
|
|
mAllocator->Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
|
|
|
|
cmd->pipeline = pipeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dawn_native
|