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,58 @@
|
|
|
1
|
+
#include "GPUComputePassEncoder.h"
|
|
2
|
+
|
|
3
|
+
namespace rnwgpu {
|
|
4
|
+
|
|
5
|
+
void GPUComputePassEncoder::setPipeline(
|
|
6
|
+
std::shared_ptr<GPUComputePipeline> pipeline) {
|
|
7
|
+
_instance.SetPipeline(pipeline->get());
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
void GPUComputePassEncoder::end() { _instance.End(); }
|
|
11
|
+
|
|
12
|
+
void GPUComputePassEncoder::setBindGroup(
|
|
13
|
+
uint32_t index,
|
|
14
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
|
|
15
|
+
std::optional<std::vector<uint32_t>> dynamicOffsets) {
|
|
16
|
+
auto dynOffsets = dynamicOffsets.value_or(std::vector<uint32_t>());
|
|
17
|
+
if (dynOffsets.size() == 0) {
|
|
18
|
+
if (std::holds_alternative<std::nullptr_t>(bindGroup)) {
|
|
19
|
+
_instance.SetBindGroup(index, nullptr, 0, nullptr);
|
|
20
|
+
} else {
|
|
21
|
+
auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
|
|
22
|
+
_instance.SetBindGroup(index, group->get(), 0, nullptr);
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
if (std::holds_alternative<std::nullptr_t>(bindGroup)) {
|
|
26
|
+
_instance.SetBindGroup(index, nullptr, dynOffsets.size(),
|
|
27
|
+
dynamicOffsets->data());
|
|
28
|
+
} else {
|
|
29
|
+
auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
|
|
30
|
+
_instance.SetBindGroup(index, group->get(), dynOffsets.size(),
|
|
31
|
+
dynamicOffsets->data());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void GPUComputePassEncoder::dispatchWorkgroups(
|
|
37
|
+
uint32_t workgroupCountX, std::optional<uint32_t> workgroupCountY,
|
|
38
|
+
std::optional<uint32_t> workgroupCountZ) {
|
|
39
|
+
_instance.DispatchWorkgroups(workgroupCountX, workgroupCountY.value_or(1),
|
|
40
|
+
workgroupCountZ.value_or(1));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void GPUComputePassEncoder::dispatchWorkgroupsIndirect(
|
|
44
|
+
std::shared_ptr<GPUBuffer> indirectBuffer, uint64_t indirectOffset) {
|
|
45
|
+
_instance.DispatchWorkgroupsIndirect(indirectBuffer->get(), indirectOffset);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void GPUComputePassEncoder::pushDebugGroup(std::string groupLabel) {
|
|
49
|
+
_instance.PushDebugGroup(groupLabel.c_str());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void GPUComputePassEncoder::popDebugGroup() { _instance.PopDebugGroup(); }
|
|
53
|
+
|
|
54
|
+
void GPUComputePassEncoder::insertDebugMarker(std::string markerLabel) {
|
|
55
|
+
_instance.InsertDebugMarker(markerLabel.c_str());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} // namespace rnwgpu
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <future>
|
|
4
3
|
#include <memory>
|
|
4
|
+
#include <optional>
|
|
5
5
|
#include <string>
|
|
6
|
+
#include <variant>
|
|
7
|
+
#include <vector>
|
|
6
8
|
|
|
7
9
|
#include "Unions.h"
|
|
8
|
-
#include <RNFHybridObject.h>
|
|
9
10
|
|
|
10
|
-
#include "
|
|
11
|
+
#include "RNFHybridObject.h"
|
|
12
|
+
|
|
13
|
+
#include "AsyncRunner.h"
|
|
11
14
|
|
|
12
15
|
#include "webgpu/webgpu_cpp.h"
|
|
13
16
|
|
|
17
|
+
#include "GPUBindGroup.h"
|
|
18
|
+
#include "GPUBuffer.h"
|
|
19
|
+
#include "GPUComputePipeline.h"
|
|
20
|
+
|
|
14
21
|
namespace rnwgpu {
|
|
15
22
|
|
|
16
23
|
namespace m = margelo;
|
|
@@ -25,16 +32,55 @@ public:
|
|
|
25
32
|
public:
|
|
26
33
|
std::string getBrand() { return _name; }
|
|
27
34
|
|
|
35
|
+
void setPipeline(std::shared_ptr<GPUComputePipeline> pipeline);
|
|
36
|
+
void dispatchWorkgroups(uint32_t workgroupCountX,
|
|
37
|
+
std::optional<uint32_t> workgroupCountY,
|
|
38
|
+
std::optional<uint32_t> workgroupCountZ);
|
|
39
|
+
void dispatchWorkgroupsIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
|
|
40
|
+
uint64_t indirectOffset);
|
|
41
|
+
void end();
|
|
42
|
+
void pushDebugGroup(std::string groupLabel);
|
|
43
|
+
void popDebugGroup();
|
|
44
|
+
void insertDebugMarker(std::string markerLabel);
|
|
45
|
+
void setBindGroup(
|
|
46
|
+
uint32_t index,
|
|
47
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
|
|
48
|
+
std::optional<std::vector<uint32_t>> dynamicOffsets);
|
|
49
|
+
|
|
28
50
|
std::string getLabel() { return _label; }
|
|
51
|
+
void setLabel(const std::string &label) {
|
|
52
|
+
_label = label;
|
|
53
|
+
_instance.SetLabel(_label.c_str());
|
|
54
|
+
}
|
|
29
55
|
|
|
30
56
|
void loadHybridMethods() override {
|
|
31
57
|
registerHybridGetter("__brand", &GPUComputePassEncoder::getBrand, this);
|
|
58
|
+
registerHybridMethod("setPipeline", &GPUComputePassEncoder::setPipeline,
|
|
59
|
+
this);
|
|
60
|
+
registerHybridMethod("dispatchWorkgroups",
|
|
61
|
+
&GPUComputePassEncoder::dispatchWorkgroups, this);
|
|
62
|
+
registerHybridMethod("dispatchWorkgroupsIndirect",
|
|
63
|
+
&GPUComputePassEncoder::dispatchWorkgroupsIndirect,
|
|
64
|
+
this);
|
|
65
|
+
registerHybridMethod("end", &GPUComputePassEncoder::end, this);
|
|
66
|
+
registerHybridMethod("pushDebugGroup",
|
|
67
|
+
&GPUComputePassEncoder::pushDebugGroup, this);
|
|
68
|
+
registerHybridMethod("popDebugGroup", &GPUComputePassEncoder::popDebugGroup,
|
|
69
|
+
this);
|
|
70
|
+
registerHybridMethod("insertDebugMarker",
|
|
71
|
+
&GPUComputePassEncoder::insertDebugMarker, this);
|
|
72
|
+
registerHybridMethod("setBindGroup", &GPUComputePassEncoder::setBindGroup,
|
|
73
|
+
this);
|
|
32
74
|
|
|
33
75
|
registerHybridGetter("label", &GPUComputePassEncoder::getLabel, this);
|
|
76
|
+
registerHybridSetter("label", &GPUComputePassEncoder::setLabel, this);
|
|
34
77
|
}
|
|
35
78
|
|
|
79
|
+
inline const wgpu::ComputePassEncoder get() { return _instance; }
|
|
80
|
+
|
|
36
81
|
private:
|
|
37
82
|
wgpu::ComputePassEncoder _instance;
|
|
38
83
|
std::string _label;
|
|
39
84
|
};
|
|
85
|
+
|
|
40
86
|
} // namespace rnwgpu
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#include "GPUComputePipeline.h"
|
|
2
|
+
|
|
3
|
+
namespace rnwgpu {
|
|
4
|
+
|
|
5
|
+
std::shared_ptr<GPUBindGroupLayout>
|
|
6
|
+
GPUComputePipeline::getBindGroupLayout(uint32_t groupIndex) {
|
|
7
|
+
auto bindGroup = _instance.GetBindGroupLayout(groupIndex);
|
|
8
|
+
return std::make_shared<GPUBindGroupLayout>(bindGroup, "");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
} // namespace rnwgpu
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <future>
|
|
4
3
|
#include <memory>
|
|
5
4
|
#include <string>
|
|
6
5
|
|
|
7
6
|
#include "Unions.h"
|
|
8
|
-
#include <RNFHybridObject.h>
|
|
9
7
|
|
|
10
|
-
#include "
|
|
8
|
+
#include "RNFHybridObject.h"
|
|
9
|
+
|
|
10
|
+
#include "AsyncRunner.h"
|
|
11
11
|
|
|
12
12
|
#include "webgpu/webgpu_cpp.h"
|
|
13
13
|
|
|
14
|
+
#include "GPUBindGroupLayout.h"
|
|
15
|
+
|
|
14
16
|
namespace rnwgpu {
|
|
15
17
|
|
|
16
18
|
namespace m = margelo;
|
|
@@ -24,16 +26,29 @@ public:
|
|
|
24
26
|
public:
|
|
25
27
|
std::string getBrand() { return _name; }
|
|
26
28
|
|
|
29
|
+
std::shared_ptr<GPUBindGroupLayout> getBindGroupLayout(uint32_t index);
|
|
30
|
+
|
|
27
31
|
std::string getLabel() { return _label; }
|
|
32
|
+
void setLabel(const std::string &label) {
|
|
33
|
+
_label = label;
|
|
34
|
+
_instance.SetLabel(_label.c_str());
|
|
35
|
+
}
|
|
28
36
|
|
|
29
37
|
void loadHybridMethods() override {
|
|
30
38
|
registerHybridGetter("__brand", &GPUComputePipeline::getBrand, this);
|
|
39
|
+
registerHybridMethod("getBindGroupLayout",
|
|
40
|
+
&GPUComputePipeline::getBindGroupLayout, this);
|
|
31
41
|
|
|
32
42
|
registerHybridGetter("label", &GPUComputePipeline::getLabel, this);
|
|
43
|
+
registerHybridSetter("label", &GPUComputePipeline::setLabel, this);
|
|
33
44
|
}
|
|
34
45
|
|
|
46
|
+
inline const wgpu::ComputePipeline get() { return _instance; }
|
|
47
|
+
|
|
35
48
|
private:
|
|
36
49
|
wgpu::ComputePipeline _instance;
|
|
37
50
|
std::string _label;
|
|
51
|
+
friend class GPUDevice;
|
|
38
52
|
};
|
|
53
|
+
|
|
39
54
|
} // namespace rnwgpu
|
|
@@ -1,12 +1,339 @@
|
|
|
1
1
|
#include "GPUDevice.h"
|
|
2
2
|
|
|
3
|
+
#include <vector>
|
|
4
|
+
|
|
5
|
+
#include "Convertors.h"
|
|
6
|
+
|
|
7
|
+
#include "GPUFeatures.h"
|
|
8
|
+
|
|
3
9
|
namespace rnwgpu {
|
|
4
10
|
|
|
5
11
|
std::shared_ptr<GPUBuffer>
|
|
6
12
|
GPUDevice::createBuffer(std::shared_ptr<GPUBufferDescriptor> descriptor) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
wgpu::BufferDescriptor desc;
|
|
14
|
+
Convertor conv;
|
|
15
|
+
if (!conv(desc, descriptor)) {
|
|
16
|
+
throw std::runtime_error(
|
|
17
|
+
"GPUDevice::createBuffer(): Error with GPUBufferDescriptor");
|
|
18
|
+
}
|
|
19
|
+
auto result = _instance.CreateBuffer(&desc);
|
|
20
|
+
return std::make_shared<GPUBuffer>(result, _async,
|
|
21
|
+
descriptor->label.value_or(""));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
std::shared_ptr<GPUSupportedLimits> GPUDevice::getLimits() {
|
|
25
|
+
wgpu::SupportedLimits limits{};
|
|
26
|
+
if (!_instance.GetLimits(&limits)) {
|
|
27
|
+
throw std::runtime_error("failed to get device limits");
|
|
28
|
+
}
|
|
29
|
+
return std::make_shared<GPUSupportedLimits>(limits);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
std::shared_ptr<GPUQueue> GPUDevice::getQueue() {
|
|
33
|
+
auto result = _instance.GetQueue();
|
|
34
|
+
return std::make_shared<GPUQueue>(result, _async, _label);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
std::shared_ptr<GPUCommandEncoder> GPUDevice::createCommandEncoder(
|
|
38
|
+
std::optional<std::shared_ptr<GPUCommandEncoderDescriptor>> descriptor) {
|
|
39
|
+
wgpu::CommandEncoderDescriptor desc;
|
|
40
|
+
Convertor conv;
|
|
41
|
+
if (!conv(desc, descriptor)) {
|
|
42
|
+
throw std::runtime_error("Error with GPUCommandEncoderDescriptor");
|
|
43
|
+
}
|
|
44
|
+
auto result = _instance.CreateCommandEncoder(&desc);
|
|
45
|
+
return std::make_shared<GPUCommandEncoder>(
|
|
46
|
+
result,
|
|
47
|
+
descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void GPUDevice::destroy() {
|
|
51
|
+
_instance.Destroy();
|
|
52
|
+
auto lostInfo = std::make_shared<GPUDeviceLostInfo>(
|
|
53
|
+
wgpu::DeviceLostReason::Destroyed, "device was destroyed");
|
|
54
|
+
m_lostPromise->set_value(lostInfo);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
std::shared_ptr<GPUTexture>
|
|
58
|
+
GPUDevice::createTexture(std::shared_ptr<GPUTextureDescriptor> descriptor) {
|
|
59
|
+
wgpu::TextureDescriptor desc;
|
|
60
|
+
Convertor conv;
|
|
61
|
+
if (!conv(desc, descriptor)) {
|
|
62
|
+
throw std::runtime_error("Error with GPUTextureDescriptor");
|
|
63
|
+
}
|
|
64
|
+
auto texture = _instance.CreateTexture(&desc);
|
|
65
|
+
return std::make_shared<GPUTexture>(texture, descriptor->label.value_or(""));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
std::shared_ptr<GPUShaderModule> GPUDevice::createShaderModule(
|
|
69
|
+
std::shared_ptr<GPUShaderModuleDescriptor> descriptor) {
|
|
70
|
+
wgpu::ShaderModuleWGSLDescriptor wgsl_desc{};
|
|
71
|
+
wgpu::ShaderModuleDescriptor sm_desc{};
|
|
72
|
+
wgsl_desc.code = descriptor->code.c_str();
|
|
73
|
+
sm_desc.label = descriptor->label.value_or("").c_str();
|
|
74
|
+
sm_desc.nextInChain = &wgsl_desc;
|
|
75
|
+
if (descriptor->code.find('\0') != std::string::npos) {
|
|
76
|
+
return std::make_shared<GPUShaderModule>(
|
|
77
|
+
_instance.CreateErrorShaderModule(
|
|
78
|
+
&sm_desc, "The WGSL shader contains an illegal character '\\0'"),
|
|
79
|
+
_async, descriptor->label.value_or(""));
|
|
80
|
+
}
|
|
81
|
+
auto module = _instance.CreateShaderModule(&sm_desc);
|
|
82
|
+
return std::make_shared<GPUShaderModule>(module, _async,
|
|
83
|
+
descriptor->label.value_or(""));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
std::shared_ptr<GPURenderPipeline> GPUDevice::createRenderPipeline(
|
|
87
|
+
std::shared_ptr<GPURenderPipelineDescriptor> descriptor) {
|
|
88
|
+
wgpu::RenderPipelineDescriptor desc{};
|
|
89
|
+
Convertor conv;
|
|
90
|
+
if (!conv(desc, descriptor)) {
|
|
91
|
+
throw std::runtime_error("Error with GPURenderPipelineDescriptor");
|
|
92
|
+
}
|
|
93
|
+
// assert(desc.fragment != nullptr && "Fragment state must not be null");
|
|
94
|
+
auto renderPipeline = _instance.CreateRenderPipeline(&desc);
|
|
95
|
+
return std::make_shared<GPURenderPipeline>(renderPipeline,
|
|
96
|
+
descriptor->label.value_or(""));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
std::shared_ptr<GPUBindGroup>
|
|
100
|
+
GPUDevice::createBindGroup(std::shared_ptr<GPUBindGroupDescriptor> descriptor) {
|
|
101
|
+
Convertor conv;
|
|
102
|
+
wgpu::BindGroupDescriptor desc{};
|
|
103
|
+
if (!conv(desc.label, descriptor->label) ||
|
|
104
|
+
!conv(desc.layout, descriptor->layout) ||
|
|
105
|
+
!conv(desc.entries, desc.entryCount, descriptor->entries)) {
|
|
106
|
+
throw std::runtime_error(
|
|
107
|
+
"GPUBindGroup::createBindGroup(): Error with GPUBindGroupDescriptor");
|
|
108
|
+
}
|
|
109
|
+
auto bindGroup = _instance.CreateBindGroup(&desc);
|
|
110
|
+
return std::make_shared<GPUBindGroup>(bindGroup,
|
|
111
|
+
descriptor->label.value_or(""));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
std::shared_ptr<GPUSampler> GPUDevice::createSampler(
|
|
115
|
+
std::optional<std::shared_ptr<GPUSamplerDescriptor>> descriptor) {
|
|
116
|
+
wgpu::SamplerDescriptor desc;
|
|
117
|
+
Convertor conv;
|
|
118
|
+
if (!conv(desc, descriptor)) {
|
|
119
|
+
throw std::runtime_error("GPUDevice::createSampler(): Error with "
|
|
120
|
+
"GPUSamplerDescriptor");
|
|
121
|
+
}
|
|
122
|
+
auto sampler = _instance.CreateSampler(&desc);
|
|
123
|
+
return std::make_shared<GPUSampler>(
|
|
124
|
+
sampler,
|
|
125
|
+
descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
|
|
10
126
|
}
|
|
11
127
|
|
|
128
|
+
std::shared_ptr<GPUComputePipeline> GPUDevice::createComputePipeline(
|
|
129
|
+
std::shared_ptr<GPUComputePipelineDescriptor> descriptor) {
|
|
130
|
+
wgpu::ComputePipelineDescriptor desc;
|
|
131
|
+
Convertor conv;
|
|
132
|
+
if (!conv(desc, descriptor)) {
|
|
133
|
+
throw std::runtime_error("GPUDevice::createComputePipeline(): Error with "
|
|
134
|
+
"GPUComputePipelineDescriptor");
|
|
135
|
+
}
|
|
136
|
+
auto computePipeline = _instance.CreateComputePipeline(&desc);
|
|
137
|
+
return std::make_shared<GPUComputePipeline>(computePipeline,
|
|
138
|
+
descriptor->label.value_or(""));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
std::shared_ptr<GPUQuerySet>
|
|
142
|
+
GPUDevice::createQuerySet(std::shared_ptr<GPUQuerySetDescriptor> descriptor) {
|
|
143
|
+
wgpu::QuerySetDescriptor desc;
|
|
144
|
+
Convertor conv;
|
|
145
|
+
if (!conv(desc, descriptor)) {
|
|
146
|
+
throw std::runtime_error("GPUDevice::createQuerySet(): Error with "
|
|
147
|
+
"GPUQuerySetDescriptor");
|
|
148
|
+
}
|
|
149
|
+
auto querySet = _instance.CreateQuerySet(&desc);
|
|
150
|
+
return std::make_shared<GPUQuerySet>(querySet,
|
|
151
|
+
descriptor->label.value_or(""));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
std::shared_ptr<GPURenderBundleEncoder> GPUDevice::createRenderBundleEncoder(
|
|
155
|
+
std::shared_ptr<GPURenderBundleEncoderDescriptor> descriptor) {
|
|
156
|
+
Convertor conv;
|
|
157
|
+
|
|
158
|
+
wgpu::RenderBundleEncoderDescriptor desc{};
|
|
159
|
+
if (!conv(desc.label, descriptor->label) ||
|
|
160
|
+
!conv(desc.colorFormats, desc.colorFormatCount,
|
|
161
|
+
descriptor->colorFormats) ||
|
|
162
|
+
!conv(desc.depthStencilFormat, descriptor->depthStencilFormat) ||
|
|
163
|
+
!conv(desc.sampleCount, descriptor->sampleCount) ||
|
|
164
|
+
!conv(desc.depthReadOnly, descriptor->depthReadOnly) ||
|
|
165
|
+
!conv(desc.stencilReadOnly, descriptor->stencilReadOnly)) {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
return std::make_shared<GPURenderBundleEncoder>(
|
|
169
|
+
_instance.CreateRenderBundleEncoder(&desc),
|
|
170
|
+
descriptor->label.value_or(""));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
std::shared_ptr<GPUBindGroupLayout> GPUDevice::createBindGroupLayout(
|
|
174
|
+
std::shared_ptr<GPUBindGroupLayoutDescriptor> descriptor) {
|
|
175
|
+
Convertor conv;
|
|
176
|
+
|
|
177
|
+
wgpu::BindGroupLayoutDescriptor desc{};
|
|
178
|
+
if (!conv(desc.label, descriptor->label) ||
|
|
179
|
+
!conv(desc.entries, desc.entryCount, descriptor->entries)) {
|
|
180
|
+
return {};
|
|
181
|
+
}
|
|
182
|
+
return std::make_shared<GPUBindGroupLayout>(
|
|
183
|
+
_instance.CreateBindGroupLayout(&desc), descriptor->label.value_or(""));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
std::shared_ptr<GPUPipelineLayout> GPUDevice::createPipelineLayout(
|
|
187
|
+
std::shared_ptr<GPUPipelineLayoutDescriptor> descriptor) {
|
|
188
|
+
Convertor conv;
|
|
189
|
+
|
|
190
|
+
wgpu::PipelineLayoutDescriptor desc{};
|
|
191
|
+
if (!conv(desc.label, descriptor->label) ||
|
|
192
|
+
!conv(desc.bindGroupLayouts, desc.bindGroupLayoutCount,
|
|
193
|
+
descriptor->bindGroupLayouts)) {
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
return std::make_shared<GPUPipelineLayout>(
|
|
197
|
+
_instance.CreatePipelineLayout(&desc), descriptor->label.value_or(""));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
std::shared_ptr<GPUExternalTexture> GPUDevice::importExternalTexture(
|
|
201
|
+
std::shared_ptr<GPUExternalTextureDescriptor> descriptor) {
|
|
202
|
+
throw std::runtime_error(
|
|
203
|
+
"GPUDevice::importExternalTexture(): Not implemented");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
std::future<std::shared_ptr<GPUComputePipeline>>
|
|
207
|
+
GPUDevice::createComputePipelineAsync(
|
|
208
|
+
std::shared_ptr<GPUComputePipelineDescriptor> descriptor) {
|
|
209
|
+
return _async->runAsync([=](wgpu::Instance *instance) {
|
|
210
|
+
wgpu::ComputePipelineDescriptor desc{};
|
|
211
|
+
Convertor conv;
|
|
212
|
+
if (!conv(desc, descriptor)) {
|
|
213
|
+
throw std::runtime_error("GPUDevice::createComputePipeline(): Error with "
|
|
214
|
+
"GPUComputePipelineDescriptor");
|
|
215
|
+
}
|
|
216
|
+
wgpu::ComputePipeline computePipeline = nullptr;
|
|
217
|
+
auto label = std::string(
|
|
218
|
+
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
219
|
+
auto result = std::make_shared<GPUComputePipeline>(computePipeline, label);
|
|
220
|
+
auto future = _instance.CreateComputePipelineAsync(
|
|
221
|
+
&desc, wgpu::CallbackMode::WaitAnyOnly,
|
|
222
|
+
[&result](wgpu::CreatePipelineAsyncStatus status,
|
|
223
|
+
wgpu::ComputePipeline pipeline, char const *msg) {
|
|
224
|
+
switch (status) {
|
|
225
|
+
case wgpu::CreatePipelineAsyncStatus::Success:
|
|
226
|
+
result->_instance = pipeline;
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
throw std::runtime_error(msg);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
instance->WaitAny(future, UINT64_MAX);
|
|
234
|
+
return result;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
std::future<std::shared_ptr<GPURenderPipeline>>
|
|
239
|
+
GPUDevice::createRenderPipelineAsync(
|
|
240
|
+
std::shared_ptr<GPURenderPipelineDescriptor> descriptor) {
|
|
241
|
+
return _async->runAsync([=](wgpu::Instance *instance) {
|
|
242
|
+
wgpu::RenderPipelineDescriptor desc{};
|
|
243
|
+
Convertor conv;
|
|
244
|
+
if (!conv(desc, descriptor)) {
|
|
245
|
+
throw std::runtime_error(
|
|
246
|
+
"GPUDevice::createRenderPipelineAsync(): Error with "
|
|
247
|
+
"GPURenderPipelineDescriptor");
|
|
248
|
+
}
|
|
249
|
+
wgpu::RenderPipeline renderPipeline = nullptr;
|
|
250
|
+
auto label = std::string(
|
|
251
|
+
descriptor->label.has_value() ? descriptor->label.value() : "");
|
|
252
|
+
auto result = std::make_shared<GPURenderPipeline>(renderPipeline, label);
|
|
253
|
+
auto future = _instance.CreateRenderPipelineAsync(
|
|
254
|
+
&desc, wgpu::CallbackMode::WaitAnyOnly,
|
|
255
|
+
[&result](wgpu::CreatePipelineAsyncStatus status,
|
|
256
|
+
wgpu::RenderPipeline pipeline, char const *msg) {
|
|
257
|
+
switch (status) {
|
|
258
|
+
case wgpu::CreatePipelineAsyncStatus::Success:
|
|
259
|
+
result->_instance = pipeline;
|
|
260
|
+
break;
|
|
261
|
+
default:
|
|
262
|
+
throw std::runtime_error(msg);
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
instance->WaitAny(future, UINT64_MAX);
|
|
267
|
+
return result;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
void GPUDevice::pushErrorScope(wgpu::ErrorFilter filter) {
|
|
272
|
+
_instance.PushErrorScope(filter);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
std::future<std::variant<std::nullptr_t, std::shared_ptr<GPUError>>>
|
|
276
|
+
GPUDevice::popErrorScope() {
|
|
277
|
+
return _async->runAsync([=](wgpu::Instance *instance) {
|
|
278
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUError>> result = nullptr;
|
|
279
|
+
auto future = _instance.PopErrorScope(
|
|
280
|
+
wgpu::CallbackMode::WaitAnyOnly,
|
|
281
|
+
[&result](wgpu::PopErrorScopeStatus, wgpu::ErrorType type,
|
|
282
|
+
char const *message) {
|
|
283
|
+
switch (type) {
|
|
284
|
+
case wgpu::ErrorType::NoError:
|
|
285
|
+
break;
|
|
286
|
+
case wgpu::ErrorType::OutOfMemory: {
|
|
287
|
+
result = std::make_shared<GPUError>(wgpu::ErrorType::OutOfMemory,
|
|
288
|
+
message);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case wgpu::ErrorType::Validation: {
|
|
292
|
+
result = std::make_shared<GPUError>(wgpu::ErrorType::Validation,
|
|
293
|
+
message);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
case wgpu::ErrorType::Internal: {
|
|
297
|
+
result =
|
|
298
|
+
std::make_shared<GPUError>(wgpu::ErrorType::Internal, message);
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case wgpu::ErrorType::Unknown:
|
|
302
|
+
case wgpu::ErrorType::DeviceLost:
|
|
303
|
+
result = std::make_shared<GPUError>(wgpu::ErrorType::DeviceLost,
|
|
304
|
+
message);
|
|
305
|
+
break;
|
|
306
|
+
default:
|
|
307
|
+
throw std::runtime_error(
|
|
308
|
+
"unhandled error type (" +
|
|
309
|
+
std::to_string(
|
|
310
|
+
static_cast<std::underlying_type<wgpu::ErrorType>::type>(
|
|
311
|
+
type)) +
|
|
312
|
+
")");
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
instance->WaitAny(future, UINT64_MAX);
|
|
317
|
+
return result;
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
std::unordered_set<std::string> GPUDevice::getFeatures() {
|
|
322
|
+
size_t count = _instance.EnumerateFeatures(nullptr);
|
|
323
|
+
std::vector<wgpu::FeatureName> features(count);
|
|
324
|
+
if (count > 0) {
|
|
325
|
+
_instance.EnumerateFeatures(features.data());
|
|
326
|
+
}
|
|
327
|
+
std::unordered_set<std::string> result;
|
|
328
|
+
for (auto feature : features) {
|
|
329
|
+
std::string name;
|
|
330
|
+
convertEnumToJSUnion(feature, &name);
|
|
331
|
+
result.insert(name);
|
|
332
|
+
}
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
std::future<std::shared_ptr<GPUDeviceLostInfo>> GPUDevice::getLost() {
|
|
337
|
+
return m_lostPromise->get_future();
|
|
338
|
+
}
|
|
12
339
|
} // namespace rnwgpu
|