Skip to content

Commit aaf8b98

Browse files
committed
WIP
1 parent aba6c40 commit aaf8b98

File tree

7 files changed

+71
-22
lines changed

7 files changed

+71
-22
lines changed

drivers/webgpu/SCsub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ env.drivers_sources += driver_obj
2020
# Needed to force rebuilding the driver files when the thirdparty code is updated.
2121
env.Depends(driver_obj, thirdparty_obj)
2222

23-
env.Prepend(LIBS=["wgpu_native"])
23+
# env.Prepend(LIBS=["wgpu_native"])
2424
env.Prepend(LIBPATH=[thirdparty_dir])

drivers/webgpu/rendering_context_driver_webgpu.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ static void handle_request_adapter(WGPURequestAdapterStatus status,
1515
status != WGPURequestAdapterStatus_Success, (void)0,
1616
vformat("Failed to get wgpu adapter: %s", message.data));
1717

18+
/*
1819
WGPUAdapterInfo info;
1920
wgpuAdapterGetInfo(adapter, &info);
2021
2122
RenderingContextDriver::Device device;
2223
device.name = String(info.device.data);
2324
device.vendor = info.vendorID;
2425
device.type = (RenderingContextDriver::DeviceType)info.adapterType;
26+
*/
27+
RenderingContextDriver::Device device;
28+
device.name = String("name");
29+
device.vendor = RenderingContextDriver::Vendor::VENDOR_UNKNOWN;
30+
device.type = RenderingContextDriver::DeviceType::DEVICE_TYPE_INTEGRATED_GPU;
2531

