mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Allow unaligned source offset in writeTexture
With some refactoring of the relevant validation code. Bug: dawn:520 Change-Id: Iedda0f7b1b67c20d3a88f2c4183dcc8eeae2096f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30742 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
ff39c28c6a
commit
54123a391f
@@ -101,36 +101,20 @@ namespace dawn_native {
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError ValidateTextureToBufferCopyRestrictions(const TextureCopyView& src) {
|
||||
const Format& format = src.texture->GetFormat();
|
||||
|
||||
bool depthSelected = false;
|
||||
switch (src.aspect) {
|
||||
case wgpu::TextureAspect::All:
|
||||
switch (format.aspects) {
|
||||
case Aspect::Color:
|
||||
case Aspect::Stencil:
|
||||
break;
|
||||
case Aspect::Depth:
|
||||
depthSelected = true;
|
||||
break;
|
||||
default:
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"A single aspect must be selected for multi planar formats in "
|
||||
"texture to buffer copies");
|
||||
}
|
||||
break;
|
||||
case wgpu::TextureAspect::DepthOnly:
|
||||
ASSERT(format.aspects & Aspect::Depth);
|
||||
depthSelected = true;
|
||||
break;
|
||||
case wgpu::TextureAspect::StencilOnly:
|
||||
ASSERT(format.aspects & Aspect::Stencil);
|
||||
break;
|
||||
MaybeError ValidateLinearTextureCopyOffset(const TextureDataLayout& layout,
|
||||
const TexelBlockInfo& blockInfo) {
|
||||
if (layout.offset % blockInfo.byteSize != 0) {
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"offset must be a multiple of the texel block byte size.");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
if (depthSelected) {
|
||||
switch (format.format) {
|
||||
MaybeError ValidateTextureDepthStencilToBufferCopyRestrictions(const TextureCopyView& src) {
|
||||
Aspect aspectUsed;
|
||||
DAWN_TRY_ASSIGN(aspectUsed, SingleAspectUsedByTextureCopyView(src));
|
||||
if (aspectUsed == Aspect::Depth) {
|
||||
switch (src.texture->GetFormat().format) {
|
||||
case wgpu::TextureFormat::Depth24Plus:
|
||||
case wgpu::TextureFormat::Depth24PlusStencil8:
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
@@ -640,7 +624,7 @@ namespace dawn_native {
|
||||
DAWN_TRY(ValidateCanUseAs(destination->texture, wgpu::TextureUsage::CopyDst));
|
||||
DAWN_TRY(ValidateTextureSampleCountInBufferCopyCommands(destination->texture));
|
||||
|
||||
DAWN_TRY(ValidateBufferToTextureCopyRestrictions(*destination));
|
||||
DAWN_TRY(ValidateLinearToDepthStencilCopyRestrictions(*destination));
|
||||
// We validate texture copy range before validating linear texture data,
|
||||
// because in the latter we divide copyExtent.width by blockWidth and
|
||||
// copyExtent.height by blockHeight while the divisibility conditions are
|
||||
@@ -650,6 +634,7 @@ namespace dawn_native {
|
||||
const TexelBlockInfo& blockInfo =
|
||||
destination->texture->GetFormat().GetAspectInfo(destination->aspect).block;
|
||||
if (GetDevice()->IsValidationEnabled()) {
|
||||
DAWN_TRY(ValidateLinearTextureCopyOffset(source->layout, blockInfo));
|
||||
DAWN_TRY(ValidateLinearTextureData(source->layout, source->buffer->GetSize(),
|
||||
blockInfo, *copySize));
|
||||
|
||||
@@ -700,11 +685,11 @@ namespace dawn_native {
|
||||
DAWN_TRY(ValidateTextureCopyView(GetDevice(), *source, *copySize));
|
||||
DAWN_TRY(ValidateCanUseAs(source->texture, wgpu::TextureUsage::CopySrc));
|
||||
DAWN_TRY(ValidateTextureSampleCountInBufferCopyCommands(source->texture));
|
||||
DAWN_TRY(ValidateTextureDepthStencilToBufferCopyRestrictions(*source));
|
||||
|
||||
DAWN_TRY(ValidateBufferCopyView(GetDevice(), *destination));
|
||||
DAWN_TRY(ValidateCanUseAs(destination->buffer, wgpu::BufferUsage::CopyDst));
|
||||
|
||||
DAWN_TRY(ValidateTextureToBufferCopyRestrictions(*source));
|
||||
// We validate texture copy range before validating linear texture data,
|
||||
// because in the latter we divide copyExtent.width by blockWidth and
|
||||
// copyExtent.height by blockHeight while the divisibility conditions are
|
||||
@@ -714,6 +699,7 @@ namespace dawn_native {
|
||||
const TexelBlockInfo& blockInfo =
|
||||
source->texture->GetFormat().GetAspectInfo(source->aspect).block;
|
||||
if (GetDevice()->IsValidationEnabled()) {
|
||||
DAWN_TRY(ValidateLinearTextureCopyOffset(destination->layout, blockInfo));
|
||||
DAWN_TRY(ValidateLinearTextureData(
|
||||
destination->layout, destination->buffer->GetSize(), blockInfo, *copySize));
|
||||
|
||||
|
||||
@@ -446,11 +446,6 @@ namespace dawn_native {
|
||||
uint64_t byteSize,
|
||||
const TexelBlockInfo& blockInfo,
|
||||
const Extent3D& copyExtent) {
|
||||
// Validation for the texel block alignments:
|
||||
if (layout.offset % blockInfo.byteSize != 0) {
|
||||
return DAWN_VALIDATION_ERROR("Offset must be a multiple of the texel or block size");
|
||||
}
|
||||
|
||||
ASSERT(copyExtent.width % blockInfo.width == 0);
|
||||
uint32_t widthInBlocks = copyExtent.width / blockInfo.width;
|
||||
ASSERT(copyExtent.height % blockInfo.height == 0);
|
||||
@@ -589,36 +584,35 @@ namespace dawn_native {
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError ValidateBufferToTextureCopyRestrictions(const TextureCopyView& dst) {
|
||||
const Format& format = dst.texture->GetFormat();
|
||||
|
||||
bool depthSelected = false;
|
||||
switch (dst.aspect) {
|
||||
// Always returns a single aspect (color, stencil, or depth).
|
||||
ResultOrError<Aspect> SingleAspectUsedByTextureCopyView(const TextureCopyView& view) {
|
||||
const Format& format = view.texture->GetFormat();
|
||||
switch (view.aspect) {
|
||||
case wgpu::TextureAspect::All:
|
||||
switch (format.aspects) {
|
||||
case Aspect::Color:
|
||||
case Aspect::Stencil:
|
||||
break;
|
||||
case Aspect::Depth:
|
||||
depthSelected = true;
|
||||
break;
|
||||
default:
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"A single aspect must be selected for multi planar formats in buffer "
|
||||
"to texture copies");
|
||||
if (HasOneBit(format.aspects)) {
|
||||
return Aspect{format.aspects};
|
||||
} else {
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"A single aspect must be selected for multi-planar formats in "
|
||||
"texture <-> linear data copies");
|
||||
}
|
||||
break;
|
||||
case wgpu::TextureAspect::DepthOnly:
|
||||
ASSERT(format.aspects & Aspect::Depth);
|
||||
depthSelected = true;
|
||||
break;
|
||||
return Aspect::Depth;
|
||||
case wgpu::TextureAspect::StencilOnly:
|
||||
ASSERT(format.aspects & Aspect::Stencil);
|
||||
break;
|
||||
return Aspect::Stencil;
|
||||
}
|
||||
if (depthSelected) {
|
||||
}
|
||||
|
||||
MaybeError ValidateLinearToDepthStencilCopyRestrictions(const TextureCopyView& dst) {
|
||||
Aspect aspectUsed;
|
||||
DAWN_TRY_ASSIGN(aspectUsed, SingleAspectUsedByTextureCopyView(dst));
|
||||
if (aspectUsed == Aspect::Depth) {
|
||||
return DAWN_VALIDATION_ERROR("Cannot copy into the depth aspect of a texture");
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ namespace dawn_native {
|
||||
const Extent3D& copyExtent);
|
||||
MaybeError ValidateTextureCopyRange(const TextureCopyView& textureCopyView,
|
||||
const Extent3D& copySize);
|
||||
MaybeError ValidateBufferToTextureCopyRestrictions(const TextureCopyView& dst);
|
||||
ResultOrError<Aspect> SingleAspectUsedByTextureCopyView(const TextureCopyView& view);
|
||||
MaybeError ValidateLinearToDepthStencilCopyRestrictions(const TextureCopyView& dst);
|
||||
|
||||
MaybeError ValidateBufferCopyView(DeviceBase const* device,
|
||||
const BufferCopyView& bufferCopyView);
|
||||
|
||||
@@ -415,7 +415,7 @@ namespace dawn_native {
|
||||
return DAWN_VALIDATION_ERROR("The sample count of textures must be 1");
|
||||
}
|
||||
|
||||
DAWN_TRY(ValidateBufferToTextureCopyRestrictions(*destination));
|
||||
DAWN_TRY(ValidateLinearToDepthStencilCopyRestrictions(*destination));
|
||||
// We validate texture copy range before validating linear texture data,
|
||||
// because in the latter we divide copyExtent.width by blockWidth and
|
||||
// copyExtent.height by blockHeight while the divisibility conditions are
|
||||
|
||||
Reference in New Issue
Block a user