Title: [292098] trunk/Source/WebGPU
Revision
292098
Author
[email protected]
Date
2022-03-30 00:22:05 -0700 (Wed, 30 Mar 2022)

Log Message

[WebGPU] Refactor isDepthOrStencilFormat() for upcoming data transfer patches
https://bugs.webkit.org/show_bug.cgi?id=238427

Reviewed by Kimmo Kinnunen.

This exposes isDepthOrStencilFormat() outside of Texture.mm, and changes its implementation
to use depthSpecificFormat() and stencilSpecificFormat(), which will become useful in the
implementation of subsequent data transfer patches.

* WebGPU/Texture.h:
* WebGPU/Texture.mm:
(WebGPU::depthSpecificFormat):
(WebGPU::stencilSpecificFormat):
(WebGPU::Texture::containsDepthAspect):
(WebGPU::Texture::containsStencilAspect):
(WebGPU::Texture::isDepthOrStencilFormat):
(WebGPU::Device::validateCreateTexture):
(WebGPU::isDepthOrStencilFormat): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebGPU/ChangeLog (292097 => 292098)


--- trunk/Source/WebGPU/ChangeLog	2022-03-30 07:03:38 UTC (rev 292097)
+++ trunk/Source/WebGPU/ChangeLog	2022-03-30 07:22:05 UTC (rev 292098)
@@ -1,3 +1,24 @@
+2022-03-30  Myles C. Maxfield  <[email protected]>
+
+        [WebGPU] Refactor isDepthOrStencilFormat() for upcoming data transfer patches
+        https://bugs.webkit.org/show_bug.cgi?id=238427
+
+        Reviewed by Kimmo Kinnunen.
+
+        This exposes isDepthOrStencilFormat() outside of Texture.mm, and changes its implementation
+        to use depthSpecificFormat() and stencilSpecificFormat(), which will become useful in the
+        implementation of subsequent data transfer patches.
+
+        * WebGPU/Texture.h:
+        * WebGPU/Texture.mm:
+        (WebGPU::depthSpecificFormat):
+        (WebGPU::stencilSpecificFormat):
+        (WebGPU::Texture::containsDepthAspect):
+        (WebGPU::Texture::containsStencilAspect):
+        (WebGPU::Texture::isDepthOrStencilFormat):
+        (WebGPU::Device::validateCreateTexture):
+        (WebGPU::isDepthOrStencilFormat): Deleted.
+
 2022-03-25  Myles C. Maxfield  <[email protected]>
 
         [WebGPU] Remove default: from switch statements, in favor of exhaustively listing all cases

Modified: trunk/Source/WebGPU/WebGPU/Texture.h (292097 => 292098)


--- trunk/Source/WebGPU/WebGPU/Texture.h	2022-03-30 07:03:38 UTC (rev 292097)
+++ trunk/Source/WebGPU/WebGPU/Texture.h	2022-03-30 07:22:05 UTC (rev 292098)
@@ -51,6 +51,12 @@
     void destroy();
     void setLabel(String&&);
 
+    static uint32_t texelBlockWidth(WGPUTextureFormat); // Texels
+    static uint32_t texelBlockHeight(WGPUTextureFormat); // Texels
+    static bool containsDepthAspect(WGPUTextureFormat);
+    static bool containsStencilAspect(WGPUTextureFormat);
+    static bool isDepthOrStencilFormat(WGPUTextureFormat);
+
     id<MTLTexture> texture() const { return m_texture; }
     const WGPUTextureDescriptor& descriptor() const { return m_descriptor; }
 

Modified: trunk/Source/WebGPU/WebGPU/Texture.mm (292097 => 292098)


--- trunk/Source/WebGPU/WebGPU/Texture.mm	2022-03-30 07:03:38 UTC (rev 292097)
+++ trunk/Source/WebGPU/WebGPU/Texture.mm	2022-03-30 07:22:05 UTC (rev 292098)
@@ -247,20 +247,126 @@
     }
 }
 