2632
RenderingContextDriverWebGpu *context = (RenderingContextDriverWebGpu *)userdata;
2733
context->adapter_push_back(
@@ -42,7 +48,11 @@ RenderingContextDriverWebGpu::~RenderingContextDriverWebGpu() {
4248
}
4349

4450
Error RenderingContextDriverWebGpu::initialize() {
45-
instance = wgpuCreateInstance(nullptr);
51+
WGPUInstanceDescriptor instance_desc = (WGPUInstanceDescriptor){
52+
.features = (WGPUInstanceCapabilities){
53+
.timedWaitAnyEnable = true }
54+
};
55+
instance = wgpuCreateInstance(&instance_desc);
4656

4757
WGPURequestAdapterOptions adapter_options = {};
4858
WGPURequestAdapterCallbackInfo adapter_callback_info = {
@@ -53,18 +63,19 @@ Error RenderingContextDriverWebGpu::initialize() {
5363

5464
// There is no way to request all adapters, so we just get the high and low power ones.
5565

66+
WGPUFutureWaitInfo adapter_futures[2] = {};
67+
5668
adapter_options.powerPreference = WGPUPowerPreference::WGPUPowerPreference_HighPerformance;
57-
wgpuInstanceRequestAdapter(instance,
69+
adapter_futures[0].future = wgpuInstanceRequestAdapter(instance,
5870
&adapter_options,
5971
adapter_callback_info);
6072

6173
adapter_options.powerPreference = WGPUPowerPreference::WGPUPowerPreference_LowPower;
62-
wgpuInstanceRequestAdapter(instance,
63-
&adapter_options,
64-
adapter_callback_info);
74+
adapter_futures[1].future = wgpuInstanceRequestAdapter(instance,
75+
&adapter_options,
76+
adapter_callback_info);
6577

66-
// NOTE: Currently unimplemented in wgpu.
67-
// wgpuInstanceProcessEvents(instance);
78+
wgpuInstanceWaitAny(instance, 2, adapter_futures, UINT64_MAX);
6879

6980
return OK;
7081
}
@@ -83,7 +94,7 @@ bool RenderingContextDriverWebGpu::device_supports_present(uint32_t p_device_ind
8394
DEV_ASSERT(p_device_index < adapters.size());
8495
WGPUAdapter adapter = adapters[p_device_index];
8596
Surface *surface = (Surface *)p_surface;
86-
WGPUSurfaceCapabilities caps;
97+
WGPUSurfaceCapabilities caps = { nullptr };
8798
wgpuSurfaceGetCapabilities(surface->surface, adapter, &caps);
8899
return caps.formatCount != 0;
89100
}
@@ -97,8 +108,11 @@ void RenderingContextDriverWebGpu::driver_free(RenderingDeviceDriver *p_driver)
97108
}
98109

99110
RenderingContextDriver::SurfaceID RenderingContextDriverWebGpu::surface_create(const void *p_platform_data) {
111+
#ifndef WEB_ENABLED
100112
DEV_ASSERT(false && "Surface creation should not be called on the platform-agnostic version of the driver.");
101-
return SurfaceID();
113+
#endif
114+
// Well, it can't just be 0.
115+
return SurfaceID(1);
102116
}
103117

104118
void RenderingContextDriverWebGpu::surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) {

drivers/webgpu/rendering_device_driver_webgpu.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Error RenderingDeviceDriverWebGpu::initialize(uint32_t p_device_index, uint32_t
3939
WGPUFeatureName required_features[] = {
4040
WGPUFeatureName_Depth32FloatStencil8,
4141

42+
/*
4243
// Waiting on WebGPU spec, see https://github.com/gpuweb/gpuweb/blob/main/proposals/push-constants.md
4344
(WGPUFeatureName)WGPUNativeFeature_PushConstants,
4445
// Need to implement shader translation (via naga or tint)
@@ -52,6 +53,7 @@ Error RenderingDeviceDriverWebGpu::initialize(uint32_t p_device_index, uint32_t
5253
(WGPUFeatureName)WGPUNativeFeature_TextureBindingArray,
5354
(WGPUFeatureName)WGPUNativeFeature_StorageResourceBindingArray,
5455
(WGPUFeatureName)WGPUNativeFeature_BufferBindingArray,
56+
*/
5557

5658
// Currently avoidable
5759
// (WGPUFeatureName)WGPUNativeFeature_VertexWritableStorage,
@@ -71,24 +73,29 @@ Error RenderingDeviceDriverWebGpu::initialize(uint32_t p_device_index, uint32_t
7173

7274
WGPULimits required_limits =
7375
(WGPULimits){
74-
.nextInChain = (WGPUChainedStructOut *)&required_native_limits,
76+
// .nextInChain = (WGPUChainedStructOut *)&required_native_limits,
7577
.maxTextureDimension1D = WGPU_LIMIT_U32_UNDEFINED,
7678
.maxTextureDimension2D = WGPU_LIMIT_U32_UNDEFINED,
7779
.maxTextureDimension3D = WGPU_LIMIT_U32_UNDEFINED,
7880
.maxTextureArrayLayers = WGPU_LIMIT_U32_UNDEFINED,
79-
.maxBindGroups = 5,
81+
.maxBindGroups = WGPU_LIMIT_U32_UNDEFINED,
82+
// .maxBindGroups = 5,
8083
.maxBindGroupsPlusVertexBuffers = WGPU_LIMIT_U32_UNDEFINED,
8184
.maxBindingsPerBindGroup = WGPU_LIMIT_U32_UNDEFINED,
8285
.maxDynamicUniformBuffersPerPipelineLayout = WGPU_LIMIT_U32_UNDEFINED,
8386
.maxDynamicStorageBuffersPerPipelineLayout = WGPU_LIMIT_U32_UNDEFINED,
84-
.maxSampledTexturesPerShaderStage = 49,
87+
.maxSampledTexturesPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
88+
// .maxSampledTexturesPerShaderStage = 49,
8589
.maxSamplersPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
8690
.maxStorageBuffersPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
87-
.maxStorageTexturesPerShaderStage = 15,
91+
.maxStorageTexturesPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
92+
// .maxStorageTexturesPerShaderStage = 15,
93+
.maxUniformBuffersPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
8894
// NOTE: I'm not sure why Godot uses 32768 + 272 of these...
89-
.maxUniformBuffersPerShaderStage = 32768 + 272,
95+
// .maxUniformBuffersPerShaderStage = 32768 + 272,
9096
// NOTE: This is my system's max buffer size, needed for some godot examples.
91-
.maxUniformBufferBindingSize = 2147483648,
97+
.maxUniformBufferBindingSize = WGPU_LIMIT_U64_UNDEFINED,
98+
// .maxUniformBufferBindingSize = 2147483648,
9299
.maxStorageBufferBindingSize = WGPU_LIMIT_U64_UNDEFINED,
93100
.minUniformBufferOffsetAlignment = WGPU_LIMIT_U32_UNDEFINED,
94101
.minStorageBufferOffsetAlignment = WGPU_LIMIT_U32_UNDEFINED,
@@ -117,7 +124,11 @@ Error RenderingDeviceDriverWebGpu::initialize(uint32_t p_device_index, uint32_t
117124
.callback = handle_request_device,
118125
.userdata1 = &this->device,
119126
};
120-
wgpuAdapterRequestDevice(adapter, &device_desc, device_callback_info);
127+
WGPUFutureWaitInfo request_device_future = {};
128+
request_device_future.future = wgpuAdapterRequestDevice(adapter, &device_desc, device_callback_info);
129+
130+
wgpuInstanceWaitAny(this->context_driver->instance_get(), 1, &request_device_future, UINT64_MAX);
131+
121132
ERR_FAIL_COND_V(!this->device, FAILED);
122133

123134
queue = wgpuDeviceGetQueue(device);

platform/web/detect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ def configure(env: "SConsEnvironment"):
236236

237237
if env["webgpu"] and env["use_webgpu"]:
238238
env.AppendUnique(CPPDEFINES=["WEBGPU_ENABLED", "RD_ENABLED"])
239-
env.Append(LINKFLAGS=["-sUSE_WEBGPU"])
239+
env.AppendUnique(CPPDEFINES=["EMCC_DEBUG=1"])
240+
env.Append(LINKFLAGS=["--use-port=emdawnwebgpu", "-sJSPI"])
241+
env.Append(CCFLAGS=["-g"])
240242

241243
if env["javascript_eval"]:
242244
env.Append(CPPDEFINES=["JAVASCRIPT_EVAL_ENABLED"])

platform/web/display_server_web.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
#include "drivers/gles3/rasterizer_gles3.h"
4343
#endif
4444

45+
#ifdef WEBGPU_ENABLED
46+
#include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
47+
#endif
48+
4549
#include <emscripten.h>
4650
#include <png.h>
4751

@@ -1129,8 +1133,22 @@ DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode
11291133
rendering_context = memnew(RenderingContextDriverWebGpu);
11301134
rendering_context->initialize();
11311135

1132-
rendering_device = rendering_context->driver_create();
1133-
rendering_device->initialize(0, 2);
1136+
rendering_context->window_create(MAIN_WINDOW_ID, nullptr);
1137+
1138+
rendering_device = memnew(RenderingDevice);
1139+
if (rendering_device->initialize(rendering_context, MAIN_WINDOW_ID) != OK) {
1140+
memdelete(rendering_device);
1141+
rendering_device = nullptr;
1142+
memdelete(rendering_context);
1143+
rendering_context = nullptr;
1144+
r_error = ERR_UNAVAILABLE;
1145+
return;
1146+
}
1147+
rendering_device->screen_create(MAIN_WINDOW_ID);
1148+
1149+
RendererCompositorRD::make_current();
1150+
1151+
RendererCompositorRD::make_current();
11341152
#else
11351153
RasterizerDummy::make_current();
11361154
#endif

platform/web/display_server_web.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "godot_js.h"
3636

3737
#ifdef WEBGPU_ENABLED
38+
#include "servers/rendering/rendering_device.h"
39+
3840
#include "drivers/webgpu/rendering_device_driver_webgpu.h"
3941
#include "drivers/webgpu/rendering_context_driver_webgpu.h"
4042
#endif
@@ -64,8 +66,8 @@ class DisplayServerWeb : public DisplayServer {
6466
#endif
6567

6668
#ifdef RD_ENABLED
67-
RenderingContextDriver* rendering_context;
68-
RenderingDeviceDriver* rendering_device;
69+
RenderingContextDriver* rendering_context = nullptr;
70+
RenderingDevice* rendering_device = nullptr;
6971
#endif
7072

7173
HashMap<int, CharString> utterance_ids;

servers/rendering/rendering_device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "core/config/project_settings.h"
3838
#include "core/io/dir_access.h"
3939

40+
#include <emscripten.h>
41+
4042
#define FORCE_SEPARATE_PRESENT_QUEUE 0
4143
#define PRINT_FRAMEBUFFER_FORMAT 0
4244

0 commit comments

Comments
 (0)