mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-10-23 02:05:55 +00:00
This patch simply added dynamic buffer offset in dawn idl and modify the shape of SetBindGroup. BUG=dawn:55 Change-Id: I516e08f3ee558ba375a87d98eaea6d60e93d4514 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5600 Commit-Queue: Shaobo Yan <shaobo.yan@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
144 lines
5.3 KiB
C++
144 lines
5.3 KiB
C++
// 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/ProgrammablePassEncoder.h"
|
|
|
|
#include "dawn_native/BindGroup.h"
|
|
#include "dawn_native/CommandBuffer.h"
|
|
#include "dawn_native/Commands.h"
|
|
#include "dawn_native/Device.h"
|
|
|
|
#include <string.h>
|
|
|
|
namespace dawn_native {
|
|
|
|
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
|
|
CommandEncoderBase* topLevelEncoder,
|
|
CommandAllocator* allocator)
|
|
: ObjectBase(device), mTopLevelEncoder(topLevelEncoder), mAllocator(allocator) {
|
|
DAWN_ASSERT(allocator != nullptr);
|
|
}
|
|
|
|
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
|
|
CommandEncoderBase* topLevelEncoder,
|
|
ErrorTag errorTag)
|
|
: ObjectBase(device, errorTag), mTopLevelEncoder(topLevelEncoder), mAllocator(nullptr) {
|
|
}
|
|
|
|
void ProgrammablePassEncoder::EndPass() {
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
|
return;
|
|
}
|
|
|
|
mTopLevelEncoder->PassEnded();
|
|
mAllocator = nullptr;
|
|
}
|
|
|
|
void ProgrammablePassEncoder::InsertDebugMarker(const char* groupLabel) {
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
|
return;
|
|
}
|
|
|
|
InsertDebugMarkerCmd* cmd =
|
|
mAllocator->Allocate<InsertDebugMarkerCmd>(Command::InsertDebugMarker);
|
|
new (cmd) InsertDebugMarkerCmd;
|
|
cmd->length = strlen(groupLabel);
|
|
|
|
char* label = mAllocator->AllocateData<char>(cmd->length + 1);
|
|
memcpy(label, groupLabel, cmd->length + 1);
|
|
}
|
|
|
|
void ProgrammablePassEncoder::PopDebugGroup() {
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
|
return;
|
|
}
|
|
|
|
PopDebugGroupCmd* cmd = mAllocator->Allocate<PopDebugGroupCmd>(Command::PopDebugGroup);
|
|
new (cmd) PopDebugGroupCmd;
|
|
}
|
|
|
|
void ProgrammablePassEncoder::PushDebugGroup(const char* groupLabel) {
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
|
return;
|
|
}
|
|
|
|
PushDebugGroupCmd* cmd = mAllocator->Allocate<PushDebugGroupCmd>(Command::PushDebugGroup);
|
|
new (cmd) PushDebugGroupCmd;
|
|
cmd->length = strlen(groupLabel);
|
|
|
|
char* label = mAllocator->AllocateData<char>(cmd->length + 1);
|
|
memcpy(label, groupLabel, cmd->length + 1);
|
|
}
|
|
|
|
void ProgrammablePassEncoder::SetBindGroup(uint32_t groupIndex,
|
|
BindGroupBase* group,
|
|
uint32_t dynamicOffsetCount,
|
|
const uint32_t* dynamicOffsets) {
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands()) ||
|
|
mTopLevelEncoder->ConsumedError(GetDevice()->ValidateObject(group))) {
|
|
return;
|
|
}
|
|
|
|
if (groupIndex >= kMaxBindGroups) {
|
|
mTopLevelEncoder->HandleError("Setting bind group over the max");
|
|
return;
|
|
}
|
|
|
|
// TODO(shaobo.yan@intel.com): Implement dynamic buffer offset.
|
|
if (dynamicOffsetCount != 0) {
|
|
mTopLevelEncoder->HandleError("Dynamic Buffer Offset not supported yet");
|
|
return;
|
|
}
|
|
|
|
SetBindGroupCmd* cmd = mAllocator->Allocate<SetBindGroupCmd>(Command::SetBindGroup);
|
|
new (cmd) SetBindGroupCmd;
|
|
cmd->index = groupIndex;
|
|
cmd->group = group;
|
|
}
|
|
|
|
void ProgrammablePassEncoder::SetPushConstants(dawn::ShaderStageBit stages,
|
|
uint32_t offset,
|
|
uint32_t count,
|
|
const void* data) {
|
|
if (mTopLevelEncoder->ConsumedError(ValidateCanRecordCommands())) {
|
|
return;
|
|
}
|
|
|
|
// TODO(cwallez@chromium.org): check for overflows
|
|
if (offset + count > kMaxPushConstants) {
|
|
mTopLevelEncoder->HandleError("Setting too many push constants");
|
|
return;
|
|
}
|
|
|
|
SetPushConstantsCmd* cmd =
|
|
mAllocator->Allocate<SetPushConstantsCmd>(Command::SetPushConstants);
|
|
new (cmd) SetPushConstantsCmd;
|
|
cmd->stages = stages;
|
|
cmd->offset = offset;
|
|
cmd->count = count;
|
|
|
|
uint32_t* values = mAllocator->AllocateData<uint32_t>(count);
|
|
memcpy(values, data, count * sizeof(uint32_t));
|
|
}
|
|
|
|
MaybeError ProgrammablePassEncoder::ValidateCanRecordCommands() const {
|
|
if (mAllocator == nullptr) {
|
|
return DAWN_VALIDATION_ERROR("Recording in an error or already ended pass encoder");
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace dawn_native
|