react-native-webgpu 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/rnwgpu/api/GPUFeatures.h +114 -185
- package/cpp/rnwgpu/api/GPUQueue.cpp +39 -13
- package/cpp/rnwgpu/api/descriptors/Unions.h +13 -315
- package/cpp/webgpu/webgpu.h +86 -44
- package/cpp/webgpu/webgpu_cpp.h +556 -283
- package/cpp/webgpu/webgpu_cpp_chained_struct.h +1 -1
- package/cpp/webgpu/webgpu_cpp_print.h +91 -79
- package/cpp/webgpu/webgpu_enum_class_bitmasks.h +2 -1
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +6 -6
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/package.json +3 -3
|
@@ -8,195 +8,124 @@
|
|
|
8
8
|
|
|
9
9
|
namespace rnwgpu {
|
|
10
10
|
|
|
11
|
+
// Single source of truth for the wgpu::FeatureName <-> GPUFeatureName string
|
|
12
|
+
// mapping. Every conversion (both directions, here and in EnumMapper, see
|
|
13
|
+
// api/descriptors/Unions.h) is derived from this list so the tables cannot
|
|
14
|
+
// drift apart.
|
|
15
|
+
//
|
|
16
|
+
// The list must cover every value of wgpu::FeatureName. Dawn adds features on
|
|
17
|
+
// every milestone upgrade; FeatureNames.spec.ts diffs this list against the
|
|
18
|
+
// enum in the installed webgpu_cpp.h and fails when one is missing.
|
|
19
|
+
#define RNWGPU_FOR_EACH_FEATURE_NAME(V) \
|
|
20
|
+
V(CoreFeaturesAndLimits, "core-features-and-limits") \
|
|
21
|
+
V(DepthClipControl, "depth-clip-control") \
|
|
22
|
+
V(Depth32FloatStencil8, "depth32float-stencil8") \
|
|
23
|
+
V(TextureCompressionBC, "texture-compression-bc") \
|
|
24
|
+
V(TextureCompressionBCSliced3D, "texture-compression-bc-sliced-3d") \
|
|
25
|
+
V(TextureCompressionETC2, "texture-compression-etc2") \
|
|
26
|
+
V(TextureCompressionASTC, "texture-compression-astc") \
|
|
27
|
+
V(TextureCompressionASTCSliced3D, "texture-compression-astc-sliced-3d") \
|
|
28
|
+
V(TimestampQuery, "timestamp-query") \
|
|
29
|
+
V(IndirectFirstInstance, "indirect-first-instance") \
|
|
30
|
+
V(ShaderF16, "shader-f16") \
|
|
31
|
+
V(RG11B10UfloatRenderable, "rg11b10ufloat-renderable") \
|
|
32
|
+
V(BGRA8UnormStorage, "bgra8unorm-storage") \
|
|
33
|
+
V(Float32Filterable, "float32-filterable") \
|
|
34
|
+
V(Float32Blendable, "float32-blendable") \
|
|
35
|
+
V(ClipDistances, "clip-distances") \
|
|
36
|
+
V(DualSourceBlending, "dual-source-blending") \
|
|
37
|
+
V(Subgroups, "subgroups") \
|
|
38
|
+
V(TextureFormatsTier1, "texture-formats-tier1") \
|
|
39
|
+
V(TextureFormatsTier2, "texture-formats-tier2") \
|
|
40
|
+
V(PrimitiveIndex, "primitive-index") \
|
|
41
|
+
V(TextureComponentSwizzle, "texture-component-swizzle") \
|
|
42
|
+
V(SubgroupSizeControl, "subgroup-size-control") \
|
|
43
|
+
V(DawnInternalUsages, "dawn-internal-usages") \
|
|
44
|
+
V(DawnMultiPlanarFormats, "dawn-multi-planar-formats") \
|
|
45
|
+
V(DawnNative, "dawn-native") \
|
|
46
|
+
V(ChromiumExperimentalTimestampQueryInsidePasses, \
|
|
47
|
+
"chromium-experimental-timestamp-query-inside-passes") \
|
|
48
|
+
V(ImplicitDeviceSynchronization, "implicit-device-synchronization") \
|
|
49
|
+
V(TransientAttachments, "transient-attachments") \
|
|
50
|
+
V(MSAARenderToSingleSampled, "msaa-render-to-single-sampled") \
|
|
51
|
+
V(D3D11MultithreadProtected, "d3d11-multithread-protected") \
|
|
52
|
+
V(ANGLETextureSharing, "angle-texture-sharing") \
|
|
53
|
+
V(PixelLocalStorageCoherent, "pixel-local-storage-coherent") \
|
|
54
|
+
V(PixelLocalStorageNonCoherent, "pixel-local-storage-non-coherent") \
|
|
55
|
+
V(Unorm16TextureFormats, "unorm16-texture-formats") \
|
|
56
|
+
V(MultiPlanarFormatExtendedUsages, "multi-planar-format-extended-usages") \
|
|
57
|
+
V(MultiPlanarFormatP010, "multi-planar-format-p010") \
|
|
58
|
+
V(HostMappedPointer, "host-mapped-pointer") \
|
|
59
|
+
V(MultiPlanarRenderTargets, "multi-planar-render-targets") \
|
|
60
|
+
V(MultiPlanarFormatNv12a, "multi-planar-format-nv12a") \
|
|
61
|
+
V(FramebufferFetch, "framebuffer-fetch") \
|
|
62
|
+
V(BufferMapExtendedUsages, "buffer-map-extended-usages") \
|
|
63
|
+
V(AdapterPropertiesMemoryHeaps, "adapter-properties-memory-heaps") \
|
|
64
|
+
V(AdapterPropertiesD3D, "adapter-properties-d3d") \
|
|
65
|
+
V(AdapterPropertiesVk, "adapter-properties-vk") \
|
|
66
|
+
V(DawnFormatCapabilities, "format-capabilities") \
|
|
67
|
+
V(DawnDrmFormatCapabilities, "drm-format-capabilities") \
|
|
68
|
+
V(MultiPlanarFormatNv16, "multi-planar-format-nv16") \
|
|
69
|
+
V(MultiPlanarFormatNv24, "multi-planar-format-nv24") \
|
|
70
|
+
V(MultiPlanarFormatP210, "multi-planar-format-p210") \
|
|
71
|
+
V(MultiPlanarFormatP410, "multi-planar-format-p410") \
|
|
72
|
+
V(SharedTextureMemoryVkDedicatedAllocation, \
|
|
73
|
+
"shared-texture-memory-vk-dedicated-allocation") \
|
|
74
|
+
V(SharedTextureMemoryAHardwareBuffer, \
|
|
75
|
+
"shared-texture-memory-ahardware-buffer") \
|
|
76
|
+
V(SharedTextureMemoryDmaBuf, "shared-texture-memory-dma-buf") \
|
|
77
|
+
V(SharedTextureMemoryOpaqueFD, "shared-texture-memory-opaque-fd") \
|
|
78
|
+
V(SharedTextureMemoryZirconHandle, "shared-texture-memory-zircon-handle") \
|
|
79
|
+
V(SharedTextureMemoryDXGISharedHandle, \
|
|
80
|
+
"shared-texture-memory-dxgi-shared-handle") \
|
|
81
|
+
V(SharedTextureMemoryD3D11Texture2D, \
|
|
82
|
+
"shared-texture-memory-d3d11-texture2d") \
|
|
83
|
+
V(SharedTextureMemoryIOSurface, "shared-texture-memory-iosurface") \
|
|
84
|
+
V(SharedTextureMemoryEGLImage, "shared-texture-memory-egl-image") \
|
|
85
|
+
V(SharedFenceVkSemaphoreOpaqueFD, "shared-fence-vk-semaphore-opaque-fd") \
|
|
86
|
+
V(SharedFenceSyncFD, "shared-fence-sync-fd") \
|
|
87
|
+
V(SharedFenceVkSemaphoreZirconHandle, \
|
|
88
|
+
"shared-fence-vk-semaphore-zircon-handle") \
|
|
89
|
+
V(SharedFenceDXGISharedHandle, "shared-fence-dxgi-shared-handle") \
|
|
90
|
+
V(SharedFenceMTLSharedEvent, "shared-fence-mtl-shared-event") \
|
|
91
|
+
V(SharedBufferMemoryD3D12Resource, "shared-buffer-memory-d3d12-resource") \
|
|
92
|
+
V(StaticSamplers, "static-samplers") \
|
|
93
|
+
V(YCbCrVulkanSamplers, "ycbcr-vulkan-samplers") \
|
|
94
|
+
V(ShaderModuleCompilationOptions, "shader-module-compilation-options") \
|
|
95
|
+
V(DawnLoadResolveTexture, "dawn-load-resolve-texture") \
|
|
96
|
+
V(DawnPartialLoadResolveTexture, "dawn-partial-load-resolve-texture") \
|
|
97
|
+
V(MultiDrawIndirect, "multi-draw-indirect") \
|
|
98
|
+
V(DawnTexelCopyBufferRowAlignment, "dawn-texel-copy-buffer-row-alignment") \
|
|
99
|
+
V(FlexibleTextureViews, "flexible-texture-views") \
|
|
100
|
+
V(ChromiumExperimentalSubgroupMatrix, \
|
|
101
|
+
"chromium-experimental-subgroups-matrix") \
|
|
102
|
+
V(SharedFenceEGLSync, "shared-fence-egl-sync") \
|
|
103
|
+
V(DawnDeviceAllocatorControl, "dawn-device-allocator-control") \
|
|
104
|
+
V(AdapterPropertiesWGPU, "adapter-properties-wgpu") \
|
|
105
|
+
V(SharedBufferMemoryFromWindowsHandle, \
|
|
106
|
+
"shared-buffer-memory-from-windows-handle") \
|
|
107
|
+
V(SharedTextureMemoryD3D12Resource, "shared-texture-memory-d3d12-resource") \
|
|
108
|
+
V(ChromiumExperimentalSamplingResourceTable, \
|
|
109
|
+
"chromium-experimental-sampling-resource-table") \
|
|
110
|
+
V(AtomicVec2uMinMax, "atomic-vec2u-min-max") \
|
|
111
|
+
V(Unorm16FormatsForExternalTexture, "unorm16-formats-for-external-texture") \
|
|
112
|
+
V(OpaqueYCbCrAndroidForExternalTexture, \
|
|
113
|
+
"opaque-ycbcr-android-for-external-texture") \
|
|
114
|
+
V(Unorm16Filterable, "unorm16-filterable") \
|
|
115
|
+
V(RenderPassRenderArea, "render-pass-render-area") \
|
|
116
|
+
V(AdapterPropertiesDrm, "adapter-properties-drm") \
|
|
117
|
+
V(TextureCompressionUnaligned, "texture-compression-unaligned") \
|
|
118
|
+
V(DawnAllowUndefinedLoadStoreOp, "dawn-allow-undefined-load-store-op")
|
|
119
|
+
|
|
11
120
|
static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
12
121
|
std::string *outUnion) {
|
|
13
122
|
switch (inEnum) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
case wgpu::FeatureName::Depth32FloatStencil8:
|
|
18
|
-
*outUnion = "depth32float-stencil8";
|
|
19
|
-
break;
|
|
20
|
-
case wgpu::FeatureName::TimestampQuery:
|
|
21
|
-
*outUnion = "timestamp-query";
|
|
22
|
-
break;
|
|
23
|
-
case wgpu::FeatureName::TextureCompressionBC:
|
|
24
|
-
*outUnion = "texture-compression-bc";
|
|
25
|
-
break;
|
|
26
|
-
case wgpu::FeatureName::TextureCompressionETC2:
|
|
27
|
-
*outUnion = "texture-compression-etc2";
|
|
28
|
-
break;
|
|
29
|
-
case wgpu::FeatureName::TextureCompressionASTC:
|
|
30
|
-
*outUnion = "texture-compression-astc";
|
|
31
|
-
break;
|
|
32
|
-
case wgpu::FeatureName::IndirectFirstInstance:
|
|
33
|
-
*outUnion = "indirect-first-instance";
|
|
34
|
-
break;
|
|
35
|
-
case wgpu::FeatureName::ShaderF16:
|
|
36
|
-
*outUnion = "shader-f16";
|
|
37
|
-
break;
|
|
38
|
-
case wgpu::FeatureName::RG11B10UfloatRenderable:
|
|
39
|
-
*outUnion = "rg11b10ufloat-renderable";
|
|
40
|
-
break;
|
|
41
|
-
case wgpu::FeatureName::BGRA8UnormStorage:
|
|
42
|
-
*outUnion = "bgra8unorm-storage";
|
|
43
|
-
break;
|
|
44
|
-
case wgpu::FeatureName::Float32Filterable:
|
|
45
|
-
*outUnion = "float32-filterable";
|
|
46
|
-
break;
|
|
47
|
-
case wgpu::FeatureName::Subgroups:
|
|
48
|
-
*outUnion = "subgroups";
|
|
49
|
-
break;
|
|
50
|
-
case wgpu::FeatureName::DawnInternalUsages:
|
|
51
|
-
*outUnion = "dawn-internal-usages";
|
|
52
|
-
break;
|
|
53
|
-
case wgpu::FeatureName::DawnMultiPlanarFormats:
|
|
54
|
-
*outUnion = "dawn-multi-planar-formats";
|
|
55
|
-
break;
|
|
56
|
-
case wgpu::FeatureName::DawnNative:
|
|
57
|
-
*outUnion = "dawn-native";
|
|
58
|
-
break;
|
|
59
|
-
case wgpu::FeatureName::ChromiumExperimentalTimestampQueryInsidePasses:
|
|
60
|
-
*outUnion = "chromium-experimental-timestamp-query-inside-passes";
|
|
61
|
-
break;
|
|
62
|
-
case wgpu::FeatureName::ImplicitDeviceSynchronization:
|
|
63
|
-
*outUnion = "implicit-device-synchronization";
|
|
64
|
-
break;
|
|
65
|
-
case wgpu::FeatureName::TransientAttachments:
|
|
66
|
-
*outUnion = "transient-attachments";
|
|
67
|
-
break;
|
|
68
|
-
case wgpu::FeatureName::MSAARenderToSingleSampled:
|
|
69
|
-
*outUnion = "msaa-render-to-single-sampled";
|
|
70
|
-
break;
|
|
71
|
-
case wgpu::FeatureName::DualSourceBlending:
|
|
72
|
-
*outUnion = "dual-source-blending";
|
|
73
|
-
break;
|
|
74
|
-
case wgpu::FeatureName::D3D11MultithreadProtected:
|
|
75
|
-
*outUnion = "d3d11-multithread-protected";
|
|
76
|
-
break;
|
|
77
|
-
case wgpu::FeatureName::ANGLETextureSharing:
|
|
78
|
-
*outUnion = "angle-texture-sharing";
|
|
79
|
-
break;
|
|
80
|
-
case wgpu::FeatureName::ChromiumExperimentalSubgroupMatrix:
|
|
81
|
-
*outUnion = "chromium-experimental-subgroups-matrix";
|
|
82
|
-
break;
|
|
83
|
-
case wgpu::FeatureName::PixelLocalStorageCoherent:
|
|
84
|
-
*outUnion = "pixel-local-storage-coherent";
|
|
85
|
-
break;
|
|
86
|
-
case wgpu::FeatureName::PixelLocalStorageNonCoherent:
|
|
87
|
-
*outUnion = "pixel-local-storage-non-coherent";
|
|
88
|
-
break;
|
|
89
|
-
case wgpu::FeatureName::Unorm16TextureFormats:
|
|
90
|
-
*outUnion = "unorm16-texture-formats";
|
|
91
|
-
break;
|
|
92
|
-
case wgpu::FeatureName::MultiPlanarFormatExtendedUsages:
|
|
93
|
-
*outUnion = "multi-planar-format-extended-usages";
|
|
94
|
-
break;
|
|
95
|
-
case wgpu::FeatureName::MultiPlanarFormatP010:
|
|
96
|
-
*outUnion = "multi-planar-format-p010";
|
|
97
|
-
break;
|
|
98
|
-
case wgpu::FeatureName::HostMappedPointer:
|
|
99
|
-
*outUnion = "host-mapped-pointer";
|
|
100
|
-
break;
|
|
101
|
-
case wgpu::FeatureName::MultiPlanarRenderTargets:
|
|
102
|
-
*outUnion = "multi-planar-render-targets";
|
|
103
|
-
break;
|
|
104
|
-
case wgpu::FeatureName::MultiPlanarFormatNv12a:
|
|
105
|
-
*outUnion = "multi-planar-format-nv12a";
|
|
106
|
-
break;
|
|
107
|
-
case wgpu::FeatureName::FramebufferFetch:
|
|
108
|
-
*outUnion = "framebuffer-fetch";
|
|
109
|
-
break;
|
|
110
|
-
case wgpu::FeatureName::BufferMapExtendedUsages:
|
|
111
|
-
*outUnion = "buffer-map-extended-usages";
|
|
112
|
-
break;
|
|
113
|
-
case wgpu::FeatureName::AdapterPropertiesMemoryHeaps:
|
|
114
|
-
*outUnion = "adapter-properties-memory-heaps";
|
|
115
|
-
break;
|
|
116
|
-
case wgpu::FeatureName::AdapterPropertiesD3D:
|
|
117
|
-
*outUnion = "adapter-properties-d3d";
|
|
118
|
-
break;
|
|
119
|
-
case wgpu::FeatureName::AdapterPropertiesVk:
|
|
120
|
-
*outUnion = "adapter-properties-vk";
|
|
121
|
-
break;
|
|
122
|
-
case wgpu::FeatureName::DawnFormatCapabilities:
|
|
123
|
-
*outUnion = "format-capabilities";
|
|
124
|
-
break;
|
|
125
|
-
case wgpu::FeatureName::DawnDrmFormatCapabilities:
|
|
126
|
-
*outUnion = "drm-format-capabilities";
|
|
127
|
-
break;
|
|
128
|
-
case wgpu::FeatureName::MultiPlanarFormatNv16:
|
|
129
|
-
*outUnion = "multi-planar-format-nv16";
|
|
130
|
-
break;
|
|
131
|
-
case wgpu::FeatureName::MultiPlanarFormatNv24:
|
|
132
|
-
*outUnion = "multi-planar-format-nv24";
|
|
133
|
-
break;
|
|
134
|
-
case wgpu::FeatureName::MultiPlanarFormatP210:
|
|
135
|
-
*outUnion = "multi-planar-format-p210";
|
|
136
|
-
break;
|
|
137
|
-
case wgpu::FeatureName::MultiPlanarFormatP410:
|
|
138
|
-
*outUnion = "multi-planar-format-p410";
|
|
139
|
-
break;
|
|
140
|
-
case wgpu::FeatureName::SharedTextureMemoryVkDedicatedAllocation:
|
|
141
|
-
*outUnion = "shared-texture-memory-vk-dedicated-allocation";
|
|
142
|
-
break;
|
|
143
|
-
case wgpu::FeatureName::SharedTextureMemoryAHardwareBuffer:
|
|
144
|
-
*outUnion = "shared-texture-memory-ahardware-buffer";
|
|
145
|
-
break;
|
|
146
|
-
case wgpu::FeatureName::SharedTextureMemoryDmaBuf:
|
|
147
|
-
*outUnion = "shared-texture-memory-dma-buf";
|
|
148
|
-
break;
|
|
149
|
-
case wgpu::FeatureName::SharedTextureMemoryOpaqueFD:
|
|
150
|
-
*outUnion = "shared-texture-memory-opaque-fd";
|
|
151
|
-
break;
|
|
152
|
-
case wgpu::FeatureName::SharedTextureMemoryZirconHandle:
|
|
153
|
-
*outUnion = "shared-texture-memory-zircon-handle";
|
|
154
|
-
break;
|
|
155
|
-
case wgpu::FeatureName::SharedTextureMemoryDXGISharedHandle:
|
|
156
|
-
*outUnion = "shared-texture-memory-dxgi-shared-handle";
|
|
157
|
-
break;
|
|
158
|
-
case wgpu::FeatureName::SharedTextureMemoryD3D11Texture2D:
|
|
159
|
-
*outUnion = "shared-texture-memory-d3d11-texture2d";
|
|
160
|
-
break;
|
|
161
|
-
case wgpu::FeatureName::SharedTextureMemoryIOSurface:
|
|
162
|
-
*outUnion = "shared-texture-memory-iosurface";
|
|
163
|
-
break;
|
|
164
|
-
case wgpu::FeatureName::SharedTextureMemoryEGLImage:
|
|
165
|
-
*outUnion = "shared-texture-memory-egl-image";
|
|
166
|
-
break;
|
|
167
|
-
case wgpu::FeatureName::SharedFenceVkSemaphoreOpaqueFD:
|
|
168
|
-
*outUnion = "shared-fence-vk-semaphore-opaque-fd";
|
|
169
|
-
break;
|
|
170
|
-
case wgpu::FeatureName::SharedFenceSyncFD:
|
|
171
|
-
*outUnion = "shared-fence-sync-fd";
|
|
172
|
-
break;
|
|
173
|
-
case wgpu::FeatureName::SharedFenceVkSemaphoreZirconHandle:
|
|
174
|
-
*outUnion = "shared-fence-vk-semaphore-zircon-handle";
|
|
175
|
-
break;
|
|
176
|
-
case wgpu::FeatureName::SharedFenceDXGISharedHandle:
|
|
177
|
-
*outUnion = "shared-fence-dxgi-shared-handle";
|
|
178
|
-
break;
|
|
179
|
-
case wgpu::FeatureName::SharedFenceMTLSharedEvent:
|
|
180
|
-
*outUnion = "shared-fence-mtl-shared-event";
|
|
181
|
-
break;
|
|
182
|
-
case wgpu::FeatureName::SharedBufferMemoryD3D12Resource:
|
|
183
|
-
*outUnion = "shared-buffer-memory-d3d12-resource";
|
|
184
|
-
break;
|
|
185
|
-
case wgpu::FeatureName::StaticSamplers:
|
|
186
|
-
*outUnion = "static-samplers";
|
|
187
|
-
break;
|
|
188
|
-
case wgpu::FeatureName::YCbCrVulkanSamplers:
|
|
189
|
-
*outUnion = "ycbcr-vulkan-samplers";
|
|
190
|
-
break;
|
|
191
|
-
case wgpu::FeatureName::OpaqueYCbCrAndroidForExternalTexture:
|
|
192
|
-
*outUnion = "opaque-ycbcr-android-for-external-texture";
|
|
193
|
-
break;
|
|
194
|
-
case wgpu::FeatureName::ShaderModuleCompilationOptions:
|
|
195
|
-
*outUnion = "shader-module-compilation-options";
|
|
196
|
-
break;
|
|
197
|
-
case wgpu::FeatureName::DawnLoadResolveTexture:
|
|
198
|
-
*outUnion = "dawn-load-resolve-texture";
|
|
123
|
+
#define RNWGPU_FEATURE_NAME_CASE(Enum, Name) \
|
|
124
|
+
case wgpu::FeatureName::Enum: \
|
|
125
|
+
*outUnion = Name; \
|
|
199
126
|
break;
|
|
127
|
+
RNWGPU_FOR_EACH_FEATURE_NAME(RNWGPU_FEATURE_NAME_CASE)
|
|
128
|
+
#undef RNWGPU_FEATURE_NAME_CASE
|
|
200
129
|
default:
|
|
201
130
|
fprintf(stderr, "Unknown feature name %d\n", static_cast<int>(inEnum));
|
|
202
131
|
*outUnion = "";
|
|
@@ -128,6 +128,30 @@ void GPUQueue::copyExternalImageToTexture(
|
|
|
128
128
|
throw std::runtime_error("Invalid input for GPUQueue::writeTexture()");
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
const auto origin = source->origin.value_or(nullptr);
|
|
132
|
+
// GPUOrigin2D coordinates are [EnforceRange] unsigned long: negative,
|
|
133
|
+
// NaN, or out-of-range doubles must be rejected here because casting
|
|
134
|
+
// them to an unsigned integer is undefined behavior.
|
|
135
|
+
constexpr double kMaxOrigin =
|
|
136
|
+
static_cast<double>(std::numeric_limits<uint32_t>::max());
|
|
137
|
+
if (origin && (!(origin->x >= 0) || !(origin->y >= 0) ||
|
|
138
|
+
origin->x > kMaxOrigin || origin->y > kMaxOrigin)) {
|
|
139
|
+
throw std::runtime_error(
|
|
140
|
+
"The source origin must be a non-negative integer coordinate.");
|
|
141
|
+
}
|
|
142
|
+
const size_t sourceOriginX =
|
|
143
|
+
origin ? static_cast<size_t>(origin->x) : 0;
|
|
144
|
+
const size_t sourceOriginY =
|
|
145
|
+
origin ? static_cast<size_t>(origin->y) : 0;
|
|
146
|
+
if (sourceOriginX > source->source->getWidth() ||
|
|
147
|
+
sz.width > source->source->getWidth() - sourceOriginX ||
|
|
148
|
+
sourceOriginY > source->source->getHeight() ||
|
|
149
|
+
sz.height > source->source->getHeight() - sourceOriginY ||
|
|
150
|
+
sz.depthOrArrayLayers > 1) {
|
|
151
|
+
throw std::runtime_error(
|
|
152
|
+
"The source copy region is outside the ImageBitmap.");
|
|
153
|
+
}
|
|
154
|
+
|
|
131
155
|
const bool flipY = source->flipY.value_or(false);
|
|
132
156
|
// premultipliedAlpha defaults to false per the WebGPU spec: an untagged
|
|
133
157
|
// destination expects straight alpha. Convert only when the ImageBitmap's
|
|
@@ -138,28 +162,30 @@ void GPUQueue::copyExternalImageToTexture(
|
|
|
138
162
|
const bool needsAlphaConversion =
|
|
139
163
|
bytesPerPixel == 4 && sourcePremultiplied != destinationPremultiplied;
|
|
140
164
|
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
uint32_t
|
|
165
|
+
if (sourceOriginX != 0 || sourceOriginY != 0 || flipY ||
|
|
166
|
+
needsAlphaConversion) {
|
|
167
|
+
uint32_t sourceRowSize = bytesPerPixel * source->source->getWidth();
|
|
168
|
+
uint32_t rowSize = bytesPerPixel * sz.width;
|
|
169
|
+
uint32_t totalSize = rowSize * sz.height;
|
|
144
170
|
|
|
145
|
-
// Stage
|
|
146
|
-
// ImageBitmap's backing store.
|
|
171
|
+
// Stage only the selected subregion so transformations never touch the
|
|
172
|
+
// ImageBitmap's backing store or pixels outside the requested copy.
|
|
147
173
|
std::vector<uint8_t> staged(totalSize);
|
|
148
174
|
const uint8_t *src =
|
|
149
175
|
static_cast<const uint8_t *>(source->source->getData());
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} else {
|
|
157
|
-
std::memcpy(staged.data(), src, totalSize);
|
|
176
|
+
for (uint32_t row = 0; row < sz.height; ++row) {
|
|
177
|
+
const uint32_t sourceRow =
|
|
178
|
+
sourceOriginY + (flipY ? sz.height - 1 - row : row);
|
|
179
|
+
const uint32_t sourceOffset =
|
|
180
|
+
sourceRow * sourceRowSize + sourceOriginX * bytesPerPixel;
|
|
181
|
+
std::memcpy(staged.data() + row * rowSize, src + sourceOffset, rowSize);
|
|
158
182
|
}
|
|
159
183
|
if (needsAlphaConversion) {
|
|
160
184
|
convertAlpha(staged.data(), totalSize, sourcePremultiplied,
|
|
161
185
|
destinationPremultiplied);
|
|
162
186
|
}
|
|
187
|
+
layout.bytesPerRow = rowSize;
|
|
188
|
+
layout.rowsPerImage = sz.height;
|
|
163
189
|
_instance.WriteTexture(&dst, staged.data(), totalSize, &layout, &sz);
|
|
164
190
|
} else {
|
|
165
191
|
_instance.WriteTexture(&dst, source->source->getData(),
|