[Mac] Pass all usages when creating MTLTextures for SharedTextureMemory
This CL makes the following change: When creating MTLTextures from
IOSurfaces vended by SharedTextureMemory, we now pass all Metal texture
usages. This will facilitate an upcoming change to have
SharedTextureMemory cache MTLTextures. See discussion in [1] and its
following comments for both (a) why this is necessary and (b) why it is
not harmful to performance.
Note: As this CL is a functional change, I tested it manually in Chrome
with the WebGPU github examples as well as with Graphite enabled (both
on the WebGPU github examples and just general rendering for Graphite).
Everything renders unproblematically and without any error messages
being generated.
[1] https://bugs.chromium.org/p/dawn/issues/detail?id=2152#c14
Change-Id: I3c57b13425b3ff3315d453d29e3a24788588a705
Bug: dawn:2152, 1493854
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/169660
Commit-Queue: Colin Blundell <blundell@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm
index 7247e27..91c6221 100644
--- a/src/dawn/native/metal/TextureMTL.mm
+++ b/src/dawn/native/metal/TextureMTL.mm
@@ -48,6 +48,16 @@
namespace {
+// NOTE: When creating MTLTextures from IOSurfaces vended by
+// SharedTextureMemory, we pass all Metal texture usages. This will facilitate an
+// upcoming change to have SharedTextureMemory cache MTLTextures. See
+// discussion in https://bugs.chromium.org/p/dawn/issues/detail?id=2152#c14 and
+// following comments for both (a) why this is necessary and (b) why it is not
+// harmful to performance.
+const MTLTextureUsage kMetalTextureUsageForSharedTextureMemoryIOSurface =
+ MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView |
+ MTLTextureUsageRenderTarget;
+
MTLTextureUsage MetalTextureUsage(const Format& format, wgpu::TextureUsage usage) {
MTLTextureUsage result = MTLTextureUsageUnknown; // This is 0
@@ -421,14 +431,8 @@
// Metal only allows format reinterpretation to happen on swizzle pattern or conversion
// between linear space and sRGB. For example, creating bgra8Unorm texture view on
// rgba8Unorm texture or creating rgba8Unorm_srgb texture view on rgab8Unorm texture.
- mtlDesc.usage = MetalTextureUsage(GetFormat(), GetInternalUsage());
+ mtlDesc.usage = kMetalTextureUsageForSharedTextureMemoryIOSurface;
mtlDesc.pixelFormat = MetalPixelFormat(GetDevice(), GetFormat().format);
- if (GetDevice()->IsToggleEnabled(Toggle::MetalUseCombinedDepthStencilFormatForStencil8) &&
- GetFormat().format == wgpu::TextureFormat::Stencil8) {
- // If we used a combined depth stencil format instead of stencil8, we need
- // MTLTextureUsagePixelFormatView to reinterpet as stencil8.
- mtlDesc.usage |= MTLTextureUsagePixelFormatView;
- }
mMtlUsage = mtlDesc.usage;
mMtlFormat = mtlDesc.pixelFormat;
@@ -438,7 +442,7 @@
iosurface:ioSurface
plane:0]);
} else {
- mMtlUsage = MetalTextureUsage(GetFormat(), GetInternalUsage());
+ mMtlUsage = kMetalTextureUsageForSharedTextureMemoryIOSurface;
// Multiplanar format doesn't have equivalent MTLPixelFormat so just set it to invalid.
mMtlFormat = MTLPixelFormatInvalid;
const size_t numPlanes = IOSurfaceGetPlaneCount(GetIOSurface());