-static bool isDepthOrStencilFormat(WGPUTextureFormat format)
+static std::optional<WGPUTextureFormat> depthSpecificFormat(WGPUTextureFormat textureFormat)
 {
-    // https://gpuweb.github.io/gpuweb/#depth-formats
-    // "A depth-or-stencil format is any format with depth and/or stencil aspects."
-    switch (format) {
+    // https://gpuweb.github.io/gpuweb/#aspect-specific-format
+
+    switch (textureFormat) {
+    case WGPUTextureFormat_R8Unorm:
+    case WGPUTextureFormat_R8Snorm:
+    case WGPUTextureFormat_R8Uint:
+    case WGPUTextureFormat_R8Sint:
+    case WGPUTextureFormat_R16Uint:
+    case WGPUTextureFormat_R16Sint:
+    case WGPUTextureFormat_R16Float:
+    case WGPUTextureFormat_RG8Unorm:
+    case WGPUTextureFormat_RG8Snorm:
+    case WGPUTextureFormat_RG8Uint:
+    case WGPUTextureFormat_RG8Sint:
+    case WGPUTextureFormat_R32Float:
+    case WGPUTextureFormat_R32Uint:
+    case WGPUTextureFormat_R32Sint:
+    case WGPUTextureFormat_RG16Uint:
+    case WGPUTextureFormat_RG16Sint:
+    case WGPUTextureFormat_RG16Float:
+    case WGPUTextureFormat_RGBA8Unorm:
+    case WGPUTextureFormat_RGBA8UnormSrgb:
+    case WGPUTextureFormat_RGBA8Snorm:
+    case WGPUTextureFormat_RGBA8Uint:
+    case WGPUTextureFormat_RGBA8Sint:
+    case WGPUTextureFormat_BGRA8Unorm:
+    case WGPUTextureFormat_BGRA8UnormSrgb:
+    case WGPUTextureFormat_RGB10A2Unorm:
+    case WGPUTextureFormat_RG11B10Ufloat:
+    case WGPUTextureFormat_RGB9E5Ufloat:
+    case WGPUTextureFormat_RG32Float:
+    case WGPUTextureFormat_RG32Uint:
+    case WGPUTextureFormat_RG32Sint:
+    case WGPUTextureFormat_RGBA16Uint:
+    case WGPUTextureFormat_RGBA16Sint:
+    case WGPUTextureFormat_RGBA16Float:
+    case WGPUTextureFormat_RGBA32Float:
+    case WGPUTextureFormat_RGBA32Uint:
+    case WGPUTextureFormat_RGBA32Sint:
     case WGPUTextureFormat_Stencil8:
+        return std::nullopt;
     case WGPUTextureFormat_Depth16Unorm:
+        return WGPUTextureFormat_Depth16Unorm;
     case WGPUTextureFormat_Depth24Plus:
+        return WGPUTextureFormat_Depth24Plus;
     case WGPUTextureFormat_Depth24PlusStencil8:
+        return WGPUTextureFormat_Depth24Plus;
     case WGPUTextureFormat_Depth24UnormStencil8:
+        return WGPUTextureFormat_Undefined; // Return a non-nullopt value for the benefit of containsDepthAspect().
     case WGPUTextureFormat_Depth32Float:
+        return WGPUTextureFormat_Depth32Float;
     case WGPUTextureFormat_Depth32FloatStencil8:
-        return true;
+        return WGPUTextureFormat_Depth32Float;
+    case WGPUTextureFormat_BC1RGBAUnorm:
+    case WGPUTextureFormat_BC1RGBAUnormSrgb:
+    case WGPUTextureFormat_BC2RGBAUnorm:
+    case WGPUTextureFormat_BC2RGBAUnormSrgb:
+    case WGPUTextureFormat_BC3RGBAUnorm:
+    case WGPUTextureFormat_BC3RGBAUnormSrgb:
+    case WGPUTextureFormat_BC4RUnorm:
+    case WGPUTextureFormat_BC4RSnorm:
+    case WGPUTextureFormat_BC5RGUnorm:
+    case WGPUTextureFormat_BC5RGSnorm:
+    case WGPUTextureFormat_BC6HRGBUfloat:
+    case WGPUTextureFormat_BC6HRGBFloat:
+    case WGPUTextureFormat_BC7RGBAUnorm:
+    case WGPUTextureFormat_BC7RGBAUnormSrgb:
+    case WGPUTextureFormat_ETC2RGB8Unorm:
+    case WGPUTextureFormat_ETC2RGB8UnormSrgb:
+    case WGPUTextureFormat_ETC2RGB8A1Unorm:
+    case WGPUTextureFormat_ETC2RGB8A1UnormSrgb:
+    case WGPUTextureFormat_ETC2RGBA8Unorm:
+    case WGPUTextureFormat_ETC2RGBA8UnormSrgb:
+    case WGPUTextureFormat_EACR11Unorm:
+    case WGPUTextureFormat_EACR11Snorm:
+    case WGPUTextureFormat_EACRG11Unorm:
+    case WGPUTextureFormat_EACRG11Snorm:
+    case WGPUTextureFormat_ASTC4x4Unorm:
+    case WGPUTextureFormat_ASTC4x4UnormSrgb:
+    case WGPUTextureFormat_ASTC5x4Unorm:
+    case WGPUTextureFormat_ASTC5x4UnormSrgb:
+    case WGPUTextureFormat_ASTC5x5Unorm:
+    case WGPUTextureFormat_ASTC5x5UnormSrgb:
+    case WGPUTextureFormat_ASTC6x5Unorm:
+    case WGPUTextureFormat_ASTC6x5UnormSrgb:
+    case WGPUTextureFormat_ASTC6x6Unorm:
+    case WGPUTextureFormat_ASTC6x6UnormSrgb:
+    case WGPUTextureFormat_ASTC8x5Unorm:
+    case WGPUTextureFormat_ASTC8x5UnormSrgb:
+    case WGPUTextureFormat_ASTC8x6Unorm:
+    case WGPUTextureFormat_ASTC8x6UnormSrgb:
+    case WGPUTextureFormat_ASTC8x8Unorm:
+    case WGPUTextureFormat_ASTC8x8UnormSrgb:
+    case WGPUTextureFormat_ASTC10x5Unorm:
+    case WGPUTextureFormat_ASTC10x5UnormSrgb:
+    case WGPUTextureFormat_ASTC10x6Unorm:
+    case WGPUTextureFormat_ASTC10x6UnormSrgb:
+    case WGPUTextureFormat_ASTC10x8Unorm:
+    case WGPUTextureFormat_ASTC10x8UnormSrgb:
+    case WGPUTextureFormat_ASTC10x10Unorm:
+    case WGPUTextureFormat_ASTC10x10UnormSrgb:
+    case WGPUTextureFormat_ASTC12x10Unorm:
+    case WGPUTextureFormat_ASTC12x10UnormSrgb:
+    case WGPUTextureFormat_ASTC12x12Unorm:
+    case WGPUTextureFormat_ASTC12x12UnormSrgb:
+        return std::nullopt;
     case WGPUTextureFormat_Undefined:
+    case WGPUTextureFormat_Force32:
+        ASSERT_NOT_REACHED();
+        return std::nullopt;
+    }
+}
+
+static std::optional<WGPUTextureFormat> stencilSpecificFormat(WGPUTextureFormat textureFormat)
+{
+    // https://gpuweb.github.io/gpuweb/#aspect-specific-format
+
+    switch (textureFormat) {
     case WGPUTextureFormat_R8Unorm:
     case WGPUTextureFormat_R8Snorm:
     case WGPUTextureFormat_R8Uint:
@@ -297,6 +403,20 @@
     case WGPUTextureFormat_RGBA32Float:
     case WGPUTextureFormat_RGBA32Uint:
     case WGPUTextureFormat_RGBA32Sint:
+        return std::nullopt;
+    // Depth-stencil formats:
+    case WGPUTextureFormat_Stencil8:
+        return WGPUTextureFormat_Stencil8;
+    case WGPUTextureFormat_Depth16Unorm:
+    case WGPUTextureFormat_Depth24Plus:
+        return std::nullopt;
+    case WGPUTextureFormat_Depth24PlusStencil8:
+    case WGPUTextureFormat_Depth24UnormStencil8:
+        return WGPUTextureFormat_Stencil8;
+    case WGPUTextureFormat_Depth32Float:
+        return std::nullopt;
+    case WGPUTextureFormat_Depth32FloatStencil8:
+        return WGPUTextureFormat_Stencil8;
     case WGPUTextureFormat_BC1RGBAUnorm:
     case WGPUTextureFormat_BC1RGBAUnormSrgb:
     case WGPUTextureFormat_BC2RGBAUnorm:
@@ -349,13 +469,33 @@
     case WGPUTextureFormat_ASTC12x10UnormSrgb:
     case WGPUTextureFormat_ASTC12x12Unorm:
     case WGPUTextureFormat_ASTC12x12UnormSrgb:
+        return std::nullopt;
+    case WGPUTextureFormat_Undefined:
     case WGPUTextureFormat_Force32:
-        return false;
+        ASSERT_NOT_REACHED();
+        return std::nullopt;
     }
 }
 
-static uint32_t texelBlockWidth(WGPUTextureFormat format)
+bool Texture::containsDepthAspect(WGPUTextureFormat textureFormat)
 {
+    return depthSpecificFormat(textureFormat).has_value();
+}
+
+bool Texture::containsStencilAspect(WGPUTextureFormat textureFormat)
+{
+    return stencilSpecificFormat(textureFormat).has_value();
+}
+
+bool Texture::isDepthOrStencilFormat(WGPUTextureFormat format)
+{
+    // https://gpuweb.github.io/gpuweb/#depth-formats
+    // "A depth-or-stencil format is any format with depth and/or stencil aspects."
+    return containsDepthAspect(format) || containsStencilAspect(format);
+}
+
+uint32_t Texture::texelBlockWidth(WGPUTextureFormat format)
+{
     // https://gpuweb.github.io/gpuweb/#texel-block-width
     switch (format) {
     case WGPUTextureFormat_BC1RGBAUnorm:
@@ -468,7 +608,7 @@
     }
 }
 
-static uint32_t texelBlockHeight(WGPUTextureFormat format)
+uint32_t Texture::texelBlockHeight(WGPUTextureFormat format)
 {
     // https://gpuweb.github.io/gpuweb/#texel-block-height
     switch (format) {
@@ -978,7 +1118,7 @@
             return false;
 
         // "descriptor.format must not be a compressed format or depth-or-stencil format."
-        if (isCompressedFormat(descriptor.format) || isDepthOrStencilFormat(descriptor.format))
+        if (isCompressedFormat(descriptor.format) || Texture::isDepthOrStencilFormat(descriptor.format))
             return false;
         break;
     case WGPUTextureDimension_2D:
@@ -1000,7 +1140,7 @@
             return false;
 
         // "descriptor.format must not be a compressed format or depth-or-stencil format."
-        if (isCompressedFormat(descriptor.format) || isDepthOrStencilFormat(descriptor.format))
+        if (isCompressedFormat(descriptor.format) || Texture::isDepthOrStencilFormat(descriptor.format))
             return false;
         break;
     case WGPUTextureDimension_Force32:
@@ -1008,11 +1148,11 @@
     }
 
     // "descriptor.size.width must be multiple of texel block width."
-    if (descriptor.size.width % texelBlockWidth(descriptor.format))
+    if (descriptor.size.width % Texture::texelBlockWidth(descriptor.format))
         return false;
 
     // "descriptor.size.height must be multiple of texel block height."
-    if (descriptor.size.height % texelBlockHeight(descriptor.format))
+    if (descriptor.size.height % Texture::texelBlockHeight(descriptor.format))
         return false;
 
     // "If descriptor.sampleCount > 1:"
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to