react-native-wgpu 0.1.0 → 0.1.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/README.md +221 -13
- package/android/CMakeLists.txt +15 -1
- package/android/build.gradle +0 -18
- package/android/cpp/AndroidPlatformContext.h +26 -0
- package/android/cpp/cpp-adapter.cpp +66 -3
- package/android/src/main/java/com/webgpu/WebGPUModule.java +64 -22
- package/android/src/main/java/com/webgpu/WebGPUView.java +63 -8
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +5 -6
- package/android/src/newarch/{WgpuViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +5 -5
- package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +23 -0
- package/android/src/oldarch/{WebGPUViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +1 -1
- package/cpp/{Logger.h → WGPULogger.h} +13 -6
- package/cpp/dawn/webgpu.h +9 -0
- package/cpp/dawn/webgpu_cpp.h +95 -43
- package/cpp/dawn/webgpu_cpp_print.h +6 -0
- package/cpp/dawn/wire/client/webgpu_cpp.h +80 -43
- package/cpp/jsi/RNFHybridObject.cpp +1 -1
- package/cpp/jsi/RNFHybridObject.h +4 -4
- package/cpp/jsi/RNFJSIConverter.h +204 -17
- package/cpp/rnwgpu/ArrayBuffer.h +72 -0
- package/cpp/rnwgpu/PlatformContext.h +16 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +14 -9
- package/cpp/rnwgpu/RNWebGPUManager.h +12 -1
- package/cpp/rnwgpu/SurfaceRegistry.h +36 -0
- package/cpp/rnwgpu/api/AsyncRunner.h +30 -0
- package/cpp/rnwgpu/api/Canvas.h +55 -0
- package/cpp/rnwgpu/api/Convertors.h +765 -0
- package/cpp/rnwgpu/api/External.h +12 -0
- package/cpp/rnwgpu/api/GPU.cpp +100 -23
- package/cpp/rnwgpu/api/GPU.h +24 -6
- package/cpp/rnwgpu/api/GPUAdapter.cpp +122 -8
- package/cpp/rnwgpu/api/GPUAdapter.h +24 -5
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +19 -7
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +3 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +11 -4
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +11 -4
- package/cpp/rnwgpu/api/GPUBuffer.cpp +82 -7
- package/cpp/rnwgpu/api/GPUBuffer.h +43 -7
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +63 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.h +51 -8
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +11 -4
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +177 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +75 -3
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +65 -8
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +6 -4
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +58 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +49 -3
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +11 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +18 -3
- package/cpp/rnwgpu/api/GPUDevice.cpp +330 -3
- package/cpp/rnwgpu/api/GPUDevice.h +119 -5
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +6 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +14 -7
- package/cpp/rnwgpu/api/GPUError.h +42 -0
- package/cpp/rnwgpu/api/GPUExtent3D.h +69 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +11 -4
- package/cpp/rnwgpu/api/GPUFeatures.h +221 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +59 -0
- package/cpp/rnwgpu/api/GPUOrigin3D.h +66 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +11 -4
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +11 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +19 -5
- package/cpp/rnwgpu/api/GPUQueue.cpp +110 -0
- package/cpp/rnwgpu/api/GPUQueue.h +45 -4
- package/cpp/rnwgpu/api/GPURenderBundle.h +11 -4
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +128 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +72 -3
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +161 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +93 -3
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +13 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.h +18 -3
- package/cpp/rnwgpu/api/GPUSampler.h +11 -4
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +39 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +23 -4
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +133 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +128 -4
- package/cpp/rnwgpu/api/GPUTexture.cpp +47 -0
- package/cpp/rnwgpu/api/GPUTexture.h +38 -4
- package/cpp/rnwgpu/api/GPUTextureView.h +11 -4
- package/cpp/rnwgpu/api/ImageData.h +50 -0
- package/cpp/rnwgpu/api/Navigator.h +46 -0
- package/cpp/rnwgpu/api/WebGPUCanvasContextFactory.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +31 -43
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +40 -31
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +24 -32
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +56 -49
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +27 -20
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +23 -31
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +25 -36
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +25 -25
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +26 -46
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +31 -53
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +72 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +27 -33
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +24 -25
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +25 -42
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +32 -42
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +58 -76
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +38 -30
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +11 -11
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +43 -34
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +39 -46
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +29 -45
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +25 -34
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +32 -36
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +42 -44
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +24 -34
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +24 -32
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +25 -35
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +35 -26
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +29 -35
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +23 -43
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +49 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +41 -57
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +42 -61
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +54 -66
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +52 -55
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +25 -42
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +60 -56
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +21 -20
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +17 -14
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +63 -63
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +28 -27
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +28 -49
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +32 -23
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +27 -29
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +27 -20
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +49 -76
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +48 -64
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +29 -31
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +23 -44
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +30 -36
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +39 -38
- package/cpp/rnwgpu/api/descriptors/Unions.h +57 -2
- package/ios/IOSPlatformContext.h +16 -0
- package/ios/IOSPlatformContext.mm +18 -0
- package/ios/MetalView.h +10 -0
- package/ios/MetalView.mm +27 -0
- package/ios/SurfaceUtils.h +13 -0
- package/ios/SurfaceUtils.mm +24 -0
- package/ios/WebGPUModule.h +8 -7
- package/ios/WebGPUModule.mm +47 -14
- package/ios/WebGPUView.h +6 -3
- package/ios/WebGPUView.mm +36 -24
- package/ios/WebGPUViewComponentDescriptor.h +61 -0
- package/ios/WebGPUViewManager.mm +6 -4
- package/lib/commonjs/Canvas.js +49 -0
- package/lib/commonjs/Canvas.js.map +1 -0
- package/lib/commonjs/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
- package/lib/commonjs/{WebGPUNativeModule.js.map → NativeWebGPUModule.js.map} +1 -1
- package/lib/commonjs/WebGPUView.js +2 -0
- package/lib/commonjs/WebGPUView.js.map +1 -0
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/commonjs/index.js +158 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Canvas.js +42 -0
- package/lib/module/Canvas.js.map +1 -0
- package/lib/module/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
- package/lib/module/NativeWebGPUModule.js.map +1 -0
- package/lib/module/WebGPUView.js +2 -0
- package/lib/module/WebGPUView.js.map +1 -0
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/module/index.js +144 -6
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/example/src/Triangle/triangle.d.ts +3 -0
- package/lib/typescript/example/src/Triangle/triangle.d.ts.map +1 -0
- package/lib/typescript/example/src/Wireframe/Shaders.d.ts +3 -0
- package/lib/typescript/example/src/Wireframe/Shaders.d.ts.map +1 -0
- package/lib/typescript/example/src/Wireframe/models.d.ts +29 -0
- package/lib/typescript/example/src/Wireframe/models.d.ts.map +1 -0
- package/lib/typescript/example/src/components/DrawingContext.d.ts +13 -0
- package/lib/typescript/example/src/components/DrawingContext.d.ts.map +1 -0
- package/lib/typescript/example/src/components/cube.d.ts +7 -0
- package/lib/typescript/example/src/components/cube.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/sphere.d.ts +12 -0
- package/lib/typescript/example/src/components/meshes/sphere.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/teapot.d.ts +6 -0
- package/lib/typescript/example/src/components/meshes/teapot.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/utils.d.ts +10 -0
- package/lib/typescript/example/src/components/meshes/utils.d.ts.map +1 -0
- package/lib/typescript/jest.config.d.ts +4 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts +4 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
- package/lib/typescript/lib/commonjs/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts +1 -0
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +0 -2
- package/lib/typescript/lib/module/Canvas.d.ts +2 -0
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/module/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
- package/lib/typescript/lib/module/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebGPUView.d.ts +1 -0
- package/lib/typescript/lib/module/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +2 -3
- package/lib/typescript/src/Canvas.d.ts +22 -0
- package/lib/typescript/src/Canvas.d.ts.map +1 -0
- package/lib/typescript/src/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +2 -1
- package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUView.d.ts +1 -0
- package/lib/typescript/src/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +2 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -7
- package/lib/typescript/src/index.d.ts.map +1 -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/dawn.json +4597 -0
- package/libs/ios/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/ios/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.xcframework/Info.plist +44 -0
- package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/ios/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/package.json +25 -8
- package/{react-native-webgpu.podspec → react-native-wgpu.podspec} +6 -9
- package/src/Canvas.tsx +68 -0
- package/src/{WebGPUNativeModule.ts → NativeWebGPUModule.ts} +1 -0
- package/src/WebGPUView.tsx +0 -0
- package/src/WebGPUViewNativeComponent.ts +2 -1
- package/src/index.tsx +172 -8
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/cpp/rnwgpu/MutableBuffer.h +0 -48
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -33
- package/cpp/rnwgpu/api/descriptors/GPUColorDict.h +0 -81
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDict.h +0 -76
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDictStrict.h +0 -91
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDict.h +0 -61
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDictStrict.h +0 -75
- package/cpp/rnwgpu/api/descriptors/GPUOrigin3DDict.h +0 -71
- package/cpp/rnwgpu/api/descriptors/GPUPipelineErrorInit.h +0 -54
- package/cpp/rnwgpu/api/descriptors/GPURenderPassLayout.h +0 -83
- package/ios/RNFAppleLogger.mm +0 -22
- package/ios/Utils.h +0 -5
- package/ios/Utils.m +0 -26
- package/lib/module/WebGPUNativeModule.js.map +0 -1
- package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts.map +0 -1
- package/lib/typescript/lib/module/WebGPUNativeModule.d.ts.map +0 -1
- package/lib/typescript/scripts/build/copy-artifacts.d.ts +0 -2
- package/lib/typescript/scripts/build/copy-artifacts.d.ts.map +0 -1
- package/lib/typescript/scripts/build/dawn.d.ts +0 -2
- package/lib/typescript/scripts/build/dawn.d.ts.map +0 -1
- package/lib/typescript/scripts/build/util.d.ts +0 -13
- package/lib/typescript/scripts/build/util.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/codegen.d.ts +0 -2
- package/lib/typescript/scripts/codegen/codegen.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/model/dawn.d.ts +0 -2
- package/lib/typescript/scripts/codegen/model/dawn.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/model/model.d.ts +0 -8
- package/lib/typescript/scripts/codegen/model/model.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts +0 -4
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts +0 -3
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts +0 -3
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts +0 -6
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/common.d.ts +0 -9
- package/lib/typescript/scripts/codegen/templates/common.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/util.d.ts +0 -2
- package/lib/typescript/scripts/codegen/util.d.ts.map +0 -1
- package/lib/typescript/src/WebGPUNativeModule.d.ts.map +0 -1
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <map>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <optional>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <utility>
|
|
8
|
+
#include <variant>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
#include "webgpu/webgpu_cpp.h"
|
|
12
|
+
|
|
13
|
+
#include "GPUBindGroupDescriptor.h"
|
|
14
|
+
#include "GPUBindGroupEntry.h"
|
|
15
|
+
#include "GPUBindGroupLayoutDescriptor.h"
|
|
16
|
+
#include "GPUBindGroupLayoutEntry.h"
|
|
17
|
+
#include "GPUBlendComponent.h"
|
|
18
|
+
#include "GPUBlendState.h"
|
|
19
|
+
#include "GPUBufferBinding.h"
|
|
20
|
+
#include "GPUBufferBindingLayout.h"
|
|
21
|
+
#include "GPUBufferDescriptor.h"
|
|
22
|
+
#include "GPUColor.h"
|
|
23
|
+
#include "GPUColorTargetState.h"
|
|
24
|
+
#include "GPUCommandBufferDescriptor.h"
|
|
25
|
+
#include "GPUCommandEncoderDescriptor.h"
|
|
26
|
+
#include "GPUComputePassDescriptor.h"
|
|
27
|
+
#include "GPUComputePassTimestampWrites.h"
|
|
28
|
+
#include "GPUComputePipelineDescriptor.h"
|
|
29
|
+
#include "GPUDepthStencilState.h"
|
|
30
|
+
#include "GPUDeviceDescriptor.h"
|
|
31
|
+
#include "GPUExternalTextureBindingLayout.h"
|
|
32
|
+
#include "GPUFragmentState.h"
|
|
33
|
+
#include "GPUImageCopyBuffer.h"
|
|
34
|
+
#include "GPUImageCopyTexture.h"
|
|
35
|
+
#include "GPUImageCopyTextureTagged.h"
|
|
36
|
+
#include "GPUImageDataLayout.h"
|
|
37
|
+
#include "GPUMultisampleState.h"
|
|
38
|
+
#include "GPUPipelineLayoutDescriptor.h"
|
|
39
|
+
#include "GPUPrimitiveState.h"
|
|
40
|
+
#include "GPUProgrammableStage.h"
|
|
41
|
+
#include "GPUQuerySetDescriptor.h"
|
|
42
|
+
#include "GPUQueueDescriptor.h"
|
|
43
|
+
#include "GPURenderBundleDescriptor.h"
|
|
44
|
+
#include "GPURenderBundleEncoderDescriptor.h"
|
|
45
|
+
#include "GPURenderPassColorAttachment.h"
|
|
46
|
+
#include "GPURenderPassDepthStencilAttachment.h"
|
|
47
|
+
#include "GPURenderPassDescriptor.h"
|
|
48
|
+
#include "GPURenderPassTimestampWrites.h"
|
|
49
|
+
#include "GPURenderPipelineDescriptor.h"
|
|
50
|
+
#include "GPURequestAdapterOptions.h"
|
|
51
|
+
#include "GPUSamplerBindingLayout.h"
|
|
52
|
+
#include "GPUSamplerDescriptor.h"
|
|
53
|
+
#include "GPUShaderModuleCompilationHint.h"
|
|
54
|
+
#include "GPUShaderModuleDescriptor.h"
|
|
55
|
+
#include "GPUStencilFaceState.h"
|
|
56
|
+
#include "GPUStorageTextureBindingLayout.h"
|
|
57
|
+
#include "GPUTextureBindingLayout.h"
|
|
58
|
+
#include "GPUTextureDescriptor.h"
|
|
59
|
+
#include "GPUTextureViewDescriptor.h"
|
|
60
|
+
#include "GPUVertexAttribute.h"
|
|
61
|
+
#include "GPUVertexBufferLayout.h"
|
|
62
|
+
#include "GPUVertexState.h"
|
|
63
|
+
|
|
64
|
+
namespace rnwgpu {
|
|
65
|
+
|
|
66
|
+
class Convertor {
|
|
67
|
+
public:
|
|
68
|
+
~Convertor() {
|
|
69
|
+
for (auto &free : free_) {
|
|
70
|
+
free();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
template <typename OUT, typename IN>
|
|
75
|
+
[[nodiscard]] inline bool operator()(OUT &&out, IN &&in) {
|
|
76
|
+
return Convert(std::forward<OUT>(out), std::forward<IN>(in));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
template <typename OUT, typename IN>
|
|
80
|
+
[[nodiscard]] inline bool operator()(OUT *&out_els, size_t &out_count,
|
|
81
|
+
const std::vector<IN> &in) {
|
|
82
|
+
return Convert(out_els, out_count, in);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
template <typename OUT, typename IN>
|
|
86
|
+
[[nodiscard]] inline bool Convert(OUT *&out_els, size_t &out_count,
|
|
87
|
+
const std::optional<std::vector<IN>> &in) {
|
|
88
|
+
if (!in.has_value()) {
|
|
89
|
+
out_els = nullptr;
|
|
90
|
+
out_count = 0;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return Convert(out_els, out_count, in.value());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
template <typename OUT, typename IN>
|
|
97
|
+
[[nodiscard]] inline bool Convert(OUT *&out_els, size_t &out_count,
|
|
98
|
+
const std::vector<IN> &in) {
|
|
99
|
+
if (in.size() == 0) {
|
|
100
|
+
out_els = nullptr;
|
|
101
|
+
out_count = 0;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
auto *els = Allocate<std::remove_const_t<OUT>>(in.size());
|
|
105
|
+
for (size_t i = 0; i < in.size(); i++) {
|
|
106
|
+
if (!Convert(els[i], in[i])) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
out_els = els;
|
|
111
|
+
return Convert(out_count, in.size());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
template <typename OUT, typename IN>
|
|
115
|
+
[[nodiscard]] inline bool
|
|
116
|
+
Convert(OUT *&out_els, size_t &out_count,
|
|
117
|
+
const std::vector<std::variant<std::nullptr_t, IN>> &in) {
|
|
118
|
+
std::vector<IN> filtered;
|
|
119
|
+
filtered.reserve(in.size());
|
|
120
|
+
|
|
121
|
+
for (const auto &item : in) {
|
|
122
|
+
if (auto ptr = std::get_if<IN>(&item)) {
|
|
123
|
+
filtered.push_back(*ptr);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return Convert(out_els, out_count, filtered);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
template <typename OUT, typename INKEY, typename INVALUE>
|
|
131
|
+
[[nodiscard]] inline bool
|
|
132
|
+
Convert(OUT *&out_els, size_t &out_count,
|
|
133
|
+
const std::optional<std::map<INKEY, INVALUE>> &in) {
|
|
134
|
+
if (!in.has_value() || in.value().size() == 0) {
|
|
135
|
+
out_els = nullptr;
|
|
136
|
+
out_count = 0;
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
auto val = in.value();
|
|
140
|
+
auto *els = Allocate<std::remove_const_t<OUT>>(val.size());
|
|
141
|
+
size_t i = 0;
|
|
142
|
+
for (const auto &item : val) {
|
|
143
|
+
if (!Convert(els[i], item.first, item.second)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
i++;
|
|
147
|
+
}
|
|
148
|
+
out_els = els;
|
|
149
|
+
return Convert(out_count, val.size());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
template <typename T>
|
|
153
|
+
[[nodiscard]] auto Convert(T &out, const std::nullptr_t &in) {
|
|
154
|
+
out = nullptr;
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
[[nodiscard]] bool Convert(wgpu::Bool &out, const bool &in) {
|
|
159
|
+
out = in;
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
template <typename T>
|
|
164
|
+
[[nodiscard]] typename std::enable_if<
|
|
165
|
+
(std::is_arithmetic<T>::value || std::is_enum<T>::value), bool>::type
|
|
166
|
+
Convert(T &out, const double &in) {
|
|
167
|
+
out = static_cast<T>(in);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
template <typename T>
|
|
172
|
+
[[nodiscard]] typename std::enable_if<std::is_enum<T>::value, bool>::type
|
|
173
|
+
Convert(T &out, const T &in) {
|
|
174
|
+
out = in;
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
[[nodiscard]] bool Convert(const char *&out, const std::string &in) {
|
|
179
|
+
out = in.c_str();
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
template <typename OUT, typename IN>
|
|
184
|
+
[[nodiscard]] bool Convert(OUT &out, const std::optional<IN> &in) {
|
|
185
|
+
if (in.has_value()) {
|
|
186
|
+
return Convert(out, in.value());
|
|
187
|
+
}
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
template <typename T, typename = void>
|
|
192
|
+
struct has_get_member : std::false_type {};
|
|
193
|
+
|
|
194
|
+
template <typename T>
|
|
195
|
+
struct has_get_member<T, std::void_t<decltype(std::declval<T>().get())>>
|
|
196
|
+
: std::true_type {};
|
|
197
|
+
|
|
198
|
+
template <typename OUT, typename IN>
|
|
199
|
+
[[nodiscard]] bool Convert(OUT &out, const std::shared_ptr<IN> &in) {
|
|
200
|
+
if constexpr (has_get_member<IN>::value) {
|
|
201
|
+
out = in->get();
|
|
202
|
+
return true;
|
|
203
|
+
} else {
|
|
204
|
+
return Convert(out, *in);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
template <typename OUT, typename IN,
|
|
209
|
+
typename _ = std::enable_if_t<!std::is_same_v<IN, std::string>>>
|
|
210
|
+
[[nodiscard]] inline bool Convert(OUT *&out, const std::optional<IN> &in) {
|
|
211
|
+
if (in.has_value()) {
|
|
212
|
+
auto *el = Allocate<std::remove_const_t<OUT>>();
|
|
213
|
+
if (!Convert(*el, in.value())) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
out = el;
|
|
217
|
+
} else {
|
|
218
|
+
out = nullptr;
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
template <typename OUT, typename IN>
|
|
224
|
+
[[nodiscard]] bool Convert(OUT &out,
|
|
225
|
+
const std::variant<std::nullptr_t, IN> &in) {
|
|
226
|
+
if (std::holds_alternative<std::nullptr_t>(in)) {
|
|
227
|
+
return Convert(out, std::get<std::nullptr_t>(in));
|
|
228
|
+
}
|
|
229
|
+
return Convert(out, std::get<IN>(in));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
[[nodiscard]] bool Convert(wgpu::Origin3D &out, const GPUOrigin3D &in) {
|
|
233
|
+
return Convert(out.x, in.x) && Convert(out.y, in.y) && Convert(out.z, in.z);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
[[nodiscard]] bool Convert(wgpu::Extent3D &out, const GPUExtent3D &in) {
|
|
237
|
+
return Convert(out.width, in.width) && Convert(out.height, in.height) &&
|
|
238
|
+
Convert(out.depthOrArrayLayers, in.depthOrArrayLayers);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
[[nodiscard]] bool Convert(wgpu::BindGroupLayoutEntry &out,
|
|
242
|
+
const GPUBindGroupLayoutEntry &in) {
|
|
243
|
+
return Convert(out.binding, in.binding) &&
|
|
244
|
+
Convert(out.visibility, in.visibility) &&
|
|
245
|
+
Convert(out.buffer, in.buffer) && Convert(out.sampler, in.sampler) &&
|
|
246
|
+
Convert(out.texture, in.texture) &&
|
|
247
|
+
Convert(out.storageTexture, in.storageTexture);
|
|
248
|
+
// no external textures here
|
|
249
|
+
//&& Convert(out.externalTexture, in.externalTexture);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
[[nodiscard]] bool Convert(wgpu::BlendComponent &out,
|
|
253
|
+
const GPUBlendComponent &in) {
|
|
254
|
+
out = {};
|
|
255
|
+
return Convert(out.operation, in.operation) &&
|
|
256
|
+
Convert(out.dstFactor, in.dstFactor) &&
|
|
257
|
+
Convert(out.srcFactor, in.srcFactor);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
[[nodiscard]] bool Convert(wgpu::BlendState &out, const GPUBlendState &in) {
|
|
261
|
+
out = {};
|
|
262
|
+
return Convert(out.alpha, in.alpha) && Convert(out.color, in.color);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
[[nodiscard]] bool Convert(wgpu::BufferBindingLayout &out,
|
|
266
|
+
const GPUBufferBindingLayout &in) {
|
|
267
|
+
// here the buffer property is set so type is set to its default value
|
|
268
|
+
if (!in.type.has_value()) {
|
|
269
|
+
out.type = wgpu::BufferBindingType::Uniform;
|
|
270
|
+
}
|
|
271
|
+
return Convert(out.type, in.type) &&
|
|
272
|
+
Convert(out.hasDynamicOffset, in.hasDynamicOffset) &&
|
|
273
|
+
Convert(out.minBindingSize, in.minBindingSize);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
[[nodiscard]] bool Convert(wgpu::BufferDescriptor &out,
|
|
277
|
+
const GPUBufferDescriptor &in) {
|
|
278
|
+
return Convert(out.size, in.size) && Convert(out.usage, in.usage) &&
|
|
279
|
+
Convert(out.mappedAtCreation, in.mappedAtCreation) &&
|
|
280
|
+
Convert(out.label, in.label);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// [[nodiscard]] bool Convert(wgpu::CanvasConfiguration &out,
|
|
284
|
+
// const GPUCanvasConfiguration &in) {
|
|
285
|
+
// return Convert(out.device, in.device) && Convert(out.format, in.format)
|
|
286
|
+
// &&
|
|
287
|
+
// Convert(out.usage, in.usage) && Convert(out.viewFormats,
|
|
288
|
+
// in.viewFormats) && Convert(out.colorSpace, in.colorSpace) &&
|
|
289
|
+
// Convert(out.alphaMode, in.alphaMode);
|
|
290
|
+
// }
|
|
291
|
+
|
|
292
|
+
[[nodiscard]] bool Convert(wgpu::Color &out, const GPUColor &in) {
|
|
293
|
+
return Convert(out.r, in.r) && Convert(out.g, in.g) &&
|
|
294
|
+
Convert(out.b, in.b) && Convert(out.a, in.a);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
[[nodiscard]] bool Convert(wgpu::ColorTargetState &out,
|
|
298
|
+
const GPUColorTargetState &in) {
|
|
299
|
+
out = {};
|
|
300
|
+
return Convert(out.blend, in.blend) && Convert(out.format, in.format) &&
|
|
301
|
+
Convert(out.writeMask, in.writeMask);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
[[nodiscard]] bool Convert(wgpu::ComputePassDescriptor &out,
|
|
305
|
+
const GPUComputePassDescriptor &in) {
|
|
306
|
+
return Convert(out.timestampWrites, in.timestampWrites) &&
|
|
307
|
+
Convert(out.label, in.label);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
[[nodiscard]] bool Convert(wgpu::ComputePassTimestampWrites &out,
|
|
311
|
+
const GPUComputePassTimestampWrites &in) {
|
|
312
|
+
return Convert(out.querySet, in.querySet) &&
|
|
313
|
+
Convert(out.beginningOfPassWriteIndex,
|
|
314
|
+
in.beginningOfPassWriteIndex) &&
|
|
315
|
+
Convert(out.endOfPassWriteIndex, in.endOfPassWriteIndex);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
[[nodiscard]] bool Convert(wgpu::ComputePipelineDescriptor &out,
|
|
319
|
+
const GPUComputePipelineDescriptor &in) {
|
|
320
|
+
return Convert(out.compute, in.compute) && Convert(out.layout, in.layout) &&
|
|
321
|
+
Convert(out.label, in.label);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
[[nodiscard]] bool Convert(wgpu::DepthStencilState &out,
|
|
325
|
+
const GPUDepthStencilState &in) {
|
|
326
|
+
return Convert(out.format, in.format) &&
|
|
327
|
+
Convert(out.depthWriteEnabled, in.depthWriteEnabled) &&
|
|
328
|
+
Convert(out.depthCompare, in.depthCompare) &&
|
|
329
|
+
Convert(out.stencilFront, in.stencilFront) &&
|
|
330
|
+
Convert(out.stencilBack, in.stencilBack) &&
|
|
331
|
+
Convert(out.stencilReadMask, in.stencilReadMask) &&
|
|
332
|
+
Convert(out.stencilWriteMask, in.stencilWriteMask) &&
|
|
333
|
+
Convert(out.depthBias, in.depthBias) &&
|
|
334
|
+
Convert(out.depthBiasSlopeScale, in.depthBiasSlopeScale) &&
|
|
335
|
+
Convert(out.depthBiasClamp, in.depthBiasClamp);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
[[nodiscard]] bool Convert(wgpu::DeviceDescriptor &out,
|
|
339
|
+
const GPUDeviceDescriptor &in) {
|
|
340
|
+
if (in.requiredFeatures.has_value()) {
|
|
341
|
+
if (!Convert(out.requiredFeatures, out.requiredFeatureCount,
|
|
342
|
+
in.requiredFeatures.value())) {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (in.requiredLimits.has_value()) {
|
|
348
|
+
const auto &limits = in.requiredLimits.value();
|
|
349
|
+
auto *requiredLimits = Allocate<wgpu::RequiredLimits>();
|
|
350
|
+
for (const auto &[key, value] : limits) {
|
|
351
|
+
if (key == "maxTextureDimension1D") {
|
|
352
|
+
requiredLimits->limits.maxTextureDimension1D = value;
|
|
353
|
+
} else if (key == "maxTextureDimension2D") {
|
|
354
|
+
requiredLimits->limits.maxTextureDimension2D = value;
|
|
355
|
+
} else if (key == "maxTextureDimension3D") {
|
|
356
|
+
requiredLimits->limits.maxTextureDimension3D = value;
|
|
357
|
+
} else if (key == "maxTextureArrayLayers") {
|
|
358
|
+
requiredLimits->limits.maxTextureArrayLayers = value;
|
|
359
|
+
} else if (key == "maxBindGroups") {
|
|
360
|
+
requiredLimits->limits.maxBindGroups = value;
|
|
361
|
+
} else if (key == "maxBindGroupsPlusVertexBuffers") {
|
|
362
|
+
requiredLimits->limits.maxBindGroupsPlusVertexBuffers = value;
|
|
363
|
+
} else if (key == "maxBindingsPerBindGroup") {
|
|
364
|
+
requiredLimits->limits.maxBindingsPerBindGroup = value;
|
|
365
|
+
} else if (key == "maxDynamicUniformBuffersPerPipelineLayout") {
|
|
366
|
+
requiredLimits->limits.maxDynamicUniformBuffersPerPipelineLayout =
|
|
367
|
+
value;
|
|
368
|
+
} else if (key == "maxDynamicStorageBuffersPerPipelineLayout") {
|
|
369
|
+
requiredLimits->limits.maxDynamicStorageBuffersPerPipelineLayout =
|
|
370
|
+
value;
|
|
371
|
+
} else if (key == "maxSampledTexturesPerShaderStage") {
|
|
372
|
+
requiredLimits->limits.maxSampledTexturesPerShaderStage = value;
|
|
373
|
+
} else if (key == "maxSamplersPerShaderStage") {
|
|
374
|
+
requiredLimits->limits.maxSamplersPerShaderStage = value;
|
|
375
|
+
} else if (key == "maxStorageBuffersPerShaderStage") {
|
|
376
|
+
requiredLimits->limits.maxStorageBuffersPerShaderStage = value;
|
|
377
|
+
} else if (key == "maxStorageTexturesPerShaderStage") {
|
|
378
|
+
requiredLimits->limits.maxStorageTexturesPerShaderStage = value;
|
|
379
|
+
} else if (key == "maxUniformBuffersPerShaderStage") {
|
|
380
|
+
requiredLimits->limits.maxUniformBuffersPerShaderStage = value;
|
|
381
|
+
} else if (key == "maxUniformBufferBindingSize") {
|
|
382
|
+
requiredLimits->limits.maxUniformBufferBindingSize = value;
|
|
383
|
+
} else if (key == "maxStorageBufferBindingSize") {
|
|
384
|
+
requiredLimits->limits.maxStorageBufferBindingSize = value;
|
|
385
|
+
} else if (key == "minUniformBufferOffsetAlignment") {
|
|
386
|
+
requiredLimits->limits.minUniformBufferOffsetAlignment = value;
|
|
387
|
+
} else if (key == "minStorageBufferOffsetAlignment") {
|
|
388
|
+
requiredLimits->limits.minStorageBufferOffsetAlignment = value;
|
|
389
|
+
} else if (key == "maxVertexBuffers") {
|
|
390
|
+
requiredLimits->limits.maxVertexBuffers = value;
|
|
391
|
+
} else if (key == "maxBufferSize") {
|
|
392
|
+
requiredLimits->limits.maxBufferSize = value;
|
|
393
|
+
} else if (key == "maxVertexAttributes") {
|
|
394
|
+
requiredLimits->limits.maxVertexAttributes = value;
|
|
395
|
+
} else if (key == "maxVertexBufferArrayStride") {
|
|
396
|
+
requiredLimits->limits.maxVertexBufferArrayStride = value;
|
|
397
|
+
} else if (key == "maxInterStageShaderComponents") {
|
|
398
|
+
requiredLimits->limits.maxInterStageShaderComponents = value;
|
|
399
|
+
} else if (key == "maxInterStageShaderVariables") {
|
|
400
|
+
requiredLimits->limits.maxInterStageShaderVariables = value;
|
|
401
|
+
} else if (key == "maxColorAttachments") {
|
|
402
|
+
requiredLimits->limits.maxColorAttachments = value;
|
|
403
|
+
} else if (key == "maxColorAttachmentBytesPerSample") {
|
|
404
|
+
requiredLimits->limits.maxColorAttachmentBytesPerSample = value;
|
|
405
|
+
} else if (key == "maxComputeWorkgroupStorageSize") {
|
|
406
|
+
requiredLimits->limits.maxComputeWorkgroupStorageSize = value;
|
|
407
|
+
} else if (key == "maxComputeInvocationsPerWorkgroup") {
|
|
408
|
+
requiredLimits->limits.maxComputeInvocationsPerWorkgroup = value;
|
|
409
|
+
} else if (key == "maxComputeWorkgroupSizeX") {
|
|
410
|
+
requiredLimits->limits.maxComputeWorkgroupSizeX = value;
|
|
411
|
+
} else if (key == "maxComputeWorkgroupSizeY") {
|
|
412
|
+
requiredLimits->limits.maxComputeWorkgroupSizeY = value;
|
|
413
|
+
} else if (key == "maxComputeWorkgroupSizeZ") {
|
|
414
|
+
requiredLimits->limits.maxComputeWorkgroupSizeZ = value;
|
|
415
|
+
} else if (key == "maxComputeWorkgroupsPerDimension") {
|
|
416
|
+
requiredLimits->limits.maxComputeWorkgroupsPerDimension = value;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
out.requiredLimits = requiredLimits;
|
|
420
|
+
}
|
|
421
|
+
return Convert(out.defaultQueue, in.defaultQueue) &&
|
|
422
|
+
Convert(out.label, in.label);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
[[nodiscard]] bool Convert(wgpu::ExternalTextureBindingLayout &out,
|
|
426
|
+
const GPUExternalTextureBindingLayout &in) {
|
|
427
|
+
// no external textures at the moment
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
[[nodiscard]] bool Convert(wgpu::ConstantEntry &out, const std::string &key,
|
|
432
|
+
const double &value) {
|
|
433
|
+
out.key = ConvertStringReplacingNull(key);
|
|
434
|
+
out.value = value;
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
[[nodiscard]] bool Convert(wgpu::FragmentState &out,
|
|
439
|
+
const GPUFragmentState &in) {
|
|
440
|
+
out = {};
|
|
441
|
+
|
|
442
|
+
// Replace nulls in the entryPoint name with another character that's
|
|
443
|
+
// disallowed in WGSL identifiers. This is so that using "main\0" doesn't
|
|
444
|
+
// match an entryPoint named "main".
|
|
445
|
+
out.entryPoint = in.entryPoint
|
|
446
|
+
? ConvertStringReplacingNull(in.entryPoint.value())
|
|
447
|
+
: nullptr;
|
|
448
|
+
return Convert(out.targets, out.targetCount, in.targets) && //
|
|
449
|
+
Convert(out.module, in.module) &&
|
|
450
|
+
Convert(out.constants, out.constantCount, in.constants);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
[[nodiscard]] bool Convert(wgpu::ImageCopyBuffer &out,
|
|
454
|
+
const GPUImageCopyBuffer &in) {
|
|
455
|
+
out = {};
|
|
456
|
+
out.buffer = in.buffer->get();
|
|
457
|
+
return Convert(out.layout.offset, in.offset) &&
|
|
458
|
+
Convert(out.layout.bytesPerRow, in.bytesPerRow) &&
|
|
459
|
+
Convert(out.layout.rowsPerImage, in.rowsPerImage);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
[[nodiscard]] bool Convert(wgpu::ImageCopyTexture &out,
|
|
463
|
+
const GPUImageCopyTexture &in) {
|
|
464
|
+
return Convert(out.origin, in.origin) && Convert(out.texture, in.texture) &&
|
|
465
|
+
Convert(out.mipLevel, in.mipLevel) && Convert(out.aspect, in.aspect);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
[[nodiscard]] bool Convert(wgpu::TextureDataLayout &out,
|
|
469
|
+
const GPUImageDataLayout &in) {
|
|
470
|
+
out = {};
|
|
471
|
+
return Convert(out.bytesPerRow, in.bytesPerRow) &&
|
|
472
|
+
Convert(out.offset, in.offset) &&
|
|
473
|
+
Convert(out.rowsPerImage, in.rowsPerImage);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
[[nodiscard]] bool Convert(wgpu::MultisampleState &out,
|
|
477
|
+
const GPUMultisampleState &in) {
|
|
478
|
+
return Convert(out.count, in.count) && Convert(out.mask, in.mask) &&
|
|
479
|
+
Convert(out.alphaToCoverageEnabled, in.alphaToCoverageEnabled);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
[[nodiscard]] bool Convert(wgpu::PipelineLayoutDescriptor &out,
|
|
483
|
+
const GPUPipelineLayoutDescriptor &in) {
|
|
484
|
+
return Convert(out.bindGroupLayouts, out.bindGroupLayoutCount,
|
|
485
|
+
in.bindGroupLayouts) &&
|
|
486
|
+
Convert(out.label, in.label);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
[[nodiscard]] bool Convert(wgpu::PrimitiveState &out,
|
|
490
|
+
const GPUPrimitiveState &in) {
|
|
491
|
+
out = {};
|
|
492
|
+
|
|
493
|
+
if (in.unclippedDepth) {
|
|
494
|
+
wgpu::PrimitiveDepthClipControl *depthClip =
|
|
495
|
+
Allocate<wgpu::PrimitiveDepthClipControl>();
|
|
496
|
+
depthClip->unclippedDepth = true;
|
|
497
|
+
out.nextInChain = depthClip;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return Convert(out.topology, in.topology) &&
|
|
501
|
+
Convert(out.stripIndexFormat, in.stripIndexFormat) &&
|
|
502
|
+
Convert(out.frontFace, in.frontFace) &&
|
|
503
|
+
Convert(out.cullMode, in.cullMode);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
[[nodiscard]] bool Convert(wgpu::ProgrammableStageDescriptor &out,
|
|
507
|
+
const GPUProgrammableStage &in) {
|
|
508
|
+
out = {};
|
|
509
|
+
out.module = in.module->get();
|
|
510
|
+
|
|
511
|
+
// Replace nulls in the entryPoint name with another character that's
|
|
512
|
+
// disallowed in WGSL identifiers. This is so that using "main\0" doesn't
|
|
513
|
+
// match an entryPoint named "main".
|
|
514
|
+
out.entryPoint = in.entryPoint
|
|
515
|
+
? ConvertStringReplacingNull(in.entryPoint.value())
|
|
516
|
+
: nullptr;
|
|
517
|
+
return Convert(out.constants, out.constantCount, in.constants);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
[[nodiscard]] bool Convert(wgpu::QuerySetDescriptor &out,
|
|
521
|
+
const GPUQuerySetDescriptor &in) {
|
|
522
|
+
return Convert(out.type, in.type) && Convert(out.count, in.count) &&
|
|
523
|
+
Convert(out.label, in.label);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
[[nodiscard]] bool Convert(wgpu::RenderBundleEncoderDescriptor &out,
|
|
527
|
+
const GPURenderBundleEncoderDescriptor &in) {
|
|
528
|
+
return Convert(out.depthReadOnly, in.depthReadOnly) &&
|
|
529
|
+
Convert(out.stencilReadOnly, in.stencilReadOnly) &&
|
|
530
|
+
Convert(out.colorFormats, out.colorFormatCount, in.colorFormats) &&
|
|
531
|
+
Convert(out.depthStencilFormat, in.depthStencilFormat) &&
|
|
532
|
+
Convert(out.sampleCount, in.sampleCount) &&
|
|
533
|
+
Convert(out.label, in.label);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
[[nodiscard]] bool Convert(wgpu::RenderPassColorAttachment &out,
|
|
537
|
+
const GPURenderPassColorAttachment &in) {
|
|
538
|
+
return Convert(out.view, in.view) &&
|
|
539
|
+
Convert(out.depthSlice, in.depthSlice) &&
|
|
540
|
+
Convert(out.resolveTarget, in.resolveTarget) &&
|
|
541
|
+
Convert(out.clearValue, in.clearValue) &&
|
|
542
|
+
Convert(out.loadOp, in.loadOp) && Convert(out.storeOp, in.storeOp);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
[[nodiscard]] bool Convert(wgpu::RenderPassDepthStencilAttachment &out,
|
|
546
|
+
const GPURenderPassDepthStencilAttachment &in) {
|
|
547
|
+
return Convert(out.view, in.view) &&
|
|
548
|
+
Convert(out.depthClearValue, in.depthClearValue) &&
|
|
549
|
+
Convert(out.depthLoadOp, in.depthLoadOp) &&
|
|
550
|
+
Convert(out.depthStoreOp, in.depthStoreOp) &&
|
|
551
|
+
Convert(out.depthReadOnly, in.depthReadOnly) &&
|
|
552
|
+
Convert(out.stencilClearValue, in.stencilClearValue) &&
|
|
553
|
+
Convert(out.stencilLoadOp, in.stencilLoadOp) &&
|
|
554
|
+
Convert(out.stencilStoreOp, in.stencilStoreOp) &&
|
|
555
|
+
Convert(out.stencilReadOnly, in.stencilReadOnly);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
[[nodiscard]] bool Convert(wgpu::RenderPassTimestampWrites &out,
|
|
559
|
+
const GPURenderPassTimestampWrites &in) {
|
|
560
|
+
return Convert(out.querySet, in.querySet) &&
|
|
561
|
+
Convert(out.beginningOfPassWriteIndex,
|
|
562
|
+
in.beginningOfPassWriteIndex) &&
|
|
563
|
+
Convert(out.endOfPassWriteIndex, in.endOfPassWriteIndex);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
[[nodiscard]] bool Convert(wgpu::RenderPipelineDescriptor &out,
|
|
567
|
+
const GPURenderPipelineDescriptor &in) {
|
|
568
|
+
return Convert(out.vertex, in.vertex) &&
|
|
569
|
+
Convert(out.primitive, in.primitive) &&
|
|
570
|
+
Convert(out.depthStencil, in.depthStencil) &&
|
|
571
|
+
Convert(out.multisample, in.multisample) &&
|
|
572
|
+
Convert(out.fragment, in.fragment) &&
|
|
573
|
+
Convert(out.layout, in.layout) && Convert(out.label, in.label);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
[[nodiscard]] bool Convert(wgpu::RequestAdapterOptions &out,
|
|
577
|
+
const GPURequestAdapterOptions &in) {
|
|
578
|
+
return Convert(out.powerPreference, in.powerPreference) &&
|
|
579
|
+
Convert(out.forceFallbackAdapter, in.forceFallbackAdapter);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
[[nodiscard]] bool Convert(wgpu::SamplerBindingLayout &out,
|
|
583
|
+
const GPUSamplerBindingLayout &in) {
|
|
584
|
+
// here the buffer property is set so type is set to its default value
|
|
585
|
+
if (!in.type.has_value()) {
|
|
586
|
+
out.type = wgpu::SamplerBindingType::Filtering;
|
|
587
|
+
}
|
|
588
|
+
return Convert(out.type, in.type);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
[[nodiscard]] bool Convert(wgpu::SamplerDescriptor &out,
|
|
592
|
+
const GPUSamplerDescriptor &in) {
|
|
593
|
+
return Convert(out.addressModeU, in.addressModeU) &&
|
|
594
|
+
Convert(out.addressModeV, in.addressModeV) &&
|
|
595
|
+
Convert(out.addressModeW, in.addressModeW) &&
|
|
596
|
+
Convert(out.magFilter, in.magFilter) &&
|
|
597
|
+
Convert(out.minFilter, in.minFilter) &&
|
|
598
|
+
Convert(out.mipmapFilter, in.mipmapFilter) &&
|
|
599
|
+
Convert(out.lodMinClamp, in.lodMinClamp) &&
|
|
600
|
+
Convert(out.lodMaxClamp, in.lodMaxClamp) &&
|
|
601
|
+
Convert(out.compare, in.compare) &&
|
|
602
|
+
Convert(out.maxAnisotropy, in.maxAnisotropy) &&
|
|
603
|
+
Convert(out.label, in.label);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
[[nodiscard]] bool Convert(wgpu::StencilFaceState &out,
|
|
607
|
+
const GPUStencilFaceState &in) {
|
|
608
|
+
return Convert(out.compare, in.compare) && Convert(out.failOp, in.failOp) &&
|
|
609
|
+
Convert(out.depthFailOp, in.depthFailOp) &&
|
|
610
|
+
Convert(out.passOp, in.passOp);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
[[nodiscard]] bool Convert(wgpu::StorageTextureBindingLayout &out,
|
|
614
|
+
const GPUStorageTextureBindingLayout &in) {
|
|
615
|
+
if (!in.access.has_value()) {
|
|
616
|
+
out.access = wgpu::StorageTextureAccess::WriteOnly;
|
|
617
|
+
}
|
|
618
|
+
return Convert(out.access, in.access) && Convert(out.format, in.format) &&
|
|
619
|
+
Convert(out.viewDimension, in.viewDimension);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
[[nodiscard]] bool Convert(wgpu::TextureBindingLayout &out,
|
|
623
|
+
const GPUTextureBindingLayout &in) {
|
|
624
|
+
if (!in.sampleType.has_value()) {
|
|
625
|
+
out.sampleType = wgpu::TextureSampleType::Float;
|
|
626
|
+
}
|
|
627
|
+
return Convert(out.sampleType, in.sampleType) &&
|
|
628
|
+
Convert(out.viewDimension, in.viewDimension) &&
|
|
629
|
+
Convert(out.multisampled, in.multisampled);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
[[nodiscard]] bool Convert(wgpu::TextureDescriptor &out,
|
|
633
|
+
const GPUTextureDescriptor &in) {
|
|
634
|
+
if (in.viewFormats.has_value()) {
|
|
635
|
+
if (!Convert(out.viewFormats, out.viewFormatCount,
|
|
636
|
+
in.viewFormats.value())) {
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return Convert(out.size, in.size) &&
|
|
641
|
+
Convert(out.mipLevelCount, in.mipLevelCount) &&
|
|
642
|
+
Convert(out.sampleCount, in.sampleCount) &&
|
|
643
|
+
Convert(out.dimension, in.dimension) &&
|
|
644
|
+
Convert(out.format, in.format) && Convert(out.usage, in.usage) &&
|
|
645
|
+
Convert(out.label, in.label);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
[[nodiscard]] bool Convert(wgpu::TextureViewDescriptor &out,
|
|
649
|
+
const GPUTextureViewDescriptor &in) {
|
|
650
|
+
return Convert(out.format, in.format) &&
|
|
651
|
+
Convert(out.dimension, in.dimension) &&
|
|
652
|
+
Convert(out.aspect, in.aspect) &&
|
|
653
|
+
Convert(out.baseMipLevel, in.baseMipLevel) &&
|
|
654
|
+
Convert(out.mipLevelCount, in.mipLevelCount) &&
|
|
655
|
+
Convert(out.baseArrayLayer, in.baseArrayLayer) &&
|
|
656
|
+
Convert(out.arrayLayerCount, in.arrayLayerCount) &&
|
|
657
|
+
Convert(out.label, in.label);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
[[nodiscard]] bool Convert(wgpu::VertexAttribute &out,
|
|
661
|
+
const GPUVertexAttribute &in) {
|
|
662
|
+
return Convert(out.format, in.format) && Convert(out.offset, in.offset) &&
|
|
663
|
+
Convert(out.shaderLocation, in.shaderLocation);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
[[nodiscard]] bool Convert(wgpu::VertexBufferLayout &out,
|
|
667
|
+
const GPUVertexBufferLayout &in) {
|
|
668
|
+
out = {};
|
|
669
|
+
/*
|
|
670
|
+
TODO:
|
|
671
|
+
- if (in.stepMode == wgpu::VertexStepMode::VertexBufferNotUsed) {
|
|
672
|
+
- return Convert(out.stepMode, in.stepMode);
|
|
673
|
+
- }
|
|
674
|
+
*/
|
|
675
|
+
return Convert(out.attributes, out.attributeCount, in.attributes) &&
|
|
676
|
+
Convert(out.arrayStride, in.arrayStride) &&
|
|
677
|
+
Convert(out.stepMode, in.stepMode);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
[[nodiscard]] bool Convert(wgpu::VertexState &out, const GPUVertexState &in) {
|
|
681
|
+
out = {};
|
|
682
|
+
// Replace nulls in the entryPoint name with another character that's
|
|
683
|
+
// disallowed in WGSL identifiers. This is so that using "main\0" doesn't
|
|
684
|
+
// match an entryPoint named "main".
|
|
685
|
+
out.entryPoint = in.entryPoint
|
|
686
|
+
? ConvertStringReplacingNull(in.entryPoint.value())
|
|
687
|
+
: nullptr;
|
|
688
|
+
return Convert(out.module, in.module) &&
|
|
689
|
+
Convert(out.buffers, out.bufferCount, in.buffers) &&
|
|
690
|
+
Convert(out.constants, out.constantCount, in.constants);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
[[nodiscard]] bool Convert(wgpu::CommandBufferDescriptor &out,
|
|
694
|
+
const GPUCommandBufferDescriptor &in) {
|
|
695
|
+
return Convert(out.label, in.label);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
[[nodiscard]] bool Convert(wgpu::CommandEncoderDescriptor &out,
|
|
699
|
+
const GPUCommandEncoderDescriptor &in) {
|
|
700
|
+
return Convert(out.label, in.label);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
[[nodiscard]] bool Convert(wgpu::QueueDescriptor &out,
|
|
704
|
+
const GPUQueueDescriptor &in) {
|
|
705
|
+
return Convert(out.label, in.label);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
[[nodiscard]] bool Convert(wgpu::RenderBundleDescriptor &out,
|
|
709
|
+
const GPURenderBundleDescriptor &in) {
|
|
710
|
+
return Convert(out.label, in.label);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
[[nodiscard]] bool Convert(wgpu::BindGroupEntry &out,
|
|
714
|
+
const GPUBindGroupEntry &in) {
|
|
715
|
+
out = {};
|
|
716
|
+
if (!Convert(out.binding, in.binding)) {
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
if (in.sampler != nullptr) {
|
|
721
|
+
return Convert(out.sampler, in.sampler);
|
|
722
|
+
}
|
|
723
|
+
if (in.textureView != nullptr) {
|
|
724
|
+
return Convert(out.textureView, in.textureView);
|
|
725
|
+
}
|
|
726
|
+
if (in.buffer != nullptr) {
|
|
727
|
+
auto buffer = in.buffer->buffer;
|
|
728
|
+
out.size = wgpu::kWholeSize;
|
|
729
|
+
if (!buffer || !Convert(out.offset, in.buffer->offset) ||
|
|
730
|
+
!Convert(out.size, in.buffer->size)) {
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
out.buffer = buffer->get();
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
// Not external textures at the moment
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
private:
|
|
741
|
+
char *ConvertStringReplacingNull(std::string_view in) {
|
|
742
|
+
char *out = Allocate<char>(in.size() + 1);
|
|
743
|
+
out[in.size()] = '\0';
|
|
744
|
+
|
|
745
|
+
for (size_t i = 0; i < in.size(); i++) {
|
|
746
|
+
if (in[i] == '\0') {
|
|
747
|
+
out[i] = '#';
|
|
748
|
+
} else {
|
|
749
|
+
out[i] = in[i];
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
return out;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
template <typename T> T *Allocate(size_t n = 1) {
|
|
757
|
+
auto *ptr = new T[n]{};
|
|
758
|
+
free_.emplace_back([ptr] { delete[] ptr; });
|
|
759
|
+
return ptr;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
std::vector<std::function<void()>> free_;
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
} // namespace rnwgpu
|