- Revision
- 292204
- Author
- [email protected]
- Date
- 2022-03-31 22:23:09 -0700 (Thu, 31 Mar 2022)
Log Message
[WebGPU] There's no need to sprinkle std::optionals everywhere just for _Force32 enum values
https://bugs.webkit.org/show_bug.cgi?id=238434
For ABI compatibility, the shared header uses this pattern:
enum Foo {
Foo_AValue = 1,
Foo_AnotherValue = 2,
Foo_SomeOtherValue = 3,
Foo_Force32 = 0x7FFFFFFF
};
This is so that more values can be added to the enum without making it wider.
However, this means that if you want to switch over the values of Foo, you have to have
a dummy _Force32 case. These cases will never actually occur, and we have ASSERTs() for
them.
Originally, I made some functions return a std::optional<> so that there was some "empty"
value that could be returned in these case statements. That means that every caller of
any function that switches over any enum has to check the return value for nullopt. This
is pretty yucky.
And, indeed, it's all for nothing - the client calling into WebGPU can happily cast any
aribtrary integer to a Foo can call our functions, so the cases for the _Force32 values
should be no different. Therefore, we can just say "in order to call WebGPU functions,
it's illegal to pass in the _Force32 values (just as it would be illegal to pass in
unassigned values)." This means we can clean up the code a bit, and remove a bunch of
nullopt checks.
Reviewed by Dean Jackson.
* WebGPU/BindGroupLayout.mm:
(WebGPU::createArgumentDescriptor):
* WebGPU/Buffer.mm:
(WebGPU::Buffer::mapAsync):
* WebGPU/CommandEncoder.mm:
(WebGPU::CommandEncoder::copyBufferToTexture):
(WebGPU::CommandEncoder::copyTextureToBuffer):
* WebGPU/Instance.mm:
(WebGPU::sortedDevices):
* WebGPU/Queue.mm:
(WebGPU::Queue::writeTexture):
* WebGPU/Sampler.mm:
(WebGPU::addressMode):
(WebGPU::minMagFilter):
(WebGPU::mipFilter):
(WebGPU::compareFunction):
(WebGPU::Device::createSampler):
* WebGPU/Texture.h:
* WebGPU/Texture.mm:
(WebGPU::featureRequirementForFormat):
(WebGPU::isCompressedFormat):
(WebGPU::stencilSpecificFormat):
(WebGPU::Texture::texelBlockWidth):
(WebGPU::Texture::texelBlockHeight):
(WebGPU::isRenderableFormat):
(WebGPU::supportsMultisampling):
(WebGPU::maximumMiplevelCount):
(WebGPU::hasStorageBindingCapability):
(WebGPU::Device::validateCreateTexture):
(WebGPU::pixelFormat):
(WebGPU::depthOnlyAspectMetalFormat):
(WebGPU::stencilOnlyAspectMetalFormat):
(WebGPU::Device::createTexture):
(WebGPU::Texture::resolveTextureViewDescriptorDefaults const):
(WebGPU::Texture::validateCreateView const):
(WebGPU::Texture::createView):
(WebGPU::Texture::refersToSingleAspect):
Modified Paths
Diff
Modified: trunk/Source/WebGPU/ChangeLog (292203 => 292204)
--- trunk/Source/WebGPU/ChangeLog 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/ChangeLog 2022-04-01 05:23:09 UTC (rev 292204)
@@ -1,5 +1,77 @@
2022-03-31 Myles C. Maxfield <[email protected]>
+ [WebGPU] There's no need to sprinkle std::optionals everywhere just for _Force32 enum values
+ https://bugs.webkit.org/show_bug.cgi?id=238434
+
+ For ABI compatibility, the shared header uses this pattern:
+
+ enum Foo {
+ Foo_AValue = 1,
+ Foo_AnotherValue = 2,
+ Foo_SomeOtherValue = 3,
+ Foo_Force32 = 0x7FFFFFFF
+ };
+
+ This is so that more values can be added to the enum without making it wider.
+
+ However, this means that if you want to switch over the values of Foo, you have to have
+ a dummy _Force32 case. These cases will never actually occur, and we have ASSERTs() for
+ them.
+
+ Originally, I made some functions return a std::optional<> so that there was some "empty"
+ value that could be returned in these case statements. That means that every caller of
+ any function that switches over any enum has to check the return value for nullopt. This
+ is pretty yucky.
+
+ And, indeed, it's all for nothing - the client calling into WebGPU can happily cast any
+ aribtrary integer to a Foo can call our functions, so the cases for the _Force32 values
+ should be no different. Therefore, we can just say "in order to call WebGPU functions,
+ it's illegal to pass in the _Force32 values (just as it would be illegal to pass in
+ unassigned values)." This means we can clean up the code a bit, and remove a bunch of
+ nullopt checks.
+
+ Reviewed by Dean Jackson.
+
+ * WebGPU/BindGroupLayout.mm:
+ (WebGPU::createArgumentDescriptor):
+ * WebGPU/Buffer.mm:
+ (WebGPU::Buffer::mapAsync):
+ * WebGPU/CommandEncoder.mm:
+ (WebGPU::CommandEncoder::copyBufferToTexture):
+ (WebGPU::CommandEncoder::copyTextureToBuffer):
+ * WebGPU/Instance.mm:
+ (WebGPU::sortedDevices):
+ * WebGPU/Queue.mm:
+ (WebGPU::Queue::writeTexture):
+ * WebGPU/Sampler.mm:
+ (WebGPU::addressMode):
+ (WebGPU::minMagFilter):
+ (WebGPU::mipFilter):
+ (WebGPU::compareFunction):
+ (WebGPU::Device::createSampler):
+ * WebGPU/Texture.h:
+ * WebGPU/Texture.mm:
+ (WebGPU::featureRequirementForFormat):
+ (WebGPU::isCompressedFormat):
+ (WebGPU::stencilSpecificFormat):
+ (WebGPU::Texture::texelBlockWidth):
+ (WebGPU::Texture::texelBlockHeight):
+ (WebGPU::isRenderableFormat):
+ (WebGPU::supportsMultisampling):
+ (WebGPU::maximumMiplevelCount):
+ (WebGPU::hasStorageBindingCapability):
+ (WebGPU::Device::validateCreateTexture):
+ (WebGPU::pixelFormat):
+ (WebGPU::depthOnlyAspectMetalFormat):
+ (WebGPU::stencilOnlyAspectMetalFormat):
+ (WebGPU::Device::createTexture):
+ (WebGPU::Texture::resolveTextureViewDescriptorDefaults const):
+ (WebGPU::Texture::validateCreateView const):
+ (WebGPU::Texture::createView):
+ (WebGPU::Texture::refersToSingleAspect):
+
+2022-03-31 Myles C. Maxfield <[email protected]>
+
[WebGPU] etc2-rgba8unorm and etc2-rgba8unorm-srgb are not handled
https://bugs.webkit.org/show_bug.cgi?id=238435
Modified: trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm 2022-04-01 05:23:09 UTC (rev 292204)
@@ -55,6 +55,7 @@
break;
case WGPUBufferBindingType_Undefined:
case WGPUBufferBindingType_Force32:
+ ASSERT_NOT_REACHED();
return nil;
}
return descriptor;
Modified: trunk/Source/WebGPU/WebGPU/Buffer.mm (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-01 05:23:09 UTC (rev 292204)
@@ -341,6 +341,7 @@
callback(WGPUBufferMapAsyncStatus_DeviceLost);
return;
case WGPUQueueWorkDoneStatus_Force32:
+ ASSERT_NOT_REACHED();
callback(WGPUBufferMapAsyncStatus_Error);
return;
}
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.mm (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-01 05:23:09 UTC (rev 292204)
@@ -291,6 +291,7 @@
options = MTLBlitOptionDepthFromDepthStencil;
break;
case WGPUTextureAspect_Force32:
+ ASSERT_NOT_REACHED();
return;
}
@@ -365,6 +366,7 @@
break;
}
case WGPUTextureDimension_Force32:
+ ASSERT_NOT_REACHED();
return;
}
}
@@ -474,6 +476,7 @@
options = MTLBlitOptionDepthFromDepthStencil;
break;
case WGPUTextureAspect_Force32:
+ ASSERT_NOT_REACHED();
return;
}
@@ -548,6 +551,7 @@
break;
}
case WGPUTextureDimension_Force32:
+ ASSERT_NOT_REACHED();
return;
}
}
Modified: trunk/Source/WebGPU/WebGPU/Instance.mm (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/Instance.mm 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/Instance.mm 2022-04-01 05:23:09 UTC (rev 292204)
@@ -123,6 +123,7 @@
return devices;
#endif
case WGPUPowerPreference_Force32:
+ ASSERT_NOT_REACHED();
return nil;
}
}
Modified: trunk/Source/WebGPU/WebGPU/Queue.mm (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-01 05:23:09 UTC (rev 292204)
@@ -335,6 +335,7 @@
options = MTLBlitOptionDepthFromDepthStencil;
break;
case WGPUTextureAspect_Force32:
+ ASSERT_NOT_REACHED();
return;
}
@@ -484,6 +485,7 @@
break;
}
case WGPUTextureDimension_Force32:
+ ASSERT_NOT_REACHED();
return;
}
}
Modified: trunk/Source/WebGPU/WebGPU/Sampler.mm (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-01 05:23:09 UTC (rev 292204)
@@ -62,7 +62,7 @@
return true;
}
-static std::optional<MTLSamplerAddressMode> addressMode(WGPUAddressMode addressMode)
+static MTLSamplerAddressMode addressMode(WGPUAddressMode addressMode)
{
switch (addressMode) {
case WGPUAddressMode_Repeat:
@@ -72,11 +72,12 @@
case WGPUAddressMode_ClampToEdge:
return MTLSamplerAddressModeClampToEdge;
case WGPUAddressMode_Force32:
- return std::nullopt;
+ ASSERT_NOT_REACHED();
+ return MTLSamplerAddressModeClampToEdge;
}
}
-static std::optional<MTLSamplerMinMagFilter> minMagFilter(WGPUFilterMode filterMode)
+static MTLSamplerMinMagFilter minMagFilter(WGPUFilterMode filterMode)
{
switch (filterMode) {
case WGPUFilterMode_Nearest:
@@ -84,11 +85,12 @@
case WGPUFilterMode_Linear:
return MTLSamplerMinMagFilterLinear;
case WGPUFilterMode_Force32:
- return std::nullopt;
+ ASSERT_NOT_REACHED();
+ return MTLSamplerMinMagFilterNearest;
}
}
-static std::optional<MTLSamplerMipFilter> mipFilter(WGPUFilterMode filterMode)
+static MTLSamplerMipFilter mipFilter(WGPUFilterMode filterMode)
{
switch (filterMode) {
case WGPUFilterMode_Nearest:
@@ -96,15 +98,14 @@
case WGPUFilterMode_Linear:
return MTLSamplerMipFilterLinear;
case WGPUFilterMode_Force32:
- return std::nullopt;
+ ASSERT_NOT_REACHED();
+ return MTLSamplerMipFilterNearest;
}
}
-static std::optional<MTLCompareFunction> compareFunction(WGPUCompareFunction compareFunction)
+static MTLCompareFunction compareFunction(WGPUCompareFunction compareFunction)
{
switch (compareFunction) {
- case WGPUCompareFunction_Undefined:
- return std::nullopt;
case WGPUCompareFunction_Never:
return MTLCompareFunctionNever;
case WGPUCompareFunction_Less:
@@ -121,8 +122,10 @@
return MTLCompareFunctionNotEqual;
case WGPUCompareFunction_Always:
return MTLCompareFunctionAlways;
+ case WGPUCompareFunction_Undefined:
case WGPUCompareFunction_Force32:
- return std::nullopt;
+ ASSERT_NOT_REACHED();
+ return MTLCompareFunctionAlways;
}
}
@@ -144,45 +147,16 @@
MTLSamplerDescriptor *samplerDescriptor = [MTLSamplerDescriptor new];
- if (auto addressMode = WebGPU::addressMode(descriptor.addressModeU))
- samplerDescriptor.rAddressMode = addressMode.value();
- else
- return nullptr;
-
- if (auto addressMode = WebGPU::addressMode(descriptor.addressModeV))
- samplerDescriptor.sAddressMode = addressMode.value();
- else
- return nullptr;
-
- if (auto addressMode = WebGPU::addressMode(descriptor.addressModeW))
- samplerDescriptor.tAddressMode = addressMode.value();
- else
- return nullptr;
-
- if (auto minMagFilter = WebGPU::minMagFilter(descriptor.magFilter))
- samplerDescriptor.magFilter = minMagFilter.value();
- else
- return nullptr;
-
- if (auto minMagFilter = WebGPU::minMagFilter(descriptor.minFilter))
- samplerDescriptor.minFilter = minMagFilter.value();
- else
- return nullptr;
-
- if (auto mipFilter = WebGPU::mipFilter(descriptor.mipmapFilter))
- samplerDescriptor.mipFilter = mipFilter.value();
- else
- return nullptr;
-
+ samplerDescriptor.rAddressMode = addressMode(descriptor.addressModeU);
+ samplerDescriptor.sAddressMode = addressMode(descriptor.addressModeV);
+ samplerDescriptor.tAddressMode = addressMode(descriptor.addressModeW);
+ samplerDescriptor.magFilter = minMagFilter(descriptor.magFilter);
+ samplerDescriptor.minFilter = minMagFilter(descriptor.minFilter);
+ samplerDescriptor.mipFilter = mipFilter(descriptor.mipmapFilter);
samplerDescriptor.lodMinClamp = descriptor.lodMinClamp;
-
samplerDescriptor.lodMaxClamp = descriptor.lodMaxClamp;
+ samplerDescriptor.compareFunction = compareFunction(descriptor.compare);
- if (auto compareFunction = WebGPU::compareFunction(descriptor.compare))
- samplerDescriptor.compareFunction = compareFunction.value();
- else
- return nullptr;
-
// "The used value of maxAnisotropy will be clamped to the maximum value that the platform supports."
// https://developer.apple.com/documentation/metal/mtlsamplerdescriptor/1516164-maxanisotropy?language=objc
// "Values must be between 1 and 16, inclusive."
Modified: trunk/Source/WebGPU/WebGPU/Texture.h (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-01 05:23:09 UTC (rev 292204)
@@ -77,7 +77,7 @@
private:
Texture(id<MTLTexture>, const WGPUTextureDescriptor&, Device&);
- std::optional<WGPUTextureViewDescriptor> resolveTextureViewDescriptorDefaults(const WGPUTextureViewDescriptor&) const;
+ WGPUTextureViewDescriptor resolveTextureViewDescriptorDefaults(const WGPUTextureViewDescriptor&) const;
uint32_t arrayLayerCount() const;
bool validateCreateView(const WGPUTextureViewDescriptor&) const;
Modified: trunk/Source/WebGPU/WebGPU/Texture.mm (292203 => 292204)
--- trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-01 05:09:41 UTC (rev 292203)
+++ trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-01 05:23:09 UTC (rev 292204)
@@ -95,7 +95,6 @@
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
return WGPUFeatureName_TextureCompressionASTC;
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -137,7 +136,10 @@
case WGPUTextureFormat_Depth24Plus:
case WGPUTextureFormat_Depth24PlusStencil8:
case WGPUTextureFormat_Depth32Float:
+ return std::nullopt;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return std::nullopt;
}
}
@@ -200,7 +202,6 @@
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
return true;
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -244,7 +245,10 @@
case WGPUTextureFormat_Depth24UnormStencil8:
case WGPUTextureFormat_Depth32Float:
case WGPUTextureFormat_Depth32FloatStencil8:
+ return false;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return false;
}
}
@@ -406,7 +410,6 @@
case WGPUTextureFormat_RGBA32Uint:
case WGPUTextureFormat_RGBA32Sint:
return std::nullopt;
- // Depth-stencil formats:
case WGPUTextureFormat_Stencil8:
return WGPUTextureFormat_Stencil8;
case WGPUTextureFormat_Depth16Unorm:
@@ -561,7 +564,6 @@
case WGPUTextureFormat_ASTC12x12UnormSrgb:
return 12;
// "For pixel-based GPUTextureFormats, the texel block width and texel block height are always 1."
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -605,8 +607,11 @@
case WGPUTextureFormat_Depth24UnormStencil8:
case WGPUTextureFormat_Depth32Float:
case WGPUTextureFormat_Depth32FloatStencil8:
+ return 1;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
- return 1;
+ ASSERT_NOT_REACHED();
+ return 0;
}
}
@@ -680,7 +685,6 @@
case WGPUTextureFormat_ASTC12x12UnormSrgb:
return 12;
// "For pixel-based GPUTextureFormats, the texel block width and texel block height are always 1."
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -724,8 +728,11 @@
case WGPUTextureFormat_Depth24UnormStencil8:
case WGPUTextureFormat_Depth32Float:
case WGPUTextureFormat_Depth32FloatStencil8:
+ return 1;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
- return 1;
+ ASSERT_NOT_REACHED();
+ return 0;
}
}
@@ -775,7 +782,6 @@
case WGPUTextureFormat_Depth32Float:
case WGPUTextureFormat_Depth32FloatStencil8:
return true;
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_RG8Snorm:
case WGPUTextureFormat_RGBA8Snorm:
@@ -832,7 +838,10 @@
case WGPUTextureFormat_ASTC12x10UnormSrgb:
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
+ return false;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return false;
}
}
@@ -879,7 +888,6 @@
case WGPUTextureFormat_Depth32Float:
case WGPUTextureFormat_Depth32FloatStencil8:
return true;
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R32Uint:
case WGPUTextureFormat_R32Sint:
case WGPUTextureFormat_RG32Float:
@@ -940,7 +948,10 @@
case WGPUTextureFormat_ASTC12x10UnormSrgb:
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
+ return false;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return false;
}
}
@@ -966,6 +977,7 @@
m = std::max(std::max(size.width, size.height), size.depthOrArrayLayers);
break;
case WGPUTextureDimension_Force32:
+ ASSERT_NOT_REACHED();
return 0;
}
@@ -997,7 +1009,6 @@
case WGPUTextureFormat_RGBA32Uint:
case WGPUTextureFormat_RGBA32Sint:
return true;
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -1077,7 +1088,10 @@
case WGPUTextureFormat_ASTC12x10UnormSrgb:
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
+ return false;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return false;
}
}
@@ -1146,6 +1160,7 @@
return false;
break;
case WGPUTextureDimension_Force32:
+ ASSERT_NOT_REACHED();
return false;
}
@@ -1436,6 +1451,7 @@
#endif
case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return MTLPixelFormatInvalid;
}
}
@@ -1601,7 +1617,6 @@
static std::optional<MTLPixelFormat> depthOnlyAspectMetalFormat(WGPUTextureFormat textureFormat)
{
switch (textureFormat) {
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -1703,7 +1718,10 @@
case WGPUTextureFormat_ASTC12x10UnormSrgb:
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
+ return std::nullopt;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return std::nullopt;
}
}
@@ -1711,7 +1729,6 @@
static std::optional<MTLPixelFormat> stencilOnlyAspectMetalFormat(WGPUTextureFormat textureFormat)
{
switch (textureFormat) {
- case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_R8Unorm:
case WGPUTextureFormat_R8Snorm:
case WGPUTextureFormat_R8Uint:
@@ -1820,7 +1837,10 @@
case WGPUTextureFormat_ASTC12x10UnormSrgb:
case WGPUTextureFormat_ASTC12x12Unorm:
case WGPUTextureFormat_ASTC12x12UnormSrgb:
+ return std::nullopt;
+ case WGPUTextureFormat_Undefined:
case WGPUTextureFormat_Force32:
+ ASSERT_NOT_REACHED();
return std::nullopt;
}
}
@@ -1897,6 +1917,7 @@
textureDescriptor.textureType = MTLTextureType3D;
break;
case WGPUTextureDimension_Force32:
+ ASSERT_NOT_REACHED();
return nullptr;
}
@@ -1933,7 +1954,7 @@
Texture::~Texture() = default;
-std::optional<WGPUTextureViewDescriptor> Texture::resolveTextureViewDescriptorDefaults(const WGPUTextureViewDescriptor& descriptor) const
+WGPUTextureViewDescriptor Texture::resolveTextureViewDescriptorDefaults(const WGPUTextureViewDescriptor& descriptor) const
{
// https://gpuweb.github.io/gpuweb/#abstract-opdef-resolving-gputextureviewdescriptor-defaults
@@ -1971,7 +1992,7 @@
break;
case WGPUTextureDimension_Force32:
ASSERT_NOT_REACHED();
- return std::nullopt;
+ return resolved;
}
}
@@ -1981,7 +2002,7 @@
switch (resolved.dimension) {
case WGPUTextureViewDimension_Undefined:
ASSERT_NOT_REACHED();
- return std::nullopt;
+ return resolved;
case WGPUTextureViewDimension_1D:
case WGPUTextureViewDimension_2D:
case WGPUTextureViewDimension_3D:
@@ -2000,7 +2021,7 @@
break;
case WGPUTextureViewDimension_Force32:
ASSERT_NOT_REACHED();
- return std::nullopt;
+ return resolved;
}
}
@@ -2048,6 +2069,7 @@
return false;
break;
case WGPUTextureAspect_Force32:
+ ASSERT_NOT_REACHED();
return false;
}
@@ -2172,11 +2194,9 @@
// "Set descriptor to the result of resolving GPUTextureViewDescriptor defaults with descriptor."
auto descriptor = resolveTextureViewDescriptorDefaults(inputDescriptor);
- if (!descriptor)
- return nullptr;
// "If any of the following requirements are unmet:"
- if (!validateCreateView(*descriptor)) {
+ if (!validateCreateView(descriptor)) {
// "Generate a validation error."
m_device->generateAValidationError("Validation failure."_s);
@@ -2185,18 +2205,19 @@
}
std::optional<MTLPixelFormat> pixelFormat;
- if (isDepthOrStencilFormat(descriptor->format)) {
- switch (descriptor->aspect) {
+ if (isDepthOrStencilFormat(descriptor.format)) {
+ switch (descriptor.aspect) {
case WGPUTextureAspect_All:
- pixelFormat = WebGPU::pixelFormat(descriptor->format);
+ pixelFormat = WebGPU::pixelFormat(descriptor.format);
break;
case WGPUTextureAspect_StencilOnly:
- pixelFormat = stencilOnlyAspectMetalFormat(descriptor->format);
+ pixelFormat = stencilOnlyAspectMetalFormat(descriptor.format);
break;
case WGPUTextureAspect_DepthOnly:
- pixelFormat = depthOnlyAspectMetalFormat(descriptor->format);
+ pixelFormat = depthOnlyAspectMetalFormat(descriptor.format);
break;
case WGPUTextureAspect_Force32:
+ ASSERT_NOT_REACHED();
return nullptr;
}
}
@@ -2205,12 +2226,12 @@
ASSERT(*pixelFormat != MTLPixelFormatInvalid);
MTLTextureType textureType;
- switch (descriptor->dimension) {
+ switch (descriptor.dimension) {
case WGPUTextureViewDimension_Undefined:
ASSERT_NOT_REACHED();
return nullptr;
case WGPUTextureViewDimension_1D:
- if (descriptor->arrayLayerCount == 1)
+ if (descriptor.arrayLayerCount == 1)
textureType = MTLTextureType1D;
else
textureType = MTLTextureType1DArray;
@@ -2241,18 +2262,19 @@
textureType = MTLTextureType3D;
break;
case WGPUTextureViewDimension_Force32:
+ ASSERT_NOT_REACHED();
return nullptr;
}
- auto levels = NSMakeRange(descriptor->baseMipLevel, descriptor->mipLevelCount);
+ auto levels = NSMakeRange(descriptor.baseMipLevel, descriptor.mipLevelCount);
- auto slices = NSMakeRange(descriptor->baseArrayLayer, descriptor->arrayLayerCount);
+ auto slices = NSMakeRange(descriptor.baseArrayLayer, descriptor.arrayLayerCount);
id<MTLTexture> texture = [m_texture newTextureViewWithPixelFormat:*pixelFormat textureType:textureType levels:levels slices:slices];
if (!texture)
return nullptr;
- texture.label = fromAPI(descriptor->label);
+ texture.label = fromAPI(descriptor.label);
// "Let view be a new GPUTextureView object."
// "Set view.[[texture]] to this."
@@ -2263,11 +2285,11 @@
if (m_descriptor.usage & WGPUTextureUsage_RenderAttachment) {
// "Let renderExtent be compute render extent(this.[[descriptor]].size, descriptor.baseMipLevel)."
// "Set view.[[renderExtent]] to renderExtent."
- renderExtent = computeRenderExtent(m_descriptor.size, descriptor->baseMipLevel);
+ renderExtent = computeRenderExtent(m_descriptor.size, descriptor.baseMipLevel);
}
// "Return view."
- return TextureView::create(texture, *descriptor, renderExtent);
+ return TextureView::create(texture, descriptor, renderExtent);
}
void Texture::destroy()
@@ -2416,6 +2438,7 @@
return false;
break;
case WGPUTextureAspect_Force32:
+ ASSERT_NOT_REACHED();
return false;
}