From b0abeb545232536f7ccf1ce4c2052b4de08b80da Mon Sep 17 00:00:00 2001 From: fanciful-marmot <3170456+fanciful-marmot@users.noreply.github.com> Date: Wed, 3 Dec 2025 08:06:24 -0800 Subject: [PATCH 1/2] Add support for texture-formats features in capture and Dawn playback --- capture/scripts/mainContent.js | 10 +++++++++- code_generation/code_generation.py | 2 +- code_generation/enum_types.py | 14 +++++++++++++- docs/LIMITATIONS.md | 4 +++- replay/Adapter.cpp | 2 ++ replay/Device.cpp | 4 ++++ replay/WebGPU.hpp | 6 ++++++ 7 files changed, 38 insertions(+), 4 deletions(-) diff --git a/capture/scripts/mainContent.js b/capture/scripts/mainContent.js index 873f1d0..03560e2 100644 --- a/capture/scripts/mainContent.js +++ b/capture/scripts/mainContent.js @@ -251,6 +251,8 @@ function __WebGPUReconstruct_get_bytes_per_block(format) { return 1; // 16-bit formats + case "r16unorm": + case "r16snorm": case "r16uint": case "r16sint": case "r16float": @@ -265,6 +267,8 @@ function __WebGPUReconstruct_get_bytes_per_block(format) { case "r32uint": case "r32sint": case "r32float": + case "rg16unorm": + case "rg16snorm": case "rg16uint": case "rg16sint": case "rg16float": @@ -285,6 +289,8 @@ function __WebGPUReconstruct_get_bytes_per_block(format) { case "rg32uint": case "rg32sint": case "rg32float": + case "rgba16unorm": + case "rgba16snorm": case "rgba16uint": case "rgba16sint": case "rgba16float": @@ -374,7 +380,7 @@ function __WebGPUReconstruct_get_bytes_per_block(format) { } // Features supported by WebGPUReconstruct. We will pretend the adapter doesn't support any other features. -// TODO: dual-source-blending, texture-formats-tier1, texture-formats-tier2, texture-component-swizzle +// TODO: dual-source-blending, texture-component-swizzle const __WebGPUReconstruct_supportedFeatures = new Set([ "core-features-and-limits", "depth-clip-control", @@ -394,6 +400,8 @@ const __WebGPUReconstruct_supportedFeatures = new Set([ "clip-distances", "subgroups", "primitive-index", + "texture-formats-tier1", + "texture-formats-tier2" ]); function __WebGPUReconstruct_GPUAdapter_requestDevice(originalMethod, descriptor) { diff --git a/code_generation/code_generation.py b/code_generation/code_generation.py index 7de2f4c..9de7a90 100644 --- a/code_generation/code_generation.py +++ b/code_generation/code_generation.py @@ -5,7 +5,7 @@ version = (1, 0) # Increment the file version whenever a change is introduced. -fileVersion = 15 +fileVersion = 16 versionString = str(version[0]) + "." + str(version[1]) versionInt = version[0] * 10000 + version[1] diff --git a/code_generation/enum_types.py b/code_generation/enum_types.py index 509802f..c61a69e 100644 --- a/code_generation/enum_types.py +++ b/code_generation/enum_types.py @@ -54,6 +54,10 @@ def cleanup(self, name): ["r8snorm", "WGPUTextureFormat_R8Snorm"], ["r8uint", "WGPUTextureFormat_R8Uint"], ["r8sint", "WGPUTextureFormat_R8Sint"], +#if WEBGPU_BACKEND_DAWN + ["r16unorm", "WGPUTextureFormat_R16Unorm"], + ["r16snorm", "WGPUTextureFormat_R16Snorm"], +#endif ["r16uint", "WGPUTextureFormat_R16Uint"], ["r16sint", "WGPUTextureFormat_R16Sint"], ["r16float", "WGPUTextureFormat_R16Float"], @@ -64,6 +68,10 @@ def cleanup(self, name): ["r32uint", "WGPUTextureFormat_R32Uint"], ["r32sint", "WGPUTextureFormat_R32Sint"], ["r32float", "WGPUTextureFormat_R32Float"], +#if WEBGPU_BACKEND_DAWN + ["rg16unorm", "WGPUTextureFormat_RG16Unorm"], + ["rg16snorm", "WGPUTextureFormat_RG16Snorm"], +#endif ["rg16uint", "WGPUTextureFormat_RG16Uint"], ["rg16sint", "WGPUTextureFormat_RG16Sint"], ["rg16float", "WGPUTextureFormat_RG16Float"], @@ -81,6 +89,10 @@ def cleanup(self, name): ["rg32uint", "WGPUTextureFormat_RG32Uint"], ["rg32sint", "WGPUTextureFormat_RG32Sint"], ["rg32float", "WGPUTextureFormat_RG32Float"], +#if WEBGPU_BACKEND_DAWN + ["rgba16unorm", "WGPUTextureFormat_RGBA16Unorm"], + ["rgba16snorm", "WGPUTextureFormat_RGBA16Snorm"], +#endif ["rgba16uint", "WGPUTextureFormat_RGBA16Uint"], ["rgba16sint", "WGPUTextureFormat_RGBA16Sint"], ["rgba16float", "WGPUTextureFormat_RGBA16Float"], @@ -337,4 +349,4 @@ def cleanup(self, name): GPUQueryType = EnumType("GPUQueryType", [ ["occlusion", "WGPUQueryType_Occlusion"], ["timestamp", "WGPUQueryType_Timestamp"] -]) \ No newline at end of file +]) diff --git a/docs/LIMITATIONS.md b/docs/LIMITATIONS.md index 411db23..a8161a9 100644 --- a/docs/LIMITATIONS.md +++ b/docs/LIMITATIONS.md @@ -9,9 +9,11 @@ Since workers run in a separate context, WebGPUReconstruct is not able to captur ## Unsupported features The following optional WebGPU features are not supported: - `dual-source-blending` +- `texture-component-swizzle` + +The following optional WebGPU features are not supported during WGPU playback: - `texture-formats-tier1` - `texture-formats-tier2` -- `texture-component-swizzle` During capture, `GPUAdapter` will behave as if these features are not supported, even if the device supports them. diff --git a/replay/Adapter.cpp b/replay/Adapter.cpp index 2ab9ff4..46b3ee2 100644 --- a/replay/Adapter.cpp +++ b/replay/Adapter.cpp @@ -132,6 +132,8 @@ void Adapter::RequestAdapter(WGPUBackendType backendType) { std::vector toggles; toggles.push_back("use_user_defined_labels_in_backend"); toggles.push_back("use_dxc"); + // Needed for experimental features like TextureFormatsTier1 and TextureFormatsTier2 + toggles.push_back("allow_unsafe_apis"); WGPUDawnTogglesDescriptor dawnToggles = {}; dawnToggles.chain.sType = WGPUSType_DawnTogglesDescriptor; diff --git a/replay/Device.cpp b/replay/Device.cpp index a16cb15..91759c4 100644 --- a/replay/Device.cpp +++ b/replay/Device.cpp @@ -31,6 +31,8 @@ Device::Device(Adapter& adapter) { WGPUFeatureName_ClipDistances, #if WEBGPU_BACKEND_DAWN WGPUFeatureName_Subgroups, + WGPUFeatureName_TextureFormatsTier1, + WGPUFeatureName_TextureFormatsTier2, WGPUFeatureName_PrimitiveIndex, #endif }; @@ -66,6 +68,8 @@ Device::Device(Adapter& adapter) { std::vector toggles; toggles.push_back("use_user_defined_labels_in_backend"); toggles.push_back("use_dxc"); + // Needed for experimental features like TextureFormatsTier1 and TextureFormatsTier2 + toggles.push_back("allow_unsafe_apis"); WGPUDawnTogglesDescriptor dawnToggles = {}; dawnToggles.chain.sType = WGPUSType_DawnTogglesDescriptor; diff --git a/replay/WebGPU.hpp b/replay/WebGPU.hpp index 7d2ce2b..2f18395 100644 --- a/replay/WebGPU.hpp +++ b/replay/WebGPU.hpp @@ -19,4 +19,10 @@ typedef struct { WGPUChainedStruct chain; } WGPUExternalTextureBindingLayout; #define WGPUSType_ExternalTextureBindingLayout WGPUSType_Force32 +#define WGPUTextureFormat_R16Unorm WGPUTextureFormat_Force32 +#define WGPUTextureFormat_R16Snorm WGPUTextureFormat_Force32 +#define WGPUTextureFormat_RG16Unorm WGPUTextureFormat_Force32 +#define WGPUTextureFormat_RG16Snorm WGPUTextureFormat_Force32 +#define WGPUTextureFormat_RGBA16Unorm WGPUTextureFormat_Force32 +#define WGPUTextureFormat_RGBA16Snorm WGPUTextureFormat_Force32 #endif From 5dd4bb06aee4bfaf6024a5e1889224c1b13d63b6 Mon Sep 17 00:00:00 2001 From: fanciful-marmot <3170456+fanciful-marmot@users.noreply.github.com> Date: Wed, 3 Dec 2025 12:14:30 -0800 Subject: [PATCH 2/2] Address comments --- code_generation/enum_types.py | 6 ------ docs/LIMITATIONS.md | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/code_generation/enum_types.py b/code_generation/enum_types.py index c61a69e..a3d6922 100644 --- a/code_generation/enum_types.py +++ b/code_generation/enum_types.py @@ -54,10 +54,8 @@ def cleanup(self, name): ["r8snorm", "WGPUTextureFormat_R8Snorm"], ["r8uint", "WGPUTextureFormat_R8Uint"], ["r8sint", "WGPUTextureFormat_R8Sint"], -#if WEBGPU_BACKEND_DAWN ["r16unorm", "WGPUTextureFormat_R16Unorm"], ["r16snorm", "WGPUTextureFormat_R16Snorm"], -#endif ["r16uint", "WGPUTextureFormat_R16Uint"], ["r16sint", "WGPUTextureFormat_R16Sint"], ["r16float", "WGPUTextureFormat_R16Float"], @@ -68,10 +66,8 @@ def cleanup(self, name): ["r32uint", "WGPUTextureFormat_R32Uint"], ["r32sint", "WGPUTextureFormat_R32Sint"], ["r32float", "WGPUTextureFormat_R32Float"], -#if WEBGPU_BACKEND_DAWN ["rg16unorm", "WGPUTextureFormat_RG16Unorm"], ["rg16snorm", "WGPUTextureFormat_RG16Snorm"], -#endif ["rg16uint", "WGPUTextureFormat_RG16Uint"], ["rg16sint", "WGPUTextureFormat_RG16Sint"], ["rg16float", "WGPUTextureFormat_RG16Float"], @@ -89,10 +85,8 @@ def cleanup(self, name): ["rg32uint", "WGPUTextureFormat_RG32Uint"], ["rg32sint", "WGPUTextureFormat_RG32Sint"], ["rg32float", "WGPUTextureFormat_RG32Float"], -#if WEBGPU_BACKEND_DAWN ["rgba16unorm", "WGPUTextureFormat_RGBA16Unorm"], ["rgba16snorm", "WGPUTextureFormat_RGBA16Snorm"], -#endif ["rgba16uint", "WGPUTextureFormat_RGBA16Uint"], ["rgba16sint", "WGPUTextureFormat_RGBA16Sint"], ["rgba16float", "WGPUTextureFormat_RGBA16Float"], diff --git a/docs/LIMITATIONS.md b/docs/LIMITATIONS.md index a8161a9..1a88dba 100644 --- a/docs/LIMITATIONS.md +++ b/docs/LIMITATIONS.md @@ -12,6 +12,8 @@ The following optional WebGPU features are not supported: - `texture-component-swizzle` The following optional WebGPU features are not supported during WGPU playback: +- `primitive-index` +- `subgroups` - `texture-formats-tier1` - `texture-formats-tier2`