2019-02-15 12:54:08 +00:00
|
|
|
// Copyright 2019 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/CommandEncoder.h"
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
#include "common/BitSetIterator.h"
|
|
|
|
#include "dawn_native/BindGroup.h"
|
|
|
|
#include "dawn_native/Buffer.h"
|
2019-02-15 12:54:08 +00:00
|
|
|
#include "dawn_native/CommandBuffer.h"
|
2019-02-20 11:46:16 +00:00
|
|
|
#include "dawn_native/CommandBufferStateTracker.h"
|
2019-08-13 00:22:28 +00:00
|
|
|
#include "dawn_native/CommandValidation.h"
|
2019-02-20 11:46:16 +00:00
|
|
|
#include "dawn_native/Commands.h"
|
|
|
|
#include "dawn_native/ComputePassEncoder.h"
|
2019-02-15 12:54:08 +00:00
|
|
|
#include "dawn_native/Device.h"
|
2019-02-20 11:46:16 +00:00
|
|
|
#include "dawn_native/ErrorData.h"
|
2019-08-08 17:21:39 +00:00
|
|
|
#include "dawn_native/PassResourceUsageTracker.h"
|
2019-02-20 11:46:16 +00:00
|
|
|
#include "dawn_native/RenderPassEncoder.h"
|
|
|
|
#include "dawn_native/RenderPipeline.h"
|
2019-08-13 19:00:34 +00:00
|
|
|
#include "dawn_platform/tracing/TraceEvent.h"
|
2019-02-20 11:46:16 +00:00
|
|
|
|
|
|
|
#include <map>
|
2019-02-15 12:54:08 +00:00
|
|
|
|
|
|
|
namespace dawn_native {
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
MaybeError ValidateCopySizeFitsInTexture(const TextureCopy& textureCopy,
|
|
|
|
const Extent3D& copySize) {
|
|
|
|
const TextureBase* texture = textureCopy.texture.Get();
|
2019-07-08 09:41:51 +00:00
|
|
|
if (textureCopy.mipLevel >= texture->GetNumMipLevels()) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Copy mipLevel out of range");
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 09:41:51 +00:00
|
|
|
if (textureCopy.arrayLayer >= texture->GetArrayLayers()) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Copy arrayLayer out of range");
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 09:41:51 +00:00
|
|
|
Extent3D extent = texture->GetMipLevelPhysicalSize(textureCopy.mipLevel);
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
// All texture dimensions are in uint32_t so by doing checks in uint64_t we avoid
|
|
|
|
// overflows.
|
|
|
|
if (uint64_t(textureCopy.origin.x) + uint64_t(copySize.width) >
|
2019-06-25 03:09:26 +00:00
|
|
|
static_cast<uint64_t>(extent.width) ||
|
2019-02-20 11:46:16 +00:00
|
|
|
uint64_t(textureCopy.origin.y) + uint64_t(copySize.height) >
|
2019-06-25 03:09:26 +00:00
|
|
|
static_cast<uint64_t>(extent.height)) {
|
2019-02-20 11:46:16 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Copy would touch outside of the texture");
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(cwallez@chromium.org): Check the depth bound differently for 2D arrays and 3D
|
|
|
|
// textures
|
2019-03-26 17:14:55 +00:00
|
|
|
if (textureCopy.origin.z != 0 || copySize.depth > 1) {
|
|
|
|
return DAWN_VALIDATION_ERROR("No support for z != 0 and depth > 1 for now");
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-07 03:06:47 +00:00
|
|
|
MaybeError ValidateCopySizeFitsInBuffer(const Ref<BufferBase>& buffer,
|
|
|
|
uint64_t offset,
|
|
|
|
uint64_t size) {
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t bufferSize = buffer->GetSize();
|
2019-06-07 03:06:47 +00:00
|
|
|
bool fitsInBuffer = offset <= bufferSize && (size <= (bufferSize - offset));
|
|
|
|
if (!fitsInBuffer) {
|
2019-02-20 11:46:16 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Copy would overflow the buffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-07 03:06:47 +00:00
|
|
|
MaybeError ValidateCopySizeFitsInBuffer(const BufferCopy& bufferCopy, uint64_t dataSize) {
|
|
|
|
return ValidateCopySizeFitsInBuffer(bufferCopy.buffer, bufferCopy.offset, dataSize);
|
|
|
|
}
|
|
|
|
|
2019-04-05 20:51:29 +00:00
|
|
|
MaybeError ValidateB2BCopySizeAlignment(uint64_t dataSize,
|
|
|
|
uint64_t srcOffset,
|
|
|
|
uint64_t dstOffset) {
|
2019-02-27 02:46:27 +00:00
|
|
|
// Copy size must be a multiple of 4 bytes on macOS.
|
|
|
|
if (dataSize % 4 != 0) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Copy size must be a multiple of 4 bytes");
|
|
|
|
}
|
|
|
|
|
|
|
|
// SourceOffset and destinationOffset must be multiples of 4 bytes on macOS.
|
|
|
|
if (srcOffset % 4 != 0 || dstOffset % 4 != 0) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Source offset and destination offset must be multiples of 4 bytes");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
MaybeError ValidateTexelBufferOffset(const BufferCopy& bufferCopy, const Format& format) {
|
|
|
|
if (bufferCopy.offset % format.blockByteSize != 0) {
|
2019-06-18 01:06:09 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Buffer offset must be a multiple of the texel or block size");
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-02 00:06:55 +00:00
|
|
|
MaybeError ValidateImageHeight(const Format& format,
|
|
|
|
uint32_t imageHeight,
|
|
|
|
uint32_t copyHeight) {
|
2019-02-20 11:46:16 +00:00
|
|
|
if (imageHeight < copyHeight) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Image height must not be less than the copy height.");
|
|
|
|
}
|
|
|
|
|
2019-07-02 00:06:55 +00:00
|
|
|
if (imageHeight % format.blockHeight != 0) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Image height must be a multiple of compressed texture format block width");
|
|
|
|
}
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-03-04 12:01:59 +00:00
|
|
|
MaybeError ValidateTextureSampleCountInCopyCommands(const TextureBase* texture) {
|
|
|
|
if (texture->GetSampleCount() > 1) {
|
|
|
|
return DAWN_VALIDATION_ERROR("The sample count of textures must be 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-03-26 11:06:23 +00:00
|
|
|
MaybeError ValidateEntireSubresourceCopied(const TextureCopy& src,
|
|
|
|
const TextureCopy& dst,
|
|
|
|
const Extent3D& copySize) {
|
|
|
|
Extent3D srcSize = src.texture.Get()->GetSize();
|
|
|
|
|
|
|
|
if (dst.origin.x != 0 || dst.origin.y != 0 || dst.origin.z != 0 ||
|
|
|
|
srcSize.width != copySize.width || srcSize.height != copySize.height ||
|
|
|
|
srcSize.depth != copySize.depth) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The entire subresource must be copied when using a depth/stencil texture or "
|
|
|
|
"when samples are greater than 1.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeError ValidateTextureToTextureCopyRestrictions(const TextureCopy& src,
|
|
|
|
const TextureCopy& dst,
|
|
|
|
const Extent3D& copySize) {
|
|
|
|
const uint32_t srcSamples = src.texture.Get()->GetSampleCount();
|
|
|
|
const uint32_t dstSamples = dst.texture.Get()->GetSampleCount();
|
|
|
|
|
|
|
|
if (srcSamples != dstSamples) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Source and destination textures must have matching sample counts.");
|
|
|
|
} else if (srcSamples > 1) {
|
|
|
|
// D3D12 requires entire subresource to be copied when using CopyTextureRegion when
|
|
|
|
// samples > 1.
|
|
|
|
DAWN_TRY(ValidateEntireSubresourceCopied(src, dst, copySize));
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
if (src.texture.Get()->GetFormat().format != dst.texture.Get()->GetFormat().format) {
|
2019-03-26 11:06:23 +00:00
|
|
|
// Metal requires texture-to-texture copies be the same format
|
|
|
|
return DAWN_VALIDATION_ERROR("Source and destination texture formats must match.");
|
2019-06-21 10:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (src.texture.Get()->GetFormat().HasDepthOrStencil()) {
|
2019-03-26 11:06:23 +00:00
|
|
|
// D3D12 requires entire subresource to be copied when using CopyTextureRegion is
|
|
|
|
// used with depth/stencil.
|
|
|
|
DAWN_TRY(ValidateEntireSubresourceCopied(src, dst, copySize));
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
MaybeError ComputeTextureCopyBufferSize(const Format& textureFormat,
|
2019-06-12 08:53:45 +00:00
|
|
|
const Extent3D& copySize,
|
2019-02-20 11:46:16 +00:00
|
|
|
uint32_t rowPitch,
|
|
|
|
uint32_t imageHeight,
|
|
|
|
uint32_t* bufferSize) {
|
2019-07-02 00:06:55 +00:00
|
|
|
ASSERT(imageHeight >= copySize.height);
|
2019-06-21 10:16:15 +00:00
|
|
|
uint32_t blockByteSize = textureFormat.blockByteSize;
|
|
|
|
uint32_t blockWidth = textureFormat.blockWidth;
|
|
|
|
uint32_t blockHeight = textureFormat.blockHeight;
|
2019-06-18 01:06:09 +00:00
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
// TODO(cwallez@chromium.org): check for overflows
|
2019-06-21 10:16:15 +00:00
|
|
|
uint32_t slicePitch = rowPitch * imageHeight / blockWidth;
|
|
|
|
uint32_t sliceSize = rowPitch * (copySize.height / blockHeight - 1) +
|
|
|
|
(copySize.width / blockWidth) * blockByteSize;
|
2019-02-20 11:46:16 +00:00
|
|
|
*bufferSize = (slicePitch * (copySize.depth - 1)) + sliceSize;
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
uint32_t ComputeDefaultRowPitch(const Format& format, uint32_t width) {
|
|
|
|
return width / format.blockWidth * format.blockByteSize;
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
MaybeError ValidateRowPitch(const Format& format,
|
2019-02-20 11:46:16 +00:00
|
|
|
const Extent3D& copySize,
|
|
|
|
uint32_t rowPitch) {
|
|
|
|
if (rowPitch % kTextureRowPitchAlignment != 0) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Row pitch must be a multiple of 256");
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
if (rowPitch < copySize.width / format.blockWidth * format.blockByteSize) {
|
2019-02-20 11:46:16 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Row pitch must not be less than the number of bytes per row");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
MaybeError ValidateImageOrigin(const Format& format, const Origin3D& offset) {
|
|
|
|
if (offset.x % format.blockWidth != 0) {
|
2019-06-18 01:06:09 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Offset.x must be a multiple of compressed texture format block width");
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
if (offset.y % format.blockHeight != 0) {
|
2019-06-18 01:06:09 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Offset.y must be a multiple of compressed texture format block height");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
MaybeError ValidateImageCopySize(const Format& format, const Extent3D& extent) {
|
|
|
|
if (extent.width % format.blockWidth != 0) {
|
2019-06-18 01:06:09 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Extent.width must be a multiple of compressed texture format block width");
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
if (extent.height % format.blockHeight != 0) {
|
2019-06-18 01:06:09 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Extent.height must be a multiple of compressed texture format block height");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-08-27 08:21:39 +00:00
|
|
|
MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsage usage) {
|
2019-02-20 11:46:16 +00:00
|
|
|
ASSERT(HasZeroOrOneBits(usage));
|
|
|
|
if (!(buffer->GetUsage() & usage)) {
|
|
|
|
return DAWN_VALIDATION_ERROR("buffer doesn't have the required usage.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-08-27 08:21:39 +00:00
|
|
|
MaybeError ValidateCanUseAs(TextureBase* texture, dawn::TextureUsage usage) {
|
2019-02-20 11:46:16 +00:00
|
|
|
ASSERT(HasZeroOrOneBits(usage));
|
|
|
|
if (!(texture->GetUsage() & usage)) {
|
|
|
|
return DAWN_VALIDATION_ERROR("texture doesn't have the required usage.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-02-27 09:21:56 +00:00
|
|
|
MaybeError ValidateAttachmentArrayLayersAndLevelCount(const TextureViewBase* attachment) {
|
|
|
|
// Currently we do not support layered rendering.
|
|
|
|
if (attachment->GetLayerCount() > 1) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The layer count of the texture view used as attachment cannot be greater than "
|
|
|
|
"1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attachment->GetLevelCount() > 1) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The mipmap level count of the texture view used as attachment cannot be "
|
|
|
|
"greater than 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeError ValidateOrSetAttachmentSize(const TextureViewBase* attachment,
|
|
|
|
uint32_t* width,
|
|
|
|
uint32_t* height) {
|
|
|
|
const Extent3D& textureSize = attachment->GetTexture()->GetSize();
|
|
|
|
const uint32_t attachmentWidth = textureSize.width >> attachment->GetBaseMipLevel();
|
|
|
|
const uint32_t attachmentHeight = textureSize.height >> attachment->GetBaseMipLevel();
|
|
|
|
|
|
|
|
if (*width == 0) {
|
|
|
|
DAWN_ASSERT(*height == 0);
|
|
|
|
*width = attachmentWidth;
|
|
|
|
*height = attachmentHeight;
|
|
|
|
DAWN_ASSERT(*width != 0 && *height != 0);
|
|
|
|
} else if (*width != attachmentWidth || *height != attachmentHeight) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Attachment size mismatch");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-03-11 18:41:02 +00:00
|
|
|
MaybeError ValidateOrSetColorAttachmentSampleCount(const TextureViewBase* colorAttachment,
|
|
|
|
uint32_t* sampleCount) {
|
|
|
|
if (*sampleCount == 0) {
|
|
|
|
*sampleCount = colorAttachment->GetTexture()->GetSampleCount();
|
|
|
|
DAWN_ASSERT(*sampleCount != 0);
|
|
|
|
} else if (*sampleCount != colorAttachment->GetTexture()->GetSampleCount()) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Color attachment sample counts mismatch");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeError ValidateResolveTarget(
|
|
|
|
const DeviceBase* device,
|
|
|
|
const RenderPassColorAttachmentDescriptor* colorAttachment) {
|
|
|
|
if (colorAttachment->resolveTarget == nullptr) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
DAWN_TRY(device->ValidateObject(colorAttachment->resolveTarget));
|
|
|
|
|
|
|
|
if (!colorAttachment->attachment->GetTexture()->IsMultisampledTexture()) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Cannot set resolve target when the sample count of the color attachment is 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (colorAttachment->resolveTarget->GetTexture()->IsMultisampledTexture()) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Cannot use multisampled texture as resolve target");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (colorAttachment->resolveTarget->GetLayerCount() > 1) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The array layer count of the resolve target must be 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (colorAttachment->resolveTarget->GetLevelCount() > 1) {
|
|
|
|
return DAWN_VALIDATION_ERROR("The mip level count of the resolve target must be 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t colorAttachmentBaseMipLevel = colorAttachment->attachment->GetBaseMipLevel();
|
|
|
|
const Extent3D& colorTextureSize = colorAttachment->attachment->GetTexture()->GetSize();
|
|
|
|
uint32_t colorAttachmentWidth = colorTextureSize.width >> colorAttachmentBaseMipLevel;
|
|
|
|
uint32_t colorAttachmentHeight = colorTextureSize.height >> colorAttachmentBaseMipLevel;
|
|
|
|
|
|
|
|
uint32_t resolveTargetBaseMipLevel = colorAttachment->resolveTarget->GetBaseMipLevel();
|
|
|
|
const Extent3D& resolveTextureSize =
|
|
|
|
colorAttachment->resolveTarget->GetTexture()->GetSize();
|
|
|
|
uint32_t resolveTargetWidth = resolveTextureSize.width >> resolveTargetBaseMipLevel;
|
|
|
|
uint32_t resolveTargetHeight = resolveTextureSize.height >> resolveTargetBaseMipLevel;
|
|
|
|
if (colorAttachmentWidth != resolveTargetWidth ||
|
|
|
|
colorAttachmentHeight != resolveTargetHeight) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The size of the resolve target must be the same as the color attachment");
|
|
|
|
}
|
|
|
|
|
2019-06-21 10:16:15 +00:00
|
|
|
dawn::TextureFormat resolveTargetFormat =
|
|
|
|
colorAttachment->resolveTarget->GetFormat().format;
|
|
|
|
if (resolveTargetFormat != colorAttachment->attachment->GetFormat().format) {
|
2019-03-11 18:41:02 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The format of the resolve target must be the same as the color attachment");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-02-27 09:21:56 +00:00
|
|
|
MaybeError ValidateRenderPassColorAttachment(
|
|
|
|
const DeviceBase* device,
|
|
|
|
const RenderPassColorAttachmentDescriptor* colorAttachment,
|
|
|
|
uint32_t* width,
|
2019-03-11 18:41:02 +00:00
|
|
|
uint32_t* height,
|
|
|
|
uint32_t* sampleCount) {
|
2019-02-27 09:21:56 +00:00
|
|
|
DAWN_ASSERT(colorAttachment != nullptr);
|
|
|
|
|
|
|
|
DAWN_TRY(device->ValidateObject(colorAttachment->attachment));
|
|
|
|
|
|
|
|
const TextureViewBase* attachment = colorAttachment->attachment;
|
2019-06-21 10:16:15 +00:00
|
|
|
if (!attachment->GetFormat().IsColor() || !attachment->GetFormat().isRenderable) {
|
2019-02-27 09:21:56 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The format of the texture view used as color attachment is not color "
|
|
|
|
"renderable");
|
|
|
|
}
|
|
|
|
|
2019-03-11 18:41:02 +00:00
|
|
|
DAWN_TRY(ValidateOrSetColorAttachmentSampleCount(attachment, sampleCount));
|
|
|
|
|
|
|
|
DAWN_TRY(ValidateResolveTarget(device, colorAttachment));
|
|
|
|
|
2019-02-27 09:21:56 +00:00
|
|
|
DAWN_TRY(ValidateAttachmentArrayLayersAndLevelCount(attachment));
|
|
|
|
DAWN_TRY(ValidateOrSetAttachmentSize(attachment, width, height));
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeError ValidateRenderPassDepthStencilAttachment(
|
|
|
|
const DeviceBase* device,
|
|
|
|
const RenderPassDepthStencilAttachmentDescriptor* depthStencilAttachment,
|
|
|
|
uint32_t* width,
|
2019-03-15 05:16:41 +00:00
|
|
|
uint32_t* height,
|
|
|
|
uint32_t* sampleCount) {
|
2019-02-27 09:21:56 +00:00
|
|
|
DAWN_ASSERT(depthStencilAttachment != nullptr);
|
|
|
|
|
|
|
|
DAWN_TRY(device->ValidateObject(depthStencilAttachment->attachment));
|
|
|
|
|
|
|
|
const TextureViewBase* attachment = depthStencilAttachment->attachment;
|
2019-06-21 10:16:15 +00:00
|
|
|
if (!attachment->GetFormat().HasDepthOrStencil() ||
|
|
|
|
!attachment->GetFormat().isRenderable) {
|
2019-02-27 09:21:56 +00:00
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"The format of the texture view used as depth stencil attachment is not a "
|
|
|
|
"depth stencil format");
|
|
|
|
}
|
|
|
|
|
2019-03-15 05:16:41 +00:00
|
|
|
// *sampleCount == 0 must only happen when there is no color attachment. In that case we
|
|
|
|
// do not need to validate the sample count of the depth stencil attachment.
|
2019-03-19 01:12:01 +00:00
|
|
|
const uint32_t depthStencilSampleCount = attachment->GetTexture()->GetSampleCount();
|
|
|
|
if (*sampleCount != 0) {
|
|
|
|
if (depthStencilSampleCount != *sampleCount) {
|
|
|
|
return DAWN_VALIDATION_ERROR("Depth stencil attachment sample counts mismatch");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*sampleCount = depthStencilSampleCount;
|
2019-03-15 05:16:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 09:21:56 +00:00
|
|
|
DAWN_TRY(ValidateAttachmentArrayLayersAndLevelCount(attachment));
|
|
|
|
DAWN_TRY(ValidateOrSetAttachmentSize(attachment, width, height));
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-03-19 01:12:01 +00:00
|
|
|
MaybeError ValidateRenderPassDescriptor(const DeviceBase* device,
|
2019-07-10 20:43:13 +00:00
|
|
|
const RenderPassDescriptor* descriptor,
|
2019-03-19 01:12:01 +00:00
|
|
|
uint32_t* width,
|
|
|
|
uint32_t* height,
|
|
|
|
uint32_t* sampleCount) {
|
2019-07-10 20:43:13 +00:00
|
|
|
if (descriptor->colorAttachmentCount > kMaxColorAttachments) {
|
2019-02-27 09:21:56 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Setting color attachments out of bounds");
|
|
|
|
}
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
for (uint32_t i = 0; i < descriptor->colorAttachmentCount; ++i) {
|
|
|
|
DAWN_TRY(ValidateRenderPassColorAttachment(device, descriptor->colorAttachments[i],
|
2019-03-19 01:12:01 +00:00
|
|
|
width, height, sampleCount));
|
2019-02-27 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
if (descriptor->depthStencilAttachment != nullptr) {
|
2019-02-27 09:21:56 +00:00
|
|
|
DAWN_TRY(ValidateRenderPassDepthStencilAttachment(
|
2019-07-10 20:43:13 +00:00
|
|
|
device, descriptor->depthStencilAttachment, width, height, sampleCount));
|
2019-02-27 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
if (descriptor->colorAttachmentCount == 0 &&
|
|
|
|
descriptor->depthStencilAttachment == nullptr) {
|
2019-02-27 09:21:56 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("Cannot use render pass with no attachments.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
MaybeError ValidateComputePassDescriptor(const DeviceBase* device,
|
|
|
|
const ComputePassDescriptor* descriptor) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
CommandEncoderBase::CommandEncoderBase(DeviceBase* device, const CommandEncoderDescriptor*)
|
2019-07-24 18:15:24 +00:00
|
|
|
: ObjectBase(device), mEncodingContext(device, this) {
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandBufferResourceUsage CommandEncoderBase::AcquireResourceUsages() {
|
|
|
|
ASSERT(!mWereResourceUsagesAcquired);
|
|
|
|
mWereResourceUsagesAcquired = true;
|
|
|
|
return std::move(mResourceUsages);
|
|
|
|
}
|
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
CommandIterator CommandEncoderBase::AcquireCommands() {
|
|
|
|
return mEncodingContext.AcquireCommands();
|
2019-02-15 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
// Implementation of the API's command recording methods
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
ComputePassEncoderBase* CommandEncoderBase::BeginComputePass(
|
|
|
|
const ComputePassDescriptor* descriptor) {
|
2019-03-05 01:02:47 +00:00
|
|
|
DeviceBase* device = GetDevice();
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
bool success =
|
|
|
|
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
|
|
|
DAWN_TRY(ValidateComputePassDescriptor(device, descriptor));
|
2019-07-10 20:43:13 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
allocator->Allocate<BeginComputePassCmd>(Command::BeginComputePass);
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
return {};
|
|
|
|
});
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
ComputePassEncoderBase* passEncoder =
|
|
|
|
new ComputePassEncoderBase(device, this, &mEncodingContext);
|
|
|
|
mEncodingContext.EnterPass(passEncoder);
|
|
|
|
return passEncoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ComputePassEncoderBase::MakeError(device, this, &mEncodingContext);
|
2019-02-15 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
RenderPassEncoderBase* CommandEncoderBase::BeginRenderPass(
|
|
|
|
const RenderPassDescriptor* descriptor) {
|
2019-02-27 09:21:56 +00:00
|
|
|
DeviceBase* device = GetDevice();
|
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
bool success =
|
|
|
|
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
|
|
|
uint32_t width = 0;
|
|
|
|
uint32_t height = 0;
|
|
|
|
uint32_t sampleCount = 0;
|
|
|
|
|
|
|
|
DAWN_TRY(ValidateRenderPassDescriptor(device, descriptor, &width, &height,
|
|
|
|
&sampleCount));
|
|
|
|
|
|
|
|
ASSERT(width > 0 && height > 0 && sampleCount > 0);
|
|
|
|
|
|
|
|
BeginRenderPassCmd* cmd =
|
|
|
|
allocator->Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
|
|
|
|
|
2019-07-26 19:08:18 +00:00
|
|
|
cmd->attachmentState = device->GetOrCreateAttachmentState(descriptor);
|
|
|
|
|
|
|
|
for (uint32_t i : IterateBitSet(cmd->attachmentState->GetColorAttachmentsMask())) {
|
|
|
|
cmd->colorAttachments[i].view = descriptor->colorAttachments[i]->attachment;
|
|
|
|
cmd->colorAttachments[i].resolveTarget =
|
|
|
|
descriptor->colorAttachments[i]->resolveTarget;
|
|
|
|
cmd->colorAttachments[i].loadOp = descriptor->colorAttachments[i]->loadOp;
|
|
|
|
cmd->colorAttachments[i].storeOp = descriptor->colorAttachments[i]->storeOp;
|
|
|
|
cmd->colorAttachments[i].clearColor =
|
|
|
|
descriptor->colorAttachments[i]->clearColor;
|
2019-07-24 18:15:24 +00:00
|
|
|
}
|
2019-03-19 01:12:01 +00:00
|
|
|
|
2019-07-26 19:08:18 +00:00
|
|
|
if (cmd->attachmentState->HasDepthStencilAttachment()) {
|
2019-07-24 18:15:24 +00:00
|
|
|
cmd->depthStencilAttachment.view =
|
|
|
|
descriptor->depthStencilAttachment->attachment;
|
|
|
|
cmd->depthStencilAttachment.clearDepth =
|
|
|
|
descriptor->depthStencilAttachment->clearDepth;
|
|
|
|
cmd->depthStencilAttachment.clearStencil =
|
|
|
|
descriptor->depthStencilAttachment->clearStencil;
|
|
|
|
cmd->depthStencilAttachment.depthLoadOp =
|
|
|
|
descriptor->depthStencilAttachment->depthLoadOp;
|
|
|
|
cmd->depthStencilAttachment.depthStoreOp =
|
|
|
|
descriptor->depthStencilAttachment->depthStoreOp;
|
|
|
|
cmd->depthStencilAttachment.stencilLoadOp =
|
|
|
|
descriptor->depthStencilAttachment->stencilLoadOp;
|
|
|
|
cmd->depthStencilAttachment.stencilStoreOp =
|
|
|
|
descriptor->depthStencilAttachment->stencilStoreOp;
|
|
|
|
}
|
2019-02-27 09:21:56 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
cmd->width = width;
|
|
|
|
cmd->height = height;
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
return {};
|
|
|
|
});
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
if (success) {
|
|
|
|
RenderPassEncoderBase* passEncoder =
|
|
|
|
new RenderPassEncoderBase(device, this, &mEncodingContext);
|
|
|
|
mEncodingContext.EnterPass(passEncoder);
|
|
|
|
return passEncoder;
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
return RenderPassEncoderBase::MakeError(device, this, &mEncodingContext);
|
2019-02-15 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandEncoderBase::CopyBufferToBuffer(BufferBase* source,
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t sourceOffset,
|
2019-02-15 12:54:08 +00:00
|
|
|
BufferBase* destination,
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t destinationOffset,
|
|
|
|
uint64_t size) {
|
2019-07-24 18:15:24 +00:00
|
|
|
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(source));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(destination));
|
|
|
|
|
|
|
|
CopyBufferToBufferCmd* copy =
|
|
|
|
allocator->Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
|
|
|
|
copy->source = source;
|
|
|
|
copy->sourceOffset = sourceOffset;
|
|
|
|
copy->destination = destination;
|
|
|
|
copy->destinationOffset = destinationOffset;
|
|
|
|
copy->size = size;
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
return {};
|
|
|
|
});
|
2019-02-15 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandEncoderBase::CopyBufferToTexture(const BufferCopyView* source,
|
|
|
|
const TextureCopyView* destination,
|
|
|
|
const Extent3D* copySize) {
|
2019-07-24 18:15:24 +00:00
|
|
|
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(source->buffer));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(destination->texture));
|
|
|
|
|
|
|
|
CopyBufferToTextureCmd* copy =
|
|
|
|
allocator->Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
|
|
|
|
copy->source.buffer = source->buffer;
|
|
|
|
copy->source.offset = source->offset;
|
|
|
|
copy->destination.texture = destination->texture;
|
|
|
|
copy->destination.origin = destination->origin;
|
|
|
|
copy->copySize = *copySize;
|
|
|
|
copy->destination.mipLevel = destination->mipLevel;
|
|
|
|
copy->destination.arrayLayer = destination->arrayLayer;
|
|
|
|
if (source->rowPitch == 0) {
|
|
|
|
copy->source.rowPitch =
|
|
|
|
ComputeDefaultRowPitch(destination->texture->GetFormat(), copySize->width);
|
|
|
|
} else {
|
|
|
|
copy->source.rowPitch = source->rowPitch;
|
|
|
|
}
|
|
|
|
if (source->imageHeight == 0) {
|
|
|
|
copy->source.imageHeight = copySize->height;
|
|
|
|
} else {
|
|
|
|
copy->source.imageHeight = source->imageHeight;
|
|
|
|
}
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
return {};
|
|
|
|
});
|
2019-02-15 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandEncoderBase::CopyTextureToBuffer(const TextureCopyView* source,
|
|
|
|
const BufferCopyView* destination,
|
|
|
|
const Extent3D* copySize) {
|
2019-07-24 18:15:24 +00:00
|
|
|
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(source->texture));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(destination->buffer));
|
|
|
|
|
|
|
|
CopyTextureToBufferCmd* copy =
|
|
|
|
allocator->Allocate<CopyTextureToBufferCmd>(Command::CopyTextureToBuffer);
|
|
|
|
copy->source.texture = source->texture;
|
|
|
|
copy->source.origin = source->origin;
|
|
|
|
copy->copySize = *copySize;
|
|
|
|
copy->source.mipLevel = source->mipLevel;
|
|
|
|
copy->source.arrayLayer = source->arrayLayer;
|
|
|
|
copy->destination.buffer = destination->buffer;
|
|
|
|
copy->destination.offset = destination->offset;
|
|
|
|
if (destination->rowPitch == 0) {
|
|
|
|
copy->destination.rowPitch =
|
|
|
|
ComputeDefaultRowPitch(source->texture->GetFormat(), copySize->width);
|
|
|
|
} else {
|
|
|
|
copy->destination.rowPitch = destination->rowPitch;
|
|
|
|
}
|
|
|
|
if (destination->imageHeight == 0) {
|
|
|
|
copy->destination.imageHeight = copySize->height;
|
|
|
|
} else {
|
|
|
|
copy->destination.imageHeight = destination->imageHeight;
|
|
|
|
}
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
return {};
|
|
|
|
});
|
2019-02-15 12:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 11:06:23 +00:00
|
|
|
void CommandEncoderBase::CopyTextureToTexture(const TextureCopyView* source,
|
|
|
|
const TextureCopyView* destination,
|
|
|
|
const Extent3D* copySize) {
|
2019-07-24 18:15:24 +00:00
|
|
|
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(source->texture));
|
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(destination->texture));
|
|
|
|
|
|
|
|
CopyTextureToTextureCmd* copy =
|
|
|
|
allocator->Allocate<CopyTextureToTextureCmd>(Command::CopyTextureToTexture);
|
|
|
|
copy->source.texture = source->texture;
|
|
|
|
copy->source.origin = source->origin;
|
|
|
|
copy->source.mipLevel = source->mipLevel;
|
|
|
|
copy->source.arrayLayer = source->arrayLayer;
|
|
|
|
copy->destination.texture = destination->texture;
|
|
|
|
copy->destination.origin = destination->origin;
|
|
|
|
copy->destination.mipLevel = destination->mipLevel;
|
|
|
|
copy->destination.arrayLayer = destination->arrayLayer;
|
|
|
|
copy->copySize = *copySize;
|
2019-03-26 11:06:23 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
return {};
|
|
|
|
});
|
2019-03-26 11:06:23 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
CommandBufferBase* CommandEncoderBase::Finish(const CommandBufferDescriptor* descriptor) {
|
2019-08-13 19:00:34 +00:00
|
|
|
TRACE_EVENT0(GetDevice()->GetPlatform(), TRACE_DISABLED_BY_DEFAULT("gpu.dawn"),
|
|
|
|
"CommandEncoderBase::Finish");
|
2019-07-10 20:43:13 +00:00
|
|
|
if (GetDevice()->ConsumedError(ValidateFinish(descriptor))) {
|
2019-03-28 14:10:01 +00:00
|
|
|
// Even if finish validation fails, it is now invalid to call any encoding commands on
|
|
|
|
// this object, so we set its state to finished.
|
2019-02-15 12:54:08 +00:00
|
|
|
return CommandBufferBase::MakeError(GetDevice());
|
|
|
|
}
|
|
|
|
ASSERT(!IsError());
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
return GetDevice()->CreateCommandBuffer(this, descriptor);
|
2019-02-20 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation of the command buffer validation that can be precomputed before submit
|
|
|
|
|
2019-07-10 20:43:13 +00:00
|
|
|
MaybeError CommandEncoderBase::ValidateFinish(const CommandBufferDescriptor*) {
|
2019-02-15 12:54:08 +00:00
|
|
|
DAWN_TRY(GetDevice()->ValidateObject(this));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
// Even if Finish() validation fails, calling it will mutate the internal state of the
|
|
|
|
// encoding context. Subsequent calls to encode commands will generate errors.
|
|
|
|
DAWN_TRY(mEncodingContext.Finish());
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-24 18:15:24 +00:00
|
|
|
CommandIterator* commands = mEncodingContext.GetIterator();
|
|
|
|
commands->Reset();
|
2019-02-20 11:46:16 +00:00
|
|
|
|
|
|
|
Command type;
|
2019-07-24 18:15:24 +00:00
|
|
|
while (commands->NextCommandId(&type)) {
|
2019-02-20 11:46:16 +00:00
|
|
|
switch (type) {
|
|
|
|
case Command::BeginComputePass: {
|
2019-07-24 18:15:24 +00:00
|
|
|
commands->NextCommand<BeginComputePassCmd>();
|
2019-08-13 00:22:28 +00:00
|
|
|
DAWN_TRY(ValidateComputePass(commands, &mResourceUsages.perPass));
|
2019-02-20 11:46:16 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::BeginRenderPass: {
|
2019-07-24 18:15:24 +00:00
|
|
|
BeginRenderPassCmd* cmd = commands->NextCommand<BeginRenderPassCmd>();
|
2019-08-13 00:22:28 +00:00
|
|
|
DAWN_TRY(ValidateRenderPass(commands, cmd, &mResourceUsages.perPass));
|
2019-02-20 11:46:16 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyBufferToBuffer: {
|
2019-07-24 18:15:24 +00:00
|
|
|
CopyBufferToBufferCmd* copy = commands->NextCommand<CopyBufferToBufferCmd>();
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-06-07 03:06:47 +00:00
|
|
|
DAWN_TRY(
|
|
|
|
ValidateCopySizeFitsInBuffer(copy->source, copy->sourceOffset, copy->size));
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination,
|
|
|
|
copy->destinationOffset, copy->size));
|
|
|
|
DAWN_TRY(ValidateB2BCopySizeAlignment(copy->size, copy->sourceOffset,
|
|
|
|
copy->destinationOffset));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-08-27 08:21:39 +00:00
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->source.Get(), dawn::BufferUsage::CopySrc));
|
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->destination.Get(), dawn::BufferUsage::CopyDst));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-06-07 03:06:47 +00:00
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->source.Get());
|
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->destination.Get());
|
2019-02-20 11:46:16 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyBufferToTexture: {
|
2019-07-24 18:15:24 +00:00
|
|
|
CopyBufferToTextureCmd* copy = commands->NextCommand<CopyBufferToTextureCmd>();
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-03-04 12:01:59 +00:00
|
|
|
DAWN_TRY(
|
|
|
|
ValidateTextureSampleCountInCopyCommands(copy->destination.texture.Get()));
|
|
|
|
|
2019-06-18 01:06:09 +00:00
|
|
|
DAWN_TRY(ValidateImageHeight(copy->destination.texture->GetFormat(),
|
2019-07-02 00:06:55 +00:00
|
|
|
copy->source.imageHeight, copy->copySize.height));
|
2019-06-18 01:06:09 +00:00
|
|
|
DAWN_TRY(ValidateImageOrigin(copy->destination.texture->GetFormat(),
|
|
|
|
copy->destination.origin));
|
|
|
|
DAWN_TRY(ValidateImageCopySize(copy->destination.texture->GetFormat(),
|
|
|
|
copy->copySize));
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
uint32_t bufferCopySize = 0;
|
|
|
|
DAWN_TRY(ValidateRowPitch(copy->destination.texture->GetFormat(),
|
|
|
|
copy->copySize, copy->source.rowPitch));
|
|
|
|
|
2019-06-12 08:53:45 +00:00
|
|
|
DAWN_TRY(ComputeTextureCopyBufferSize(
|
|
|
|
copy->destination.texture->GetFormat(), copy->copySize,
|
|
|
|
copy->source.rowPitch, copy->source.imageHeight, &bufferCopySize));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInTexture(copy->destination, copy->copySize));
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->source, bufferCopySize));
|
2019-06-21 10:16:15 +00:00
|
|
|
DAWN_TRY(ValidateTexelBufferOffset(copy->source,
|
|
|
|
copy->destination.texture->GetFormat()));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-07-08 10:05:46 +00:00
|
|
|
DAWN_TRY(
|
2019-08-27 08:21:39 +00:00
|
|
|
ValidateCanUseAs(copy->source.buffer.Get(), dawn::BufferUsage::CopySrc));
|
2019-02-20 11:46:16 +00:00
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->destination.texture.Get(),
|
2019-08-27 08:21:39 +00:00
|
|
|
dawn::TextureUsage::CopyDst));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->source.buffer.Get());
|
|
|
|
mResourceUsages.topLevelTextures.insert(copy->destination.texture.Get());
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Command::CopyTextureToBuffer: {
|
2019-07-24 18:15:24 +00:00
|
|
|
CopyTextureToBufferCmd* copy = commands->NextCommand<CopyTextureToBufferCmd>();
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-03-04 12:01:59 +00:00
|
|
|
DAWN_TRY(ValidateTextureSampleCountInCopyCommands(copy->source.texture.Get()));
|
|
|
|
|
2019-06-18 01:06:09 +00:00
|
|
|
DAWN_TRY(ValidateImageHeight(copy->source.texture->GetFormat(),
|
2019-07-02 00:06:55 +00:00
|
|
|
copy->destination.imageHeight,
|
|
|
|
copy->copySize.height));
|
2019-06-18 01:06:09 +00:00
|
|
|
DAWN_TRY(ValidateImageOrigin(copy->source.texture->GetFormat(),
|
|
|
|
copy->source.origin));
|
|
|
|
DAWN_TRY(
|
|
|
|
ValidateImageCopySize(copy->source.texture->GetFormat(), copy->copySize));
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
uint32_t bufferCopySize = 0;
|
|
|
|
DAWN_TRY(ValidateRowPitch(copy->source.texture->GetFormat(), copy->copySize,
|
|
|
|
copy->destination.rowPitch));
|
|
|
|
DAWN_TRY(ComputeTextureCopyBufferSize(
|
2019-06-12 08:53:45 +00:00
|
|
|
copy->source.texture->GetFormat(), copy->copySize,
|
|
|
|
copy->destination.rowPitch, copy->destination.imageHeight,
|
2019-02-20 11:46:16 +00:00
|
|
|
&bufferCopySize));
|
|
|
|
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInTexture(copy->source, copy->copySize));
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination, bufferCopySize));
|
2019-06-21 10:16:15 +00:00
|
|
|
DAWN_TRY(ValidateTexelBufferOffset(copy->destination,
|
|
|
|
copy->source.texture->GetFormat()));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
2019-08-27 08:21:39 +00:00
|
|
|
DAWN_TRY(
|
|
|
|
ValidateCanUseAs(copy->source.texture.Get(), dawn::TextureUsage::CopySrc));
|
2019-02-20 11:46:16 +00:00
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
|
2019-08-27 08:21:39 +00:00
|
|
|
dawn::BufferUsage::CopyDst));
|
2019-02-20 11:46:16 +00:00
|
|
|
|
|
|
|
mResourceUsages.topLevelTextures.insert(copy->source.texture.Get());
|
|
|
|
mResourceUsages.topLevelBuffers.insert(copy->destination.buffer.Get());
|
|
|
|
} break;
|
|
|
|
|
2019-03-26 11:06:23 +00:00
|
|
|
case Command::CopyTextureToTexture: {
|
|
|
|
CopyTextureToTextureCmd* copy =
|
2019-07-24 18:15:24 +00:00
|
|
|
commands->NextCommand<CopyTextureToTextureCmd>();
|
2019-03-26 11:06:23 +00:00
|
|
|
|
|
|
|
DAWN_TRY(ValidateTextureToTextureCopyRestrictions(
|
|
|
|
copy->source, copy->destination, copy->copySize));
|
|
|
|
|
2019-06-18 01:06:09 +00:00
|
|
|
DAWN_TRY(ValidateImageOrigin(copy->source.texture->GetFormat(),
|
|
|
|
copy->source.origin));
|
|
|
|
DAWN_TRY(
|
|
|
|
ValidateImageCopySize(copy->source.texture->GetFormat(), copy->copySize));
|
|
|
|
DAWN_TRY(ValidateImageOrigin(copy->destination.texture->GetFormat(),
|
|
|
|
copy->destination.origin));
|
|
|
|
DAWN_TRY(ValidateImageCopySize(copy->destination.texture->GetFormat(),
|
|
|
|
copy->copySize));
|
|
|
|
|
2019-03-26 11:06:23 +00:00
|
|
|
DAWN_TRY(ValidateCopySizeFitsInTexture(copy->source, copy->copySize));
|
|
|
|
DAWN_TRY(ValidateCopySizeFitsInTexture(copy->destination, copy->copySize));
|
|
|
|
|
2019-08-27 08:21:39 +00:00
|
|
|
DAWN_TRY(
|
|
|
|
ValidateCanUseAs(copy->source.texture.Get(), dawn::TextureUsage::CopySrc));
|
2019-03-26 11:06:23 +00:00
|
|
|
DAWN_TRY(ValidateCanUseAs(copy->destination.texture.Get(),
|
2019-08-27 08:21:39 +00:00
|
|
|
dawn::TextureUsage::CopyDst));
|
2019-03-26 11:06:23 +00:00
|
|
|
|
|
|
|
mResourceUsages.topLevelTextures.insert(copy->source.texture.Get());
|
|
|
|
mResourceUsages.topLevelTextures.insert(copy->destination.texture.Get());
|
|
|
|
} break;
|
|
|
|
|
2019-02-20 11:46:16 +00:00
|
|
|
default:
|
|
|
|
return DAWN_VALIDATION_ERROR("Command disallowed outside of a pass");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 12:54:08 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dawn_native
|