2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/CommandBuffer.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/BindGroup.h"
|
|
|
|
#include "backend/Buffer.h"
|
|
|
|
#include "backend/CommandBufferStateTracker.h"
|
2017-11-24 18:59:42 +00:00
|
|
|
#include "backend/Commands.h"
|
2017-07-14 14:58:07 +00:00
|
|
|
#include "backend/ComputePipeline.h"
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/Device.h"
|
|
|
|
#include "backend/InputState.h"
|
|
|
|
#include "backend/PipelineLayout.h"
|
2017-07-14 14:58:07 +00:00
|
|
|
#include "backend/RenderPipeline.h"
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/Texture.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace backend {
|
|
|
|
|
2017-06-26 15:43:51 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError ValidateCopyLocationFitsInTexture(const TextureCopyLocation& location) {
|
2017-06-26 15:43:51 +00:00
|
|
|
const TextureBase* texture = location.texture.Get();
|
|
|
|
if (location.level >= texture->GetNumMipLevels()) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Copy mip-level out of range");
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
// All texture dimensions are in uint32_t so by doing checks in uint64_t we avoid
|
|
|
|
// overflows.
|
2017-06-26 15:43:51 +00:00
|
|
|
uint64_t level = location.level;
|
2017-11-24 18:59:42 +00:00
|
|
|
if (uint64_t(location.x) + uint64_t(location.width) >
|
|
|
|
(static_cast<uint64_t>(texture->GetWidth()) >> level) ||
|
|
|
|
uint64_t(location.y) + uint64_t(location.height) >
|
|
|
|
(static_cast<uint64_t>(texture->GetHeight()) >> level)) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Copy would touch outside of the texture");
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
// TODO(cwallez@chromium.org): Check the depth bound differently for 2D arrays and 3D
|
|
|
|
// textures
|
2017-06-26 15:43:51 +00:00
|
|
|
if (location.z != 0 || location.depth != 1) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("No support for z != 0 and depth != 1 for now");
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FitsInBuffer(const BufferBase* buffer, uint32_t offset, uint32_t size) {
|
|
|
|
uint32_t bufferSize = buffer->GetSize();
|
|
|
|
return offset <= bufferSize && (size <= (bufferSize - offset));
|
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError ValidateCopySizeFitsInBuffer(const BufferCopyLocation& location,
|
|
|
|
uint32_t dataSize) {
|
2017-06-26 15:43:51 +00:00
|
|
|
if (!FitsInBuffer(location.buffer.Get(), location.offset, dataSize)) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Copy would overflow the buffer");
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError ValidateTexelBufferOffset(TextureBase* texture,
|
|
|
|
const BufferCopyLocation& location) {
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t texelSize =
|
|
|
|
static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat()));
|
2017-07-18 17:18:58 +00:00
|
|
|
if (location.offset % texelSize != 0) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Buffer offset must be a multiple of the texel size");
|
2017-07-18 17:18:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2017-07-18 17:18:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError ComputeTextureCopyBufferSize(const TextureCopyLocation& location,
|
|
|
|
uint32_t rowPitch,
|
|
|
|
uint32_t* bufferSize) {
|
2017-06-26 15:43:51 +00:00
|
|
|
// TODO(cwallez@chromium.org): check for overflows
|
2017-07-13 14:23:26 +00:00
|
|
|
*bufferSize = (rowPitch * (location.height - 1) + location.width) * location.depth;
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2017-07-13 14:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ComputeDefaultRowPitch(TextureBase* texture, uint32_t width) {
|
2017-07-22 00:00:22 +00:00
|
|
|
uint32_t texelSize = TextureFormatPixelSize(texture->GetFormat());
|
2017-07-13 14:23:26 +00:00
|
|
|
return texelSize * width;
|
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError ValidateRowPitch(const TextureCopyLocation& location, uint32_t rowPitch) {
|
2017-07-13 14:23:26 +00:00
|
|
|
if (rowPitch % kTextureRowPitchAlignment != 0) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Row pitch must be a multiple of 256");
|
2017-07-13 14:23:26 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 00:00:22 +00:00
|
|
|
uint32_t texelSize = TextureFormatPixelSize(location.texture.Get()->GetFormat());
|
2017-07-13 14:23:26 +00:00
|
|
|
if (rowPitch < location.width * texelSize) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Row pitch must not be less than the number of bytes per row");
|
2017-07-13 14:23:26 +00:00
|
|
|
}
|
2017-06-26 15:43:51 +00:00
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsageBit usage) {
|
2018-07-09 13:15:07 +00:00
|
|
|
ASSERT(HasZeroOrOneBits(usage));
|
|
|
|
if (!(buffer->GetAllowedUsage() & usage)) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("buffer doesn't have the required usage.");
|
2018-07-09 13:15:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2018-07-09 13:15:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
MaybeError ValidateCanUseAs(TextureBase* texture, dawn::TextureUsageBit usage) {
|
2018-07-09 13:15:07 +00:00
|
|
|
ASSERT(HasZeroOrOneBits(usage));
|
|
|
|
if (!(texture->GetAllowedUsage() & usage)) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("texture doesn't have the required usage.");
|
2018-07-09 13:15:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2018-07-09 13:15:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 16:03:22 +00:00
|
|
|
enum class PassType {
|
|
|
|
Render,
|
|
|
|
Compute,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper class to encapsulate the logic of tracking per-resource usage during the
|
|
|
|
// validation of command buffer passes. It is used both to know if there are validation
|
|
|
|
// errors, and to get a list of resources used per pass for backends that need the
|
|
|
|
// information.
|
|
|
|
class PassResourceUsageTracker {
|
|
|
|
public:
|
2018-07-18 09:38:11 +00:00
|
|
|
void BufferUsedAs(BufferBase* buffer, dawn::BufferUsageBit usage) {
|
2018-07-10 16:03:22 +00:00
|
|
|
// std::map's operator[] will create the key and return 0 if the key didn't exist
|
|
|
|
// before.
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::BufferUsageBit& storedUsage = mBufferUsages[buffer];
|
2018-07-10 16:03:22 +00:00
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
if (usage == dawn::BufferUsageBit::Storage &&
|
|
|
|
storedUsage & dawn::BufferUsageBit::Storage) {
|
2018-07-10 16:03:22 +00:00
|
|
|
mStorageUsedMultipleTimes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
storedUsage |= usage;
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
void TextureUsedAs(TextureBase* texture, dawn::TextureUsageBit usage) {
|
2018-07-10 16:03:22 +00:00
|
|
|
// std::map's operator[] will create the key and return 0 if the key didn't exist
|
|
|
|
// before.
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::TextureUsageBit& storedUsage = mTextureUsages[texture];
|
2018-07-10 16:03:22 +00:00
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
if (usage == dawn::TextureUsageBit::Storage &&
|
|
|
|
storedUsage & dawn::TextureUsageBit::Storage) {
|
2018-07-10 16:03:22 +00:00
|
|
|
mStorageUsedMultipleTimes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
storedUsage |= usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Performs the per-pass usage validation checks
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError ValidateUsages(PassType pass) const {
|
2018-07-10 16:03:22 +00:00
|
|
|
// Storage resources cannot be used twice in the same compute pass
|
|
|
|
if (pass == PassType::Compute && mStorageUsedMultipleTimes) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Storage resource used multiple times in compute pass");
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Buffers can only be used as single-write or multiple read.
|
|
|
|
for (auto& it : mBufferUsages) {
|
|
|
|
BufferBase* buffer = it.first;
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::BufferUsageBit usage = it.second;
|
2018-07-10 16:03:22 +00:00
|
|
|
|
|
|
|
if (usage & ~buffer->GetAllowedUsage()) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Buffer missing usage for the pass");
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool readOnly = (usage & kReadOnlyBufferUsages) == usage;
|
2018-07-18 09:38:11 +00:00
|
|
|
bool singleUse = dawn::HasZeroOrOneBits(usage);
|
2018-07-10 16:03:22 +00:00
|
|
|
|
|
|
|
if (!readOnly && !singleUse) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR(
|
2018-07-16 16:20:09 +00:00
|
|
|
"Buffer used as writeable usage and another usage in pass");
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Textures can only be used as single-write or multiple read.
|
|
|
|
// TODO(cwallez@chromium.org): implement per-subresource tracking
|
|
|
|
for (auto& it : mTextureUsages) {
|
|
|
|
TextureBase* texture = it.first;
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::TextureUsageBit usage = it.second;
|
2018-07-10 16:03:22 +00:00
|
|
|
|
|
|
|
if (usage & ~texture->GetAllowedUsage()) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Texture missing usage for the pass");
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// For textures the only read-only usage in a pass is Sampled, so checking the
|
|
|
|
// usage constraint simplifies to checking a single usage bit is set.
|
2018-07-18 09:38:11 +00:00
|
|
|
if (!dawn::HasZeroOrOneBits(it.second)) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Texture used with more than one usage in pass");
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the per-pass usage for use by backends for APIs with explicit barriers.
|
|
|
|
PassResourceUsage AcquireResourceUsage() {
|
|
|
|
PassResourceUsage result;
|
|
|
|
result.buffers.reserve(mBufferUsages.size());
|
|
|
|
result.bufferUsages.reserve(mBufferUsages.size());
|
|
|
|
result.textures.reserve(mTextureUsages.size());
|
|
|
|
result.textureUsages.reserve(mTextureUsages.size());
|
|
|
|
|
|
|
|
for (auto& it : mBufferUsages) {
|
|
|
|
result.buffers.push_back(it.first);
|
|
|
|
result.bufferUsages.push_back(it.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& it : mTextureUsages) {
|
|
|
|
result.textures.push_back(it.first);
|
|
|
|
result.textureUsages.push_back(it.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-07-18 09:38:11 +00:00
|
|
|
std::map<BufferBase*, dawn::BufferUsageBit> mBufferUsages;
|
|
|
|
std::map<TextureBase*, dawn::TextureUsageBit> mTextureUsages;
|
2018-07-10 16:03:22 +00:00
|
|
|
bool mStorageUsedMultipleTimes = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TrackBindGroupResourceUsage(BindGroupBase* group, PassResourceUsageTracker* tracker) {
|
|
|
|
const auto& layoutInfo = group->GetLayout()->GetBindingInfo();
|
|
|
|
|
|
|
|
for (uint32_t i : IterateBitSet(layoutInfo.mask)) {
|
2018-07-18 09:38:11 +00:00
|
|
|
dawn::BindingType type = layoutInfo.types[i];
|
2018-07-10 16:03:22 +00:00
|
|
|
|
|
|
|
switch (type) {
|
2018-07-18 09:38:11 +00:00
|
|
|
case dawn::BindingType::UniformBuffer: {
|
2018-07-10 16:03:22 +00:00
|
|
|
BufferBase* buffer = group->GetBindingAsBufferView(i)->GetBuffer();
|
2018-07-18 09:38:11 +00:00
|
|
|
tracker->BufferUsedAs(buffer, dawn::BufferUsageBit::Uniform);
|
2018-07-10 16:03:22 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
case dawn::BindingType::StorageBuffer: {
|
2018-07-10 16:03:22 +00:00
|
|
|
BufferBase* buffer = group->GetBindingAsBufferView(i)->GetBuffer();
|
2018-07-18 09:38:11 +00:00
|
|
|
tracker->BufferUsedAs(buffer, dawn::BufferUsageBit::Storage);
|
2018-07-10 16:03:22 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
case dawn::BindingType::SampledTexture: {
|
2018-07-10 16:03:22 +00:00
|
|
|
TextureBase* texture = group->GetBindingAsTextureView(i)->GetTexture();
|
2018-07-18 09:38:11 +00:00
|
|
|
tracker->TextureUsedAs(texture, dawn::TextureUsageBit::Sampled);
|
2018-07-10 16:03:22 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
case dawn::BindingType::Sampler:
|
2018-07-10 16:03:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
} // namespace
|
2017-06-26 15:43:51 +00:00
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
// CommandBuffer
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder)
|
2018-07-09 13:15:07 +00:00
|
|
|
: mDevice(builder->mDevice) {
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 00:49:20 +00:00
|
|
|
DeviceBase* CommandBufferBase::GetDevice() {
|
2017-11-23 18:32:51 +00:00
|
|
|
return mDevice;
|
2017-07-12 00:49:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
// CommandBufferBuilder
|
|
|
|
|
2018-07-18 16:23:08 +00:00
|
|
|
CommandBufferBuilder::CommandBufferBuilder(DeviceBase* device) : Builder(device) {
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandBufferBuilder::~CommandBufferBuilder() {
|
2017-11-23 18:32:51 +00:00
|
|
|
if (!mWereCommandsAcquired) {
|
2017-04-20 18:38:20 +00:00
|
|
|
MoveToIterator();
|
2017-11-23 18:32:51 +00:00
|
|
|
FreeCommands(&mIterator);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
CommandIterator CommandBufferBuilder::AcquireCommands() {
|
|
|
|
ASSERT(!mWereCommandsAcquired);
|
|
|
|
mWereCommandsAcquired = true;
|
|
|
|
return std::move(mIterator);
|
|
|
|
}
|
|
|
|
|
2018-07-10 16:03:22 +00:00
|
|
|
std::vector<PassResourceUsage> CommandBufferBuilder::AcquirePassResourceUsage() {
|
|
|
|
ASSERT(!mWerePassUsagesAcquired);
|
|
|
|
mWerePassUsagesAcquired = true;
|
|
|
|
return std::move(mPassResourceUsages);
|
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
CommandBufferBase* CommandBufferBuilder::GetResultImpl() {
|
|
|
|
MoveToIterator();
|
|
|
|
return mDevice->CreateCommandBuffer(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandBufferBuilder::MoveToIterator() {
|
|
|
|
if (!mWasMovedToIterator) {
|
|
|
|
mIterator = std::move(mAllocator);
|
|
|
|
mWasMovedToIterator = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation of the command buffer validation that can be precomputed before submit
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError CommandBufferBuilder::ValidateGetResult() {
|
2017-04-20 18:38:20 +00:00
|
|
|
MoveToIterator();
|
2018-07-04 13:20:19 +00:00
|
|
|
mIterator.Reset();
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
Command type;
|
2017-11-23 18:32:51 +00:00
|
|
|
while (mIterator.NextCommandId(&type)) {
|
2017-04-20 18:38:20 +00:00
|
|
|
switch (type) {
|
2017-11-24 18:59:42 +00:00
|
|
|
case Command::BeginComputePass: {
|
|
|
|
mIterator.NextCommand<BeginComputePassCmd>();
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateComputePass());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::BeginRenderPass: {
|
|
|
|
BeginRenderPassCmd* cmd = mIterator.NextCommand<BeginRenderPassCmd>();
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateRenderPass(cmd->info.Get()));
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyBufferToBuffer: {
|
|
|
|
CopyBufferToBufferCmd* copy = mIterator.NextCommand<CopyBufferToBufferCmd>();
|
2018-07-16 16:20:09 +00:00
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->source, copy->size));
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination, copy->size));
|
2018-07-16 16:20:09 +00:00
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->source.buffer.Get(),
|
|
|
|
dawn::BufferUsageBit::TransferSrc));
|
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
|
|
|
|
dawn::BufferUsageBit::TransferDst));
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyBufferToTexture: {
|
|
|
|
CopyBufferToTextureCmd* copy = mIterator.NextCommand<CopyBufferToTextureCmd>();
|
|
|
|
|
|
|
|
uint32_t bufferCopySize = 0;
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateRowPitch(copy->destination, copy->rowPitch));
|
|
|
|
DAWN_TRY(ComputeTextureCopyBufferSize(copy->destination, copy->rowPitch,
|
|
|
|
&bufferCopySize));
|
2018-07-16 16:20:09 +00:00
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateCopyLocationFitsInTexture(copy->destination));
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->source, bufferCopySize));
|
|
|
|
DAWN_TRY(
|
2018-07-16 16:20:09 +00:00
|
|
|
ValidateTexelBufferOffset(copy->destination.texture.Get(), copy->source));
|
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->source.buffer.Get(),
|
|
|
|
dawn::BufferUsageBit::TransferSrc));
|
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->destination.texture.Get(),
|
|
|
|
dawn::TextureUsageBit::TransferDst));
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyTextureToBuffer: {
|
|
|
|
CopyTextureToBufferCmd* copy = mIterator.NextCommand<CopyTextureToBufferCmd>();
|
|
|
|
|
|
|
|
uint32_t bufferCopySize = 0;
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateRowPitch(copy->source, copy->rowPitch));
|
|
|
|
DAWN_TRY(ComputeTextureCopyBufferSize(copy->source, copy->rowPitch,
|
|
|
|
&bufferCopySize));
|
2018-07-16 16:20:09 +00:00
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateCopyLocationFitsInTexture(copy->source));
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination, bufferCopySize));
|
|
|
|
DAWN_TRY(
|
2018-07-16 16:20:09 +00:00
|
|
|
ValidateTexelBufferOffset(copy->source.texture.Get(), copy->destination));
|
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->source.texture.Get(),
|
|
|
|
dawn::TextureUsageBit::TransferSrc));
|
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
|
|
|
|
dawn::BufferUsageBit::TransferDst));
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
default:
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Command disallowed outside of a pass");
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError CommandBufferBuilder::ValidateComputePass() {
|
2018-07-10 16:03:22 +00:00
|
|
|
PassResourceUsageTracker usageTracker;
|
2018-07-18 16:23:08 +00:00
|
|
|
CommandBufferStateTracker persistentState;
|
2018-07-10 16:03:22 +00:00
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
Command type;
|
|
|
|
while (mIterator.NextCommandId(&type)) {
|
|
|
|
switch (type) {
|
|
|
|
case Command::EndComputePass: {
|
|
|
|
mIterator.NextCommand<EndComputePassCmd>();
|
2018-07-10 16:03:22 +00:00
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(usageTracker.ValidateUsages(PassType::Compute));
|
2018-07-10 16:03:22 +00:00
|
|
|
mPassResourceUsages.push_back(usageTracker.AcquireResourceUsage());
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2018-07-04 13:20:19 +00:00
|
|
|
} break;
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
case Command::Dispatch: {
|
|
|
|
mIterator.NextCommand<DispatchCmd>();
|
2018-07-18 16:23:08 +00:00
|
|
|
DAWN_TRY(persistentState.ValidateCanDispatch());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
case Command::SetComputePipeline: {
|
|
|
|
SetComputePipelineCmd* cmd = mIterator.NextCommand<SetComputePipelineCmd>();
|
|
|
|
ComputePipelineBase* pipeline = cmd->pipeline.Get();
|
2018-07-18 16:23:08 +00:00
|
|
|
persistentState.SetComputePipeline(pipeline);
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
case Command::SetPushConstants: {
|
|
|
|
SetPushConstantsCmd* cmd = mIterator.NextCommand<SetPushConstantsCmd>();
|
|
|
|
mIterator.NextData<uint32_t>(cmd->count);
|
|
|
|
// Validation of count and offset has already been done when the command was
|
|
|
|
// recorded because it impacts the size of an allocation in the
|
|
|
|
// CommandAllocator.
|
2018-07-18 09:38:11 +00:00
|
|
|
if (cmd->stages & ~dawn::ShaderStageBit::Compute) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR(
|
2018-07-04 13:20:19 +00:00
|
|
|
"SetPushConstants stage must be compute or 0 in compute passes");
|
2017-11-24 18:59:42 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
case Command::SetBindGroup: {
|
|
|
|
SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>();
|
2018-07-10 16:03:22 +00:00
|
|
|
|
|
|
|
TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker);
|
2018-07-18 16:23:08 +00:00
|
|
|
persistentState.SetBindGroup(cmd->index, cmd->group.Get());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
default:
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Command disallowed inside a compute pass");
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Unfinished compute pass");
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError CommandBufferBuilder::ValidateRenderPass(RenderPassDescriptorBase* renderPass) {
|
2018-07-10 16:03:22 +00:00
|
|
|
PassResourceUsageTracker usageTracker;
|
2018-07-18 16:23:08 +00:00
|
|
|
CommandBufferStateTracker persistentState;
|
2018-07-10 16:03:22 +00:00
|
|
|
|
|
|
|
// Track usage of the render pass attachments
|
|
|
|
for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) {
|
|
|
|
TextureBase* texture = renderPass->GetColorAttachment(i).view->GetTexture();
|
2018-07-18 09:38:11 +00:00
|
|
|
usageTracker.TextureUsedAs(texture, dawn::TextureUsageBit::OutputAttachment);
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (renderPass->HasDepthStencilAttachment()) {
|
|
|
|
TextureBase* texture = renderPass->GetDepthStencilAttachment().view->GetTexture();
|
2018-07-18 09:38:11 +00:00
|
|
|
usageTracker.TextureUsedAs(texture, dawn::TextureUsageBit::OutputAttachment);
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
Command type;
|
|
|
|
while (mIterator.NextCommandId(&type)) {
|
|
|
|
switch (type) {
|
2017-11-24 18:59:42 +00:00
|
|
|
case Command::EndRenderPass: {
|
|
|
|
mIterator.NextCommand<EndRenderPassCmd>();
|
2018-07-10 16:03:22 +00:00
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(usageTracker.ValidateUsages(PassType::Render));
|
2018-07-10 16:03:22 +00:00
|
|
|
mPassResourceUsages.push_back(usageTracker.AcquireResourceUsage());
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2018-07-04 13:20:19 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::DrawArrays: {
|
|
|
|
mIterator.NextCommand<DrawArraysCmd>();
|
2018-07-18 16:23:08 +00:00
|
|
|
DAWN_TRY(persistentState.ValidateCanDrawArrays());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
case Command::DrawElements: {
|
|
|
|
mIterator.NextCommand<DrawElementsCmd>();
|
2018-07-18 16:23:08 +00:00
|
|
|
DAWN_TRY(persistentState.ValidateCanDrawElements());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::SetRenderPipeline: {
|
|
|
|
SetRenderPipelineCmd* cmd = mIterator.NextCommand<SetRenderPipelineCmd>();
|
|
|
|
RenderPipelineBase* pipeline = cmd->pipeline.Get();
|
2018-07-04 13:20:19 +00:00
|
|
|
|
|
|
|
if (!pipeline->IsCompatibleWith(renderPass)) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Pipeline is incompatible with this render pass");
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 16:23:08 +00:00
|
|
|
persistentState.SetRenderPipeline(pipeline);
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::SetPushConstants: {
|
|
|
|
SetPushConstantsCmd* cmd = mIterator.NextCommand<SetPushConstantsCmd>();
|
|
|
|
mIterator.NextData<uint32_t>(cmd->count);
|
|
|
|
// Validation of count and offset has already been done when the command was
|
|
|
|
// recorded because it impacts the size of an allocation in the
|
|
|
|
// CommandAllocator.
|
2018-07-04 13:20:19 +00:00
|
|
|
if (cmd->stages &
|
2018-07-18 09:38:11 +00:00
|
|
|
~(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment)) {
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR(
|
2018-07-04 13:20:19 +00:00
|
|
|
"SetPushConstants stage must be a subset of (vertex|fragment) in "
|
|
|
|
"render passes");
|
2017-11-24 18:59:42 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::SetStencilReference: {
|
|
|
|
mIterator.NextCommand<SetStencilReferenceCmd>();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::SetBlendColor: {
|
|
|
|
mIterator.NextCommand<SetBlendColorCmd>();
|
|
|
|
} break;
|
|
|
|
|
2018-02-13 19:57:13 +00:00
|
|
|
case Command::SetScissorRect: {
|
|
|
|
mIterator.NextCommand<SetScissorRectCmd>();
|
|
|
|
} break;
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
case Command::SetBindGroup: {
|
|
|
|
SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>();
|
2018-07-10 16:03:22 +00:00
|
|
|
|
|
|
|
TrackBindGroupResourceUsage(cmd->group.Get(), &usageTracker);
|
2018-07-18 16:23:08 +00:00
|
|
|
persistentState.SetBindGroup(cmd->index, cmd->group.Get());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::SetIndexBuffer: {
|
|
|
|
SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>();
|
2018-07-10 16:03:22 +00:00
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
usageTracker.BufferUsedAs(cmd->buffer.Get(), dawn::BufferUsageBit::Index);
|
2018-07-18 16:23:08 +00:00
|
|
|
persistentState.SetIndexBuffer();
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
case Command::SetVertexBuffers: {
|
|
|
|
SetVertexBuffersCmd* cmd = mIterator.NextCommand<SetVertexBuffersCmd>();
|
|
|
|
auto buffers = mIterator.NextData<Ref<BufferBase>>(cmd->count);
|
|
|
|
mIterator.NextData<uint32_t>(cmd->count);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
for (uint32_t i = 0; i < cmd->count; ++i) {
|
2018-07-18 09:38:11 +00:00
|
|
|
usageTracker.BufferUsedAs(buffers[i].Get(), dawn::BufferUsageBit::Vertex);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
2018-07-18 16:23:08 +00:00
|
|
|
persistentState.SetVertexBuffer(cmd->startSlot, cmd->count);
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
default:
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Command disallowed inside a render pass");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_RETURN_ERROR("Unfinished render pass");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
// Implementation of the API's command recording methods
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-10 21:07:24 +00:00
|
|
|
void CommandBufferBuilder::BeginComputePass() {
|
2017-11-23 18:32:51 +00:00
|
|
|
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
2017-05-16 21:04:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 17:04:44 +00:00
|
|
|
void CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
|
2017-11-23 18:32:51 +00:00
|
|
|
BeginRenderPassCmd* cmd = mAllocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
|
2017-11-24 18:59:42 +00:00
|
|
|
new (cmd) BeginRenderPassCmd;
|
2018-05-02 22:10:13 +00:00
|
|
|
cmd->info = info;
|
2017-07-10 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void CommandBufferBuilder::CopyBufferToBuffer(BufferBase* source,
|
|
|
|
uint32_t sourceOffset,
|
|
|
|
BufferBase* destination,
|
|
|
|
uint32_t destinationOffset,
|
|
|
|
uint32_t size) {
|
|
|
|
CopyBufferToBufferCmd* copy =
|
|
|
|
mAllocator.Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
|
|
|
|
new (copy) CopyBufferToBufferCmd;
|
2017-06-26 15:43:51 +00:00
|
|
|
copy->source.buffer = source;
|
|
|
|
copy->source.offset = sourceOffset;
|
|
|
|
copy->destination.buffer = destination;
|
|
|
|
copy->destination.offset = destinationOffset;
|
2017-06-12 22:12:29 +00:00
|
|
|
copy->size = size;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void CommandBufferBuilder::CopyBufferToTexture(BufferBase* buffer,
|
|
|
|
uint32_t bufferOffset,
|
|
|
|
uint32_t rowPitch,
|
|
|
|
TextureBase* texture,
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t z,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height,
|
|
|
|
uint32_t depth,
|
|
|
|
uint32_t level) {
|
2017-07-13 14:23:26 +00:00
|
|
|
if (rowPitch == 0) {
|
|
|
|
rowPitch = ComputeDefaultRowPitch(texture, width);
|
|
|
|
}
|
2017-11-24 18:59:42 +00:00
|
|
|
CopyBufferToTextureCmd* copy =
|
|
|
|
mAllocator.Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
|
|
|
|
new (copy) CopyBufferToTextureCmd;
|
2017-06-26 15:43:51 +00:00
|
|
|
copy->source.buffer = buffer;
|
|
|
|
copy->source.offset = bufferOffset;
|
|
|
|
copy->destination.texture = texture;
|
|
|
|
copy->destination.x = x;
|
|
|
|
copy->destination.y = y;
|
|
|
|
copy->destination.z = z;
|
|
|
|
copy->destination.width = width;
|
|
|
|
copy->destination.height = height;
|
|
|
|
copy->destination.depth = depth;
|
|
|
|
copy->destination.level = level;
|
2017-07-13 14:04:23 +00:00
|
|
|
copy->rowPitch = rowPitch;
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void CommandBufferBuilder::CopyTextureToBuffer(TextureBase* texture,
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t z,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height,
|
|
|
|
uint32_t depth,
|
|
|
|
uint32_t level,
|
|
|
|
BufferBase* buffer,
|
|
|
|
uint32_t bufferOffset,
|
|
|
|
uint32_t rowPitch) {
|
2017-07-13 14:23:26 +00:00
|
|
|
if (rowPitch == 0) {
|
|
|
|
rowPitch = ComputeDefaultRowPitch(texture, width);
|
|
|
|
}
|
2017-11-24 18:59:42 +00:00
|
|
|
CopyTextureToBufferCmd* copy =
|
|
|
|
mAllocator.Allocate<CopyTextureToBufferCmd>(Command::CopyTextureToBuffer);
|
|
|
|
new (copy) CopyTextureToBufferCmd;
|
2017-06-26 20:23:03 +00:00
|
|
|
copy->source.texture = texture;
|
|
|
|
copy->source.x = x;
|
|
|
|
copy->source.y = y;
|
|
|
|
copy->source.z = z;
|
|
|
|
copy->source.width = width;
|
|
|
|
copy->source.height = height;
|
|
|
|
copy->source.depth = depth;
|
|
|
|
copy->source.level = level;
|
|
|
|
copy->destination.buffer = buffer;
|
|
|
|
copy->destination.offset = bufferOffset;
|
2017-07-13 14:04:23 +00:00
|
|
|
copy->rowPitch = rowPitch;
|
2017-06-26 20:23:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
void CommandBufferBuilder::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
|
2017-11-23 18:32:51 +00:00
|
|
|
DispatchCmd* dispatch = mAllocator.Allocate<DispatchCmd>(Command::Dispatch);
|
2017-11-24 18:59:42 +00:00
|
|
|
new (dispatch) DispatchCmd;
|
2017-04-20 18:38:20 +00:00
|
|
|
dispatch->x = x;
|
|
|
|
dispatch->y = y;
|
|
|
|
dispatch->z = z;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void CommandBufferBuilder::DrawArrays(uint32_t vertexCount,
|
|
|
|
uint32_t instanceCount,
|
|
|
|
uint32_t firstVertex,
|
|
|
|
uint32_t firstInstance) {
|
2017-11-23 18:32:51 +00:00
|
|
|
DrawArraysCmd* draw = mAllocator.Allocate<DrawArraysCmd>(Command::DrawArrays);
|
2017-11-24 18:59:42 +00:00
|
|
|
new (draw) DrawArraysCmd;
|
2017-04-20 18:38:20 +00:00
|
|
|
draw->vertexCount = vertexCount;
|
|
|
|
draw->instanceCount = instanceCount;
|
|
|
|
draw->firstVertex = firstVertex;
|
|
|
|
draw->firstInstance = firstInstance;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void CommandBufferBuilder::DrawElements(uint32_t indexCount,
|
|
|
|
uint32_t instanceCount,
|
|
|
|
uint32_t firstIndex,
|
|
|
|
uint32_t firstInstance) {
|
2017-11-23 18:32:51 +00:00
|
|
|
DrawElementsCmd* draw = mAllocator.Allocate<DrawElementsCmd>(Command::DrawElements);
|
2017-11-24 18:59:42 +00:00
|
|
|
new (draw) DrawElementsCmd;
|
2017-04-20 18:38:20 +00:00
|
|
|
draw->indexCount = indexCount;
|
|
|
|
draw->instanceCount = instanceCount;
|
|
|
|
draw->firstIndex = firstIndex;
|
|
|
|
draw->firstInstance = firstInstance;
|
|
|
|
}
|
|
|
|
|
2017-07-10 21:07:24 +00:00
|
|
|
void CommandBufferBuilder::EndComputePass() {
|
2017-11-23 18:32:51 +00:00
|
|
|
mAllocator.Allocate<EndComputePassCmd>(Command::EndComputePass);
|
2017-07-10 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 21:04:22 +00:00
|
|
|
void CommandBufferBuilder::EndRenderPass() {
|
2017-11-23 18:32:51 +00:00
|
|
|
mAllocator.Allocate<EndRenderPassCmd>(Command::EndRenderPass);
|
2017-05-16 21:04:22 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 14:58:07 +00:00
|
|
|
void CommandBufferBuilder::SetComputePipeline(ComputePipelineBase* pipeline) {
|
2017-11-24 18:59:42 +00:00
|
|
|
SetComputePipelineCmd* cmd =
|
|
|
|
mAllocator.Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
|
|
|
|
new (cmd) SetComputePipelineCmd;
|
2017-07-14 14:58:07 +00:00
|
|
|
cmd->pipeline = pipeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandBufferBuilder::SetRenderPipeline(RenderPipelineBase* pipeline) {
|
2017-11-24 18:59:42 +00:00
|
|
|
SetRenderPipelineCmd* cmd =
|
|
|
|
mAllocator.Allocate<SetRenderPipelineCmd>(Command::SetRenderPipeline);
|
|
|
|
new (cmd) SetRenderPipelineCmd;
|
2017-04-20 18:38:20 +00:00
|
|
|
cmd->pipeline = pipeline;
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:38:11 +00:00
|
|
|
void CommandBufferBuilder::SetPushConstants(dawn::ShaderStageBit stages,
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t offset,
|
|
|
|
uint32_t count,
|
|
|
|
const void* data) {
|
2017-07-20 15:01:37 +00:00
|
|
|
// TODO(cwallez@chromium.org): check for overflows
|
2017-04-20 18:38:20 +00:00
|
|
|
if (offset + count > kMaxPushConstants) {
|
2017-05-08 08:52:11 +00:00
|
|
|
HandleError("Setting too many push constants");
|
2017-04-20 18:38:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
SetPushConstantsCmd* cmd =
|
|
|
|
mAllocator.Allocate<SetPushConstantsCmd>(Command::SetPushConstants);
|
|
|
|
new (cmd) SetPushConstantsCmd;
|
2017-07-20 15:01:37 +00:00
|
|
|
cmd->stages = stages;
|
2017-04-20 18:38:20 +00:00
|
|
|
cmd->offset = offset;
|
|
|
|
cmd->count = count;
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
uint32_t* values = mAllocator.AllocateData<uint32_t>(count);
|
2017-04-20 18:38:20 +00:00
|
|
|
memcpy(values, data, count * sizeof(uint32_t));
|
|
|
|
}
|
|
|
|
|
2017-06-01 15:30:03 +00:00
|
|
|
void CommandBufferBuilder::SetStencilReference(uint32_t reference) {
|
2017-11-24 18:59:42 +00:00
|
|
|
SetStencilReferenceCmd* cmd =
|
|
|
|
mAllocator.Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
|
|
|
|
new (cmd) SetStencilReferenceCmd;
|
2017-06-01 15:30:03 +00:00
|
|
|
cmd->reference = reference;
|
2017-05-30 22:13:03 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 18:22:52 +00:00
|
|
|
void CommandBufferBuilder::SetBlendColor(float r, float g, float b, float a) {
|
2017-11-23 18:32:51 +00:00
|
|
|
SetBlendColorCmd* cmd = mAllocator.Allocate<SetBlendColorCmd>(Command::SetBlendColor);
|
2017-11-24 18:59:42 +00:00
|
|
|
new (cmd) SetBlendColorCmd;
|
2017-08-01 18:22:52 +00:00
|
|
|
cmd->r = r;
|
|
|
|
cmd->g = g;
|
|
|
|
cmd->b = b;
|
|
|
|
cmd->a = a;
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:57:13 +00:00
|
|
|
void CommandBufferBuilder::SetScissorRect(uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height) {
|
|
|
|
SetScissorRectCmd* cmd = mAllocator.Allocate<SetScissorRectCmd>(Command::SetScissorRect);
|
|
|
|
new (cmd) SetScissorRectCmd;
|
|
|
|
cmd->x = x;
|
|
|
|
cmd->y = y;
|
|
|
|
cmd->width = width;
|
|
|
|
cmd->height = height;
|
|
|
|
}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
void CommandBufferBuilder::SetBindGroup(uint32_t groupIndex, BindGroupBase* group) {
|
|
|
|
if (groupIndex >= kMaxBindGroups) {
|
2017-05-08 08:52:11 +00:00
|
|
|
HandleError("Setting bind group over the max");
|
2017-04-20 18:38:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
SetBindGroupCmd* cmd = mAllocator.Allocate<SetBindGroupCmd>(Command::SetBindGroup);
|
2017-11-24 18:59:42 +00:00
|
|
|
new (cmd) SetBindGroupCmd;
|
2017-04-20 18:38:20 +00:00
|
|
|
cmd->index = groupIndex;
|
|
|
|
cmd->group = group;
|
|
|
|
}
|
|
|
|
|
2017-09-19 17:38:05 +00:00
|
|
|
void CommandBufferBuilder::SetIndexBuffer(BufferBase* buffer, uint32_t offset) {
|
2017-04-20 18:38:20 +00:00
|
|
|
// TODO(kainino@chromium.org): validation
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
SetIndexBufferCmd* cmd = mAllocator.Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
|
2017-11-24 18:59:42 +00:00
|
|
|
new (cmd) SetIndexBufferCmd;
|
2017-04-20 18:38:20 +00:00
|
|
|
cmd->buffer = buffer;
|
|
|
|
cmd->offset = offset;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
void CommandBufferBuilder::SetVertexBuffers(uint32_t startSlot,
|
|
|
|
uint32_t count,
|
|
|
|
BufferBase* const* buffers,
|
|
|
|
uint32_t const* offsets) {
|
2017-04-20 18:38:20 +00:00
|
|
|
// TODO(kainino@chromium.org): validation
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
SetVertexBuffersCmd* cmd =
|
|
|
|
mAllocator.Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
|
|
|
|
new (cmd) SetVertexBuffersCmd;
|
2017-04-20 18:38:20 +00:00
|
|
|
cmd->startSlot = startSlot;
|
|
|
|
cmd->count = count;
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
Ref<BufferBase>* cmdBuffers = mAllocator.AllocateData<Ref<BufferBase>>(count);
|
2017-04-20 18:38:20 +00:00
|
|
|
for (size_t i = 0; i < count; ++i) {
|
2017-11-24 18:59:42 +00:00
|
|
|
new (&cmdBuffers[i]) Ref<BufferBase>(buffers[i]);
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
uint32_t* cmdOffsets = mAllocator.AllocateData<uint32_t>(count);
|
2017-04-20 18:38:20 +00:00
|
|
|
memcpy(cmdOffsets, offsets, count * sizeof(uint32_t));
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
} // namespace backend
|