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(
|
||||
[&](const SubresourceRange& range, wgpu::TextureUsage usage) {
|
||||
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());
|
||||
|
||||
buffer->EnsureDataInitialized(commandContext);
|
||||
EnsureDestinationTextureInitialized(texture, copy->destination, copy->copySize);
|
||||
EnsureDestinationTextureInitialized(commandContext, texture, copy->destination,
|
||||
copy->copySize);
|
||||
|
||||
TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit(
|
||||
texture, dst.mipLevel, dst.origin, copySize, buffer->GetSize(), src.offset,
|
||||
|
@ -684,7 +685,7 @@ namespace dawn_native { namespace metal {
|
|||
buffer->EnsureDataInitializedAsDestination(commandContext, copy);
|
||||
|
||||
texture->EnsureSubresourceContentInitialized(
|
||||
GetSubresourcesAffectedByCopy(src, copySize));
|
||||
commandContext, GetSubresourcesAffectedByCopy(src, copySize));
|
||||
|
||||
TextureBufferCopySplit splitCopies = ComputeTextureBufferCopySplit(
|
||||
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());
|
||||
|
||||
srcTexture->EnsureSubresourceContentInitialized(
|
||||
commandContext,
|
||||
GetSubresourcesAffectedByCopy(copy->source, copy->copySize));
|
||||
EnsureDestinationTextureInitialized(dstTexture, copy->destination,
|
||||
copy->copySize);
|
||||
EnsureDestinationTextureInitialized(commandContext, dstTexture,
|
||||
copy->destination, copy->copySize);
|
||||
|
||||
// TODO(jiawei.shao@intel.com): support copies with 1D and 3D textures.
|
||||
ASSERT(srcTexture->GetDimension() == wgpu::TextureDimension::e2D &&
|
||||
|
|
|
@ -306,7 +306,8 @@ namespace dawn_native { namespace metal {
|
|||
ASSERT(dataLayout.bytesPerRow ==
|
||||
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
|
||||
// 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 {
|
||||
|
||||
class CommandRecordingContext;
|
||||
class Device;
|
||||
|
||||
MTLPixelFormat MetalPixelFormat(wgpu::TextureFormat format);
|
||||
|
@ -48,7 +49,8 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
id<MTLTexture> GetMTLTexture();
|
||||
|
||||
void EnsureSubresourceContentInitialized(const SubresourceRange& range);
|
||||
void EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext,
|
||||
const SubresourceRange& range);
|
||||
|
||||
private:
|
||||
Texture(Device* device, const TextureDescriptor* descriptor);
|
||||
|
@ -56,7 +58,9 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -359,8 +359,9 @@ namespace dawn_native { namespace metal {
|
|||
AcquireNSPRef([device->GetMTLDevice() newTextureWithDescriptor:mtlDesc.Get()]);
|
||||
|
||||
if (device->IsToggleEnabled(Toggle::NonzeroClearResourcesOnCreationForTesting)) {
|
||||
device->ConsumedError(
|
||||
ClearTexture(GetAllSubresources(), TextureBase::ClearValue::NonZero));
|
||||
device->ConsumedError(ClearTexture(device->GetPendingCommandContext(),
|
||||
GetAllSubresources(),
|
||||
TextureBase::ClearValue::NonZero));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,12 +402,11 @@ namespace dawn_native { namespace metal {
|
|||
return mMtlTexture.Get();
|
||||
}
|
||||
|
||||
MaybeError Texture::ClearTexture(const SubresourceRange& range,
|
||||
MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
|
||||
const SubresourceRange& range,
|
||||
TextureBase::ClearValue clearValue) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
CommandRecordingContext* commandContext = device->GetPendingCommandContext();
|
||||
|
||||
const uint8_t clearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0 : 1;
|
||||
const double dClearColor = (clearValue == TextureBase::ClearValue::Zero) ? 0.0 : 1.0;
|
||||
|
||||
|
@ -595,14 +595,16 @@ namespace dawn_native { namespace metal {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Texture::EnsureSubresourceContentInitialized(const SubresourceRange& range) {
|
||||
void Texture::EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext,
|
||||
const SubresourceRange& range) {
|
||||
if (!GetDevice()->IsToggleEnabled(Toggle::LazyClearResourceOnFirstUse)) {
|
||||
return;
|
||||
}
|
||||
if (!IsSubresourceContentInitialized(range)) {
|
||||
// If subresource has not been initialized, clear it to black as it could
|
||||
// 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,
|
||||
Aspect aspect);
|
||||
|
||||
void EnsureDestinationTextureInitialized(Texture* texture,
|
||||
void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext,
|
||||
Texture* texture,
|
||||
const TextureCopy& dst,
|
||||
const Extent3D& size);
|
||||
|
||||
|
|
|
@ -154,7 +154,8 @@ namespace dawn_native { namespace metal {
|
|||
return copy;
|
||||
}
|
||||
|
||||
void EnsureDestinationTextureInitialized(Texture* texture,
|
||||
void EnsureDestinationTextureInitialized(CommandRecordingContext* commandContext,
|
||||
Texture* texture,
|
||||
const TextureCopy& dst,
|
||||
const Extent3D& size) {
|
||||
ASSERT(texture == dst.texture.Get());
|
||||
|
@ -162,7 +163,7 @@ namespace dawn_native { namespace metal {
|
|||
if (IsCompleteSubresourceCopiedTo(dst.texture.Get(), size, dst.mipLevel)) {
|
||||
texture->SetIsSubresourceContentInitialized(true, range);
|
||||
} else {
|
||||
texture->EnsureSubresourceContentInitialized(range);
|
||||
texture->EnsureSubresourceContentInitialized(commandContext, range);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue