mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-17 04:41:23 +00:00
Metal: Add CommandRecordingContext argument to ClearTexture
This is more consistent with the other backends that have a CommandRecordingContext. Bug: dawn:780 Change-Id: Icb689d00cc4d873a489fc4d4c247feeb15f8797c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/50120 Commit-Queue: Stephen White <senorblanco@chromium.org> Auto-Submit: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
parent
26b3915b54
commit
26468c4071
@ -565,7 +565,7 @@ namespace dawn_native { namespace metal {
|
|||||||
scope.textureUsages[i].Iterate(
|
scope.textureUsages[i].Iterate(
|
||||||
[&](const SubresourceRange& range, wgpu::TextureUsage usage) {
|
[&](const SubresourceRange& range, wgpu::TextureUsage usage) {
|
||||||
if (usage & ~wgpu::TextureUsage::RenderAttachment) {
|
if (usage & ~wgpu::TextureUsage::RenderAttachment) {
|
||||||
texture->EnsureSubresourceContentInitialized(range);
|
texture->EnsureSubresourceContentInitialized(commandContext, range);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -634,7 +634,8 @@ namespace dawn_native { namespace metal {
|
|||||||
Texture* texture = ToBackend(dst.texture.Get());
|
Texture* texture = ToBackend(dst.texture.Get());
|
||||||
|
|
||||||
buffer->EnsureDataInitialized(commandContext);
|
buffer->EnsureDataInitialized(commandContext);
|
||||||
EnsureDestinationTextureInitialized(texture, copy->destination, copy->copySize);
|
EnsureDestinationTextureInitialized(commandContext, texture, copy->destination,
|
||||||
|
copy->copySize);
|
||||||
|
|
||||||
TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit(
|
TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit(
|
||||||
texture, dst.mipLevel, dst.origin, copySize, buffer->GetSize(), src.offset,
|
texture, dst.mipLevel, dst.origin, copySize, buffer->GetSize(), src.offset,
|
||||||
@ -684,7 +685,7 @@ namespace dawn_native { namespace metal {
|
|||||||
buffer->EnsureDataInitializedAsDestination(commandContext, copy);
|
buffer->EnsureDataInitializedAsDestination(commandContext, copy);
|
||||||
|
|
||||||
texture->EnsureSubresourceContentInitialized(
|
texture->EnsureSubresourceContentInitialized(
|
||||||
GetSubresourcesAffectedByCopy(src, copySize));
|
commandContext, GetSubresourcesAffectedByCopy(src, copySize));
|
||||||
|
|
||||||
TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit(
|
TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit(
|
||||||
texture, src.mipLevel, src.origin, copySize, buffer->GetSize(), dst.offset,
|
texture, src.mipLevel, src.origin, copySize, buffer->GetSize(), dst.offset,
|
||||||
@ -730,9 +731,10 @@ namespace dawn_native { namespace metal {
|
|||||||
Texture* dstTexture = ToBackend(copy->destination.texture.Get());
|
Texture* dstTexture = ToBackend(copy->destination.texture.Get());
|
||||||
|
|
||||||
srcTexture->EnsureSubresourceContentInitialized(
|
srcTexture->EnsureSubresourceContentInitialized(
|
||||||
|
commandContext,
|
||||||
GetSubresourcesAffectedByCopy(copy->source, copy->copySize));
|
GetSubresourcesAffectedByCopy(copy->source, copy->copySize));
|
||||||
EnsureDestinationTextureInitialized(dstTexture, copy->destination,
|
EnsureDestinationTextureInitialized(commandContext, dstTexture,
|
||||||
copy->copySize);
|
copy->destination, copy->copySize);
|
||||||
|
|
||||||
// TODO(jiawei.shao@intel.com): support copies with 1D and 3D textures.
|
// TODO(jiawei.shao@intel.com): support copies with 1D and 3D textures.
|
||||||
ASSERT(srcTexture->GetDimension() == wgpu::TextureDimension::e2D &&
|
ASSERT(srcTexture->GetDimension() == wgpu::TextureDimension::e2D &&
|
||||||
|
@ -306,7 +306,8 @@ namespace dawn_native { namespace metal {
|
|||||||
ASSERT(dataLayout.bytesPerRow ==
|
ASSERT(dataLayout.bytesPerRow ==
|
||||||
copySizePixels.width / blockInfo.width * blockInfo.byteSize);
|
copySizePixels.width / blockInfo.width * blockInfo.byteSize);
|
||||||
|
|
||||||
EnsureDestinationTextureInitialized(texture, *dst, copySizePixels);
|
EnsureDestinationTextureInitialized(GetPendingCommandContext(), texture, *dst,
|
||||||
|
copySizePixels);
|
||||||
|
|
||||||
// Metal validation layer requires that if the texture's pixel format is a compressed
|
// Metal validation layer requires that if the texture's pixel format is a compressed
|
||||||
// format, the sourceSize must be a multiple of the pixel format's block size or be
|
// format, the sourceSize must be a multiple of the pixel format's block size or be
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
namespace dawn_native { namespace metal {
|
namespace dawn_native { namespace metal {
|
||||||
|
|
||||||
|
class CommandRecordingContext;
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format);
|
MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format);
|
||||||
@ -48,7 +49,8 @@ namespace dawn_native { namespace metal {
|
|||||||
|
|
||||||
id<MTLTexture> GetMTLTexture();
|
id<MTLTexture> GetMTLTexture();
|
||||||
|
|
||||||
void EnsureSubresourceContentInitialized(const SubresourceRange& range);
|
void EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext,
|
||||||
|
const SubresourceRange& range);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Texture(Device* device, const TextureDescriptor* descriptor);
|
Texture(Device* device, const TextureDescriptor* descriptor);
|
||||||
@ -56,7 +58,9 @@ namespace dawn_native { namespace metal {
|
|||||||
|
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
|
|
||||||
MaybeError ClearTexture(const SubresourceRange& range, TextureBase::ClearValue clearValue);
|
MaybeError ClearTexture(CommandRecordingContext* commandContext,
|
||||||
|
const SubresourceRange& range,
|
||||||
|
TextureBase::ClearValue clearValue);
|
||||||
|
|
||||||
NSPRef<id<MTLTexture>> mMtlTexture;
|
NSPRef<id<MTLTexture>> mMtlTexture;
|
||||||
};
|
};
|
||||||
|
@ -359,8 +359,9 @@ namespace dawn_native { namespace metal {
|
|||||||
AcquireNSPRef([device->GetMTLDevice() newTextureWithDescriptor:mtlDesc.Get()]);
|
AcquireNSPRef([device->GetMTLDevice() newTextureWithDescriptor:mtlDesc.Get()]);
|
||||||
|
|
||||||
if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) {
|
if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) {
|
||||||
device->ConsumedError(
|
device->ConsumedError(ClearTexture(device->GetPendingCommandContext(),
|
||||||
ClearTexture(GetAllSubresources(), TextureBase::ClearValue::NonZero));
|
GetAllSubresources(),
|
||||||
|
TextureBase::ClearValue::NonZero));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,12 +402,11 @@ namespace dawn_native { namespace metal {
|
|||||||
return mMtlTexture.Get();
|
return mMtlTexture.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Texture::ClearTexture(const SubresourceRange& range,
|
MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
|
||||||
|
const SubresourceRange& range,
|
||||||
TextureBase::ClearValue clearValue) {
|
TextureBase::ClearValue clearValue) {
|
||||||
Device* device = ToBackend(GetDevice());
|
Device* device = ToBackend(GetDevice());
|
||||||
|
|
||||||
CommandRecordingContext* commandContext = device->GetPendingCommandContext();
|
|
||||||
|
|
||||||
const uint8_t clearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0 : 1;
|
const uint8_t clearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0 : 1;
|
||||||
const double dClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.0 : 1.0;
|
const double dClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.0 : 1.0;
|
||||||
|
|
||||||
@ -595,14 +595,16 @@ namespace dawn_native { namespace metal {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::EnsureSubresourceContentInitialized(const SubresourceRange& range) {
|
void Texture::EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext,
|
||||||
|
const SubresourceRange& range) {
|
||||||
if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
|
if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!IsSubresourceContentInitialized(range)) {
|
if (!IsSubresourceContentInitialized(range)) {
|
||||||
// If subresource has not been initialized, clear it to black as it could
|
// If subresource has not been initialized, clear it to black as it could
|
||||||
// contain dirty bits from recycled memory
|
// contain dirty bits from recycled memory
|
||||||
GetDevice()->ConsumedError(ClearTexture(range, TextureBase::ClearValue::Zero));
|
GetDevice()->ConsumedError(
|
||||||
|
ClearTexture(commandContext, range, TextureBase::ClearValue::Zero));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ namespace dawn_native { namespace metal {
|
|||||||
uint32_t rowsPerImage,
|
uint32_t rowsPerImage,
|
||||||
Aspect aspect);
|
Aspect aspect);
|
||||||
|
|
||||||
void EnsureDestinationTextureInitialized(Texture* texture,
|
void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext,
|
||||||
|
Texture* texture,
|
||||||
const TextureCopy& dst,
|
const TextureCopy& dst,
|
||||||
const Extent3D& size);
|
const Extent3D& size);
|
||||||
|
|
||||||
|
@ -154,7 +154,8 @@ namespace dawn_native { namespace metal {
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnsureDestinationTextureInitialized(Texture* texture,
|
void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext,
|
||||||
|
Texture* texture,
|
||||||
const TextureCopy& dst,
|
const TextureCopy& dst,
|
||||||
const Extent3D& size) {
|
const Extent3D& size) {
|
||||||
ASSERT(texture == dst.texture.Get());
|
ASSERT(texture == dst.texture.Get());
|
||||||
@ -162,7 +163,7 @@ namespace dawn_native { namespace metal {
|
|||||||
if (IsCompleteSubresourceCopiedTo(dst.texture.Get(), size, dst.mipLevel)) {
|
if (IsCompleteSubresourceCopiedTo(dst.texture.Get(), size, dst.mipLevel)) {
|
||||||
texture->SetIsSubresourceContentInitialized(true, range);
|
texture->SetIsSubresourceContentInitialized(true, range);
|
||||||
} else {
|
} else {
|
||||||
texture->EnsureSubresourceContentInitialized(range);
|
texture->EnsureSubresourceContentInitialized(commandContext, range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user