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.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/CommandBuffer.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/BindGroup.h"
|
|
|
|
#include "dawn_native/Buffer.h"
|
|
|
|
#include "dawn_native/CommandBufferStateTracker.h"
|
|
|
|
#include "dawn_native/Commands.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
#include "dawn_native/ComputePassEncoder.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/ComputePipeline.h"
|
|
|
|
#include "dawn_native/Device.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
#include "dawn_native/ErrorData.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/InputState.h"
|
|
|
|
#include "dawn_native/PipelineLayout.h"
|
2019-02-18 08:56:03 +00:00
|
|
|
#include "dawn_native/RenderPassDescriptor.h"
|
2018-09-21 00:24:37 +00:00
|
|
|
#include "dawn_native/RenderPassEncoder.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/RenderPipeline.h"
|
|
|
|
#include "dawn_native/Texture.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <map>
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-06-26 15:43:51 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-11-30 17:39:24 +00:00
|
|
|
MaybeError ValidateCopySizeFitsInTexture(const TextureCopy& textureCopy,
|
|
|
|
const Extent3D& copySize) {
|
|
|
|
const TextureBase* texture = textureCopy.texture.Get();
|
|
|
|
if (textureCopy.level >= texture->GetNumMipLevels()) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Copy mip-level out of range");
|
2017-06-26 15:43:51 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 17:39:24 +00:00
|
|
|
if (textureCopy.slice >= texture->GetArrayLayers()) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Copy array-layer out of range");
|
2018-08-30 08:27:38 +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.
|
2018-11-30 17:39:24 +00:00
|
|
|
uint64_t level = textureCopy.level;
|
|
|
|
if (uint64_t(textureCopy.origin.x) + uint64_t(copySize.width) >
|
2018-09-18 12:51:42 +00:00
|
|
|
(static_cast<uint64_t>(texture->GetSize().width) >> level) ||
|
2018-11-30 17:39:24 +00:00
|
|
|
uint64_t(textureCopy.origin.y) + uint64_t(copySize.height) >
|
2018-09-18 12:51:42 +00:00
|
|
|
(static_cast<uint64_t>(texture->GetSize().height) >> level)) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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
|
2018-11-30 17:39:24 +00:00
|
|
|
if (textureCopy.origin.z != 0 || copySize.depth != 1) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-11-30 17:39:24 +00:00
|
|
|
MaybeError ValidateCopySizeFitsInBuffer(const BufferCopy& bufferCopy, uint32_t dataSize) {
|
|
|
|
if (!FitsInBuffer(bufferCopy.buffer.Get(), bufferCopy.offset, dataSize)) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-11-30 17:39:24 +00:00
|
|
|
MaybeError ValidateTexelBufferOffset(TextureBase* texture, const BufferCopy& bufferCopy) {
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t texelSize =
|
|
|
|
static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat()));
|
2018-11-30 17:39:24 +00:00
|
|
|
if (bufferCopy.offset % texelSize != 0) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-12-11 09:48:36 +00:00
|
|
|
MaybeError ValidateImageHeight(uint32_t imageHeight, uint32_t copyHeight) {
|
|
|
|
if (imageHeight < copyHeight) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Image height must not be less than the copy height.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-11-30 17:39:24 +00:00
|
|
|
MaybeError ComputeTextureCopyBufferSize(const Extent3D& copySize,
|
2018-07-16 16:20:09 +00:00
|
|
|
uint32_t rowPitch,
|
2018-12-11 09:48:36 +00:00
|
|
|
uint32_t imageHeight,
|
2018-07-16 16:20:09 +00:00
|
|
|
uint32_t* bufferSize) {
|
2018-12-11 09:48:36 +00:00
|
|
|
DAWN_TRY(ValidateImageHeight(imageHeight, copySize.height));
|
|
|
|
|
2017-06-26 15:43:51 +00:00
|
|
|
// TODO(cwallez@chromium.org): check for overflows
|
2018-12-11 09:48:36 +00:00
|
|
|
uint32_t slicePitch = rowPitch * imageHeight;
|
|
|
|
uint32_t sliceSize = rowPitch * (copySize.height - 1) + copySize.width;
|
|
|
|
*bufferSize = (slicePitch * (copySize.depth - 1)) + sliceSize;
|
2017-07-13 14:23:26 +00:00
|
|
|
|
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-11-30 17:39:24 +00:00
|
|
|
MaybeError ValidateRowPitch(dawn::TextureFormat format,
|
|
|
|
const Extent3D& copySize,
|
|
|
|
uint32_t rowPitch) {
|
2017-07-13 14:23:26 +00:00
|
|
|
if (rowPitch % kTextureRowPitchAlignment != 0) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Row pitch must be a multiple of 256");
|
2017-07-13 14:23:26 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 17:39:24 +00:00
|
|
|
uint32_t texelSize = TextureFormatPixelSize(format);
|
|
|
|
if (rowPitch < copySize.width * texelSize) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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));
|
2018-08-22 13:08:02 +00:00
|
|
|
if (!(buffer->GetUsage() & usage)) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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));
|
2018-08-22 13:08:02 +00:00
|
|
|
if (!(texture->GetUsage() & usage)) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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
|
|
|
|
2018-08-22 13:08:02 +00:00
|
|
|
if (usage & ~buffer->GetUsage()) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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
|
|
|
|
2018-08-22 13:08:02 +00:00
|
|
|
if (usage & ~texture->GetUsage()) {
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-12-07 12:31:53 +00:00
|
|
|
BufferBase* buffer = group->GetBindingAsBufferBinding(i).buffer;
|
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-12-07 12:31:53 +00:00
|
|
|
BufferBase* buffer = group->GetBindingAsBufferBinding(i).buffer;
|
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-09-21 00:24:37 +00:00
|
|
|
enum class CommandBufferBuilder::EncodingState : uint8_t {
|
|
|
|
TopLevel,
|
|
|
|
ComputePass,
|
|
|
|
RenderPass,
|
|
|
|
Finished
|
|
|
|
};
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
// CommandBuffer
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder)
|
2018-11-07 10:02:43 +00:00
|
|
|
: ObjectBase(builder->GetDevice()), mResourceUsages(builder->AcquireResourceUsages()) {
|
|
|
|
}
|
|
|
|
|
2019-02-15 12:54:08 +00:00
|
|
|
CommandBufferBase::CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
|
|
|
: ObjectBase(device, tag) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CommandBufferBase* CommandBufferBase::MakeError(DeviceBase* device) {
|
|
|
|
return new CommandBufferBase(device, ObjectBase::kError);
|
|
|
|
}
|
|
|
|
|
2018-11-07 10:02:43 +00:00
|
|
|
const CommandBufferResourceUsage& CommandBufferBase::GetResourceUsages() const {
|
|
|
|
return mResourceUsages;
|
2017-07-12 00:49:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
// CommandBufferBuilder
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
CommandBufferBuilder::CommandBufferBuilder(DeviceBase* device)
|
|
|
|
: Builder(device), mEncodingState(EncodingState::TopLevel) {
|
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-11-07 10:02:43 +00:00
|
|
|
CommandBufferResourceUsage CommandBufferBuilder::AcquireResourceUsages() {
|
|
|
|
ASSERT(!mWereResourceUsagesAcquired);
|
|
|
|
mWereResourceUsagesAcquired = true;
|
|
|
|
return std::move(mResourceUsages);
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
CommandBufferBase* CommandBufferBuilder::GetResultImpl() {
|
2018-09-21 00:24:37 +00:00
|
|
|
mEncodingState = EncodingState::Finished;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
MoveToIterator();
|
2018-10-15 12:54:30 +00:00
|
|
|
return GetDevice()->CreateCommandBuffer(this);
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandBufferBuilder::MoveToIterator() {
|
|
|
|
if (!mWasMovedToIterator) {
|
|
|
|
mIterator = std::move(mAllocator);
|
|
|
|
mWasMovedToIterator = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
void CommandBufferBuilder::PassEnded() {
|
|
|
|
if (mEncodingState == EncodingState::ComputePass) {
|
|
|
|
mAllocator.Allocate<EndComputePassCmd>(Command::EndComputePass);
|
|
|
|
} else {
|
|
|
|
ASSERT(mEncodingState == EncodingState::RenderPass);
|
|
|
|
mAllocator.Allocate<EndRenderPassCmd>(Command::EndRenderPass);
|
|
|
|
}
|
|
|
|
mEncodingState = EncodingState::TopLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandBufferBuilder::ConsumeError(ErrorData* error) {
|
|
|
|
HandleError(error->GetMessage().c_str());
|
|
|
|
delete error;
|
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
// Implementation of the command buffer validation that can be precomputed before submit
|
|
|
|
|
2018-07-16 16:20:09 +00:00
|
|
|
MaybeError CommandBufferBuilder::ValidateGetResult() {
|
2018-12-15 10:34:42 +00:00
|
|
|
if (mEncodingState != EncodingState::TopLevel) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Command buffer recording ended mid-pass");
|
|
|
|
}
|
|
|
|
|
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>();
|
2019-02-18 08:56:03 +00:00
|
|
|
DAWN_TRY(ValidateRenderPass(cmd));
|
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
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(copy->source.buffer.Get()));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(copy->destination.buffer.Get()));
|
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));
|
2018-11-07 10:02:43 +00:00
|
|
|
|
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->source.buffer.Get());
|
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->destination.buffer.Get());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyBufferToTexture: {
|
|
|
|
CopyBufferToTextureCmd* copy = mIterator.NextCommand<CopyBufferToTextureCmd>();
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(copy->source.buffer.Get()));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(copy->destination.texture.Get()));
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t bufferCopySize = 0;
|
2018-11-30 17:39:24 +00:00
|
|
|
DAWN_TRY(ValidateRowPitch(copy->destination.texture->GetFormat(),
|
|
|
|
copy->copySize, copy->source.rowPitch));
|
2018-12-11 09:48:36 +00:00
|
|
|
|
2018-11-30 17:39:24 +00:00
|
|
|
DAWN_TRY(ComputeTextureCopyBufferSize(copy->copySize, copy->source.rowPitch,
|
2018-12-11 09:48:36 +00:00
|
|
|
copy->source.imageHeight,
|
2018-07-18 09:45:17 +00:00
|
|
|
&bufferCopySize));
|
2018-07-16 16:20:09 +00:00
|
|
|
|
2018-11-30 17:39:24 +00:00
|
|
|
DAWN_TRY(ValidateCopySizeFitsInTexture(copy->destination, copy->copySize));
|
2018-07-18 09:45:17 +00:00
|
|
|
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));
|
2018-11-07 10:02:43 +00:00
|
|
|
|
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->source.buffer.Get());
|
|
|
|
mResourceUsages.topLevelTextures.insert(copy->destination.texture.Get());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyTextureToBuffer: {
|
|
|
|
CopyTextureToBufferCmd* copy = mIterator.NextCommand<CopyTextureToBufferCmd>();
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(copy->source.texture.Get()));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(copy->destination.buffer.Get()));
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
uint32_t bufferCopySize = 0;
|
2018-11-30 17:39:24 +00:00
|
|
|
DAWN_TRY(ValidateRowPitch(copy->source.texture->GetFormat(), copy->copySize,
|
|
|
|
copy->destination.rowPitch));
|
|
|
|
DAWN_TRY(ComputeTextureCopyBufferSize(
|
2018-12-11 09:48:36 +00:00
|
|
|
copy->copySize, copy->destination.rowPitch, copy->destination.imageHeight,
|
|
|
|
&bufferCopySize));
|
2018-07-16 16:20:09 +00:00
|
|
|
|
2018-11-30 17:39:24 +00:00
|
|
|
DAWN_TRY(ValidateCopySizeFitsInTexture(copy->source, copy->copySize));
|
2018-07-18 09:45:17 +00:00
|
|
|
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));
|
2018-11-07 10:02:43 +00:00
|
|
|
|
|
|
|
mResourceUsages.topLevelTextures.insert(copy->source.texture.Get());
|
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->destination.buffer.Get());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
default:
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-11-07 10:02:43 +00:00
|
|
|
mResourceUsages.perPass.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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Command disallowed inside a compute pass");
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-15 10:34:42 +00:00
|
|
|
UNREACHABLE();
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Unfinished compute pass");
|
2018-07-04 13:20:19 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 08:56:03 +00:00
|
|
|
MaybeError CommandBufferBuilder::ValidateRenderPass(BeginRenderPassCmd* 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
|
2019-02-18 08:56:03 +00:00
|
|
|
for (uint32_t i : IterateBitSet(renderPass->colorAttachmentsSet)) {
|
|
|
|
RenderPassColorAttachmentInfo* colorAttachment = &renderPass->colorAttachments[i];
|
|
|
|
TextureBase* texture = colorAttachment->view->GetTexture();
|
2018-07-18 09:38:11 +00:00
|
|
|
usageTracker.TextureUsedAs(texture, dawn::TextureUsageBit::OutputAttachment);
|
2018-07-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 08:56:03 +00:00
|
|
|
if (renderPass->hasDepthStencilAttachment) {
|
|
|
|
TextureBase* texture = renderPass->depthStencilAttachment.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-11-07 10:02:43 +00:00
|
|
|
mResourceUsages.perPass.push_back(usageTracker.AcquireResourceUsage());
|
2018-07-16 16:20:09 +00:00
|
|
|
return {};
|
2018-07-04 13:20:19 +00:00
|
|
|
} break;
|
|
|
|
|
2018-12-10 05:20:19 +00:00
|
|
|
case Command::Draw: {
|
|
|
|
mIterator.NextCommand<DrawCmd>();
|
|
|
|
DAWN_TRY(persistentState.ValidateCanDraw());
|
2017-11-24 18:59:42 +00:00
|
|
|
} break;
|
|
|
|
|
2018-12-10 05:20:19 +00:00
|
|
|
case Command::DrawIndexed: {
|
|
|
|
mIterator.NextCommand<DrawIndexedCmd>();
|
|
|
|
DAWN_TRY(persistentState.ValidateCanDrawIndexed());
|
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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_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-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Command disallowed inside a render pass");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-15 10:34:42 +00:00
|
|
|
UNREACHABLE();
|
2018-09-10 14:17:24 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Unfinished render pass");
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:19:36 +00:00
|
|
|
MaybeError CommandBufferBuilder::ValidateCanRecordTopLevelCommands() const {
|
|
|
|
if (mEncodingState != EncodingState::TopLevel) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Command cannot be recorded inside a pass");
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-07-04 13:20:19 +00:00
|
|
|
// Implementation of the API's command recording methods
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
ComputePassEncoderBase* CommandBufferBuilder::BeginComputePass() {
|
2018-11-21 11:19:36 +00:00
|
|
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-23 18:32:51 +00:00
|
|
|
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
2018-09-21 00:24:37 +00:00
|
|
|
|
|
|
|
mEncodingState = EncodingState::ComputePass;
|
2018-10-15 12:54:30 +00:00
|
|
|
return new ComputePassEncoderBase(GetDevice(), this, &mAllocator);
|
2017-05-16 21:04:22 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 00:24:37 +00:00
|
|
|
RenderPassEncoderBase* CommandBufferBuilder::BeginRenderPass(RenderPassDescriptorBase* info) {
|
2018-11-21 11:19:36 +00:00
|
|
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-12-10 10:03:08 +00:00
|
|
|
if (info == nullptr) {
|
|
|
|
HandleError("RenderPassDescriptor cannot be null");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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;
|
2019-02-18 08:56:03 +00:00
|
|
|
|
|
|
|
for (uint32_t i : IterateBitSet(info->GetColorAttachmentMask())) {
|
|
|
|
const RenderPassColorAttachmentInfo& colorAttachment = info->GetColorAttachment(i);
|
|
|
|
if (colorAttachment.view.Get() != nullptr) {
|
|
|
|
cmd->colorAttachmentsSet.set(i);
|
|
|
|
cmd->colorAttachments[i] = colorAttachment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd->hasDepthStencilAttachment = info->HasDepthStencilAttachment();
|
|
|
|
if (cmd->hasDepthStencilAttachment) {
|
|
|
|
const RenderPassDepthStencilAttachmentInfo& depthStencilAttachment =
|
|
|
|
info->GetDepthStencilAttachment();
|
|
|
|
cmd->depthStencilAttachment = depthStencilAttachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd->width = info->GetWidth();
|
|
|
|
cmd->height = info->GetHeight();
|
2018-09-21 00:24:37 +00:00
|
|
|
|
|
|
|
mEncodingState = EncodingState::RenderPass;
|
2018-10-15 12:54:30 +00:00
|
|
|
return new RenderPassEncoderBase(GetDevice(), this, &mAllocator);
|
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) {
|
2018-11-21 11:19:36 +00:00
|
|
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-10 10:03:08 +00:00
|
|
|
if (source == nullptr) {
|
|
|
|
HandleError("Source cannot be null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (destination == nullptr) {
|
|
|
|
HandleError("Destination cannot be null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-28 17:54:13 +00:00
|
|
|
void CommandBufferBuilder::CopyBufferToTexture(const BufferCopyView* source,
|
|
|
|
const TextureCopyView* destination,
|
|
|
|
const Extent3D* copySize) {
|
2018-11-21 11:19:36 +00:00
|
|
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-10 10:03:08 +00:00
|
|
|
|
|
|
|
if (source->buffer == nullptr) {
|
|
|
|
HandleError("Buffer cannot be null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (destination->texture == nullptr) {
|
|
|
|
HandleError("Texture cannot be null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
CopyBufferToTextureCmd* copy =
|
|
|
|
mAllocator.Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
|
|
|
|
new (copy) CopyBufferToTextureCmd;
|
2018-11-28 17:54:13 +00:00
|
|
|
copy->source.buffer = source->buffer;
|
|
|
|
copy->source.offset = source->offset;
|
|
|
|
copy->destination.texture = destination->texture;
|
2018-11-30 17:39:24 +00:00
|
|
|
copy->destination.origin = destination->origin;
|
|
|
|
copy->copySize = *copySize;
|
2018-11-28 17:54:13 +00:00
|
|
|
copy->destination.level = destination->level;
|
|
|
|
copy->destination.slice = destination->slice;
|
|
|
|
if (source->rowPitch == 0) {
|
2018-11-30 17:39:24 +00:00
|
|
|
copy->source.rowPitch = ComputeDefaultRowPitch(destination->texture, copySize->width);
|
2018-11-28 17:54:13 +00:00
|
|
|
} else {
|
2018-11-30 17:39:24 +00:00
|
|
|
copy->source.rowPitch = source->rowPitch;
|
2018-11-28 17:54:13 +00:00
|
|
|
}
|
2018-12-11 09:48:36 +00:00
|
|
|
if (source->imageHeight == 0) {
|
|
|
|
copy->source.imageHeight = copySize->height;
|
|
|
|
} else {
|
|
|
|
copy->source.imageHeight = source->imageHeight;
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 17:54:13 +00:00
|
|
|
void CommandBufferBuilder::CopyTextureToBuffer(const TextureCopyView* source,
|
|
|
|
const BufferCopyView* destination,
|
|
|
|
const Extent3D* copySize) {
|
2018-11-21 11:19:36 +00:00
|
|
|
if (ConsumedError(ValidateCanRecordTopLevelCommands())) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-10 10:03:08 +00:00
|
|
|
|
|
|
|
if (source->texture == nullptr) {
|
|
|
|
HandleError("Texture cannot be null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (destination->buffer == nullptr) {
|
|
|
|
HandleError("Buffer cannot be null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
CopyTextureToBufferCmd* copy =
|
|
|
|
mAllocator.Allocate<CopyTextureToBufferCmd>(Command::CopyTextureToBuffer);
|
|
|
|
new (copy) CopyTextureToBufferCmd;
|
2018-11-28 17:54:13 +00:00
|
|
|
copy->source.texture = source->texture;
|
2018-11-30 17:39:24 +00:00
|
|
|
copy->source.origin = source->origin;
|
|
|
|
copy->copySize = *copySize;
|
2018-11-28 17:54:13 +00:00
|
|
|
copy->source.level = source->level;
|
|
|
|
copy->source.slice = source->slice;
|
|
|
|
copy->destination.buffer = destination->buffer;
|
|
|
|
copy->destination.offset = destination->offset;
|
|
|
|
if (destination->rowPitch == 0) {
|
2018-11-30 17:39:24 +00:00
|
|
|
copy->destination.rowPitch = ComputeDefaultRowPitch(source->texture, copySize->width);
|
2018-11-28 17:54:13 +00:00
|
|
|
} else {
|
2018-11-30 17:39:24 +00:00
|
|
|
copy->destination.rowPitch = destination->rowPitch;
|
2018-11-28 17:54:13 +00:00
|
|
|
}
|
2018-12-11 09:48:36 +00:00
|
|
|
if (destination->imageHeight == 0) {
|
|
|
|
copy->destination.imageHeight = copySize->height;
|
|
|
|
} else {
|
|
|
|
copy->destination.imageHeight = destination->imageHeight;
|
|
|
|
}
|
2017-06-26 20:23:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|