@@ -109,12 +109,27 @@ Error RenderingDeviceDriverWebGpu::initialize(uint32_t p_device_index, uint32_t
109
109
queue = wgpuDeviceGetQueue (device);
110
110
ERR_FAIL_COND_V (!this ->queue , FAILED);
111
111
112
- capabilties = (RenderingDeviceDriver:: Capabilities){
112
+ capabilties = (Capabilities){
113
113
// TODO: This information is not accurate, see modules/glslang/register_types.cpp:78.
114
114
.device_family = DEVICE_WEBGPU,
115
115
.version_major = 24 ,
116
116
.version_minor = 0 ,
117
117
};
118
+ multiview_capabilities = (MultiviewCapabilities) {
119
+ .is_supported = false ,
120
+ };
121
+ fdm_capabilities = (FragmentDensityMapCapabilities) {
122
+ .attachment_supported = false ,
123
+ .dynamic_attachment_supported = false ,
124
+ .non_subsampled_images_supported = false ,
125
+ .invocations_supported = false ,
126
+ .offset_supported = false ,
127
+ };
128
+ fsr_capabilities = (FragmentShadingRateCapabilities) {
129
+ .pipeline_supported = false ,
130
+ .primitive_supported = false ,
131
+ .attachment_supported = false ,
132
+ };
118
133
119
134
return OK;
120
135
}
@@ -206,6 +221,11 @@ void RenderingDeviceDriverWebGpu::buffer_unmap(BufferID p_buffer) {
206
221
wgpuBufferUnmap (buffer_info->buffer );
207
222
}
208
223
224
+ uint64_t RenderingDeviceDriverWebGpu::buffer_get_device_address (BufferID p_buffer) {
225
+ // TODO: impl
226
+ CRASH_NOW_MSG (" TODO --> buffer_get_device_address" );
227
+ }
228
+
209
229
/* ****************/
210
230
/* *** TEXTURE ****/
211
231
/* ****************/
@@ -329,7 +349,7 @@ RenderingDeviceDriver::TextureID RenderingDeviceDriverWebGpu::texture_create(con
329
349
return TextureID (texture_info);
330
350
}
331
351
332
- RenderingDeviceDriver::TextureID RenderingDeviceDriverWebGpu::texture_create_from_extension (uint64_t p_native_texture, TextureType p_type, DataFormat p_format, uint32_t p_array_layers, bool p_depth_stencil) {
352
+ RenderingDeviceDriver::TextureID RenderingDeviceDriverWebGpu::texture_create_from_extension (uint64_t p_native_texture, TextureType p_type, DataFormat p_format, uint32_t p_array_layers, bool p_depth_stencil, uint32_t p_mipmaps ) {
333
353
// TODO: impl
334
354
CRASH_NOW_MSG (" TODO --> texture_create_from_extension" );
335
355
}
@@ -462,6 +482,12 @@ BitField<RenderingDeviceDriver::TextureUsageBits> RenderingDeviceDriverWebGpu::t
462
482
return supported;
463
483
}
464
484
485
+ bool RenderingDeviceDriverWebGpu::texture_can_make_shared_with_format (TextureID p_texture, DataFormat p_format, bool &r_raw_reinterpretation) {
486
+ // TODO: impl
487
+ // CRASH_NOW_MSG("TODO --> texture_can_make_shared_with_format");
488
+ return true ;
489
+ }
490
+
465
491
/* ****************/
466
492
/* *** SAMPLER ****/
467
493
/* ****************/
@@ -645,6 +671,11 @@ RenderingDeviceDriver::CommandPoolID RenderingDeviceDriverWebGpu::command_pool_c
645
671
return CommandPoolID (command_pool);
646
672
}
647
673
674
+ bool RenderingDeviceDriverWebGpu::command_pool_reset (CommandPoolID p_cmd_pool) {
675
+ // TODO: impl
676
+ return true ;
677
+ }
678
+
648
679
void RenderingDeviceDriverWebGpu::command_pool_free (CommandPoolID p_cmd_pool) {
649
680
TightLocalVector<CommandBufferInfo *> *command_pool = (TightLocalVector<CommandBufferInfo *> *)p_cmd_pool.id ;
650
681
for (uint32_t i = 0 ; i < command_pool->size (); i++) {
@@ -891,8 +922,10 @@ Vector<uint8_t> RenderingDeviceDriverWebGpu::shader_compile_binary_from_spirv(Ve
891
922
892
923
for (const ShaderSpecializationConstant &refl_sc : shader_refl.specialization_constants ) {
893
924
ShaderBinary::SpecializationConstant spec_constant;
925
+ spec_constant.type = refl_sc.type ;
894
926
spec_constant.constant_id = refl_sc.constant_id ;
895
927
spec_constant.int_value = refl_sc.int_value ;
928
+ spec_constant.stage_flags = refl_sc.stages ;
896
929
897
930
CharString ascii_name = refl_sc.name .ascii ();
898
931
ERR_FAIL_COND_V (ascii_name.size () > ShaderBinary::SpecializationConstant::OVERRIDE_CONSTANT_STRLEN, Vector<uint8_t >());
@@ -1025,12 +1058,12 @@ Vector<uint8_t> RenderingDeviceDriverWebGpu::shader_compile_binary_from_spirv(Ve
1025
1058
return ret;
1026
1059
}
1027
1060
1028
- RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_bytecode (const Vector<uint8_t > &p_shader_binary, ShaderDescription &r_shader_desc, String &r_name) {
1061
+ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_bytecode (const Vector<uint8_t > &p_shader_binary, ShaderDescription &r_shader_desc, String &r_name, const Vector<ImmutableSampler> &p_immutable_samplers ) {
1029
1062
r_shader_desc = {};
1030
1063
1031
1064
// TODO: We allocate memory and call wgpuDeviceCreate*. Perhaps, we should free that memory if we fail.
1032
1065
ShaderInfo *shader_info = memnew (ShaderInfo);
1033
- *shader_info = { 0 };
1066
+ *shader_info = { nullptr };
1034
1067
1035
1068
const uint8_t *binptr = p_shader_binary.ptr ();
1036
1069
uint32_t binsize = p_shader_binary.size ();
@@ -1059,7 +1092,7 @@ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_
1059
1092
read_offset += sizeof (uint32_t ) * 3 + bin_data_size;
1060
1093
1061
1094
if (binary_data.shader_name_len ) {
1062
- r_name. parse_utf8 ((const char *)(binptr + read_offset), binary_data.shader_name_len );
1095
+ r_name = String::utf8 ((const char *)(binptr + read_offset), binary_data.shader_name_len );
1063
1096
read_offset += STEPIFY (binary_data.shader_name_len , 4 );
1064
1097
}
1065
1098
@@ -1215,8 +1248,10 @@ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_
1215
1248
for (uint32_t i = 0 ; i < binary_data.specialization_constants_count ; i++) {
1216
1249
const ShaderBinary::SpecializationConstant &src_sc = *(reinterpret_cast <const ShaderBinary::SpecializationConstant *>(binptr + read_offset));
1217
1250
ShaderSpecializationConstant sc;
1251
+ sc.type = (PipelineSpecializationConstantType)src_sc.type ;
1218
1252
sc.constant_id = src_sc.constant_id ;
1219
1253
sc.int_value = src_sc.int_value ;
1254
+ sc.stages = src_sc.stage_flags ;
1220
1255
sc.name = String ((char *)src_sc.value_name );
1221
1256
r_shader_desc.specialization_constants .write [i] = sc;
1222
1257
@@ -1351,11 +1386,16 @@ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_
1351
1386
void RenderingDeviceDriverWebGpu::shader_free (ShaderID p_shader) {
1352
1387
}
1353
1388
1389
+ void RenderingDeviceDriverWebGpu::shader_destroy_modules (ShaderID p_shader) {
1390
+ // TODO: impl
1391
+ // CRASH_NOW_MSG("TODO --> shader_destroy_modules");
1392
+ }
1393
+
1354
1394
/* ********************/
1355
1395
/* *** UNIFORM SET ****/
1356
1396
/* ********************/
1357
1397
1358
- RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_create (VectorView<BoundUniform> p_uniforms, ShaderID p_shader, uint32_t p_set_index) {
1398
+ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_create (VectorView<BoundUniform> p_uniforms, ShaderID p_shader, uint32_t p_set_index, int p_linear_pool_index ) {
1359
1399
ShaderInfo *shader_info = (ShaderInfo *)p_shader.id ;
1360
1400
1361
1401
Vector<WGPUBindGroupEntry> entries;
@@ -1366,7 +1406,7 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
1366
1406
1367
1407
switch (uniform.type ) {
1368
1408
case RenderingDeviceCommons::UNIFORM_TYPE_SAMPLER: {
1369
- WGPUBindGroupEntry entry = { 0 };
1409
+ WGPUBindGroupEntry entry = { nullptr };
1370
1410
entry.binding = uniform.binding + binding_offset;
1371
1411
if (uniform.ids .size () == 1 ) {
1372
1412
entry.sampler = (WGPUSampler)uniform.ids [0 ].id ;
@@ -1391,12 +1431,12 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
1391
1431
entries.push_back (entry);
1392
1432
} break ;
1393
1433
case RenderingDeviceCommons::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE: {
1394
- WGPUBindGroupEntry texture_entry = { 0 };
1434
+ WGPUBindGroupEntry texture_entry = { nullptr };
1395
1435
texture_entry.binding = uniform.binding + binding_offset;
1396
1436
1397
1437
binding_offset += 1 ;
1398
1438
1399
- WGPUBindGroupEntry sampler_entry = { 0 };
1439
+ WGPUBindGroupEntry sampler_entry = { nullptr };
1400
1440
sampler_entry.binding = uniform.binding + binding_offset;
1401
1441
1402
1442
if (uniform.ids .size () == 2 ) {
@@ -1445,7 +1485,7 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
1445
1485
case RenderingDeviceCommons::UNIFORM_TYPE_TEXTURE:
1446
1486
case RenderingDeviceCommons::UNIFORM_TYPE_IMAGE:
1447
1487
case RenderingDeviceCommons::UNIFORM_TYPE_INPUT_ATTACHMENT: {
1448
- WGPUBindGroupEntry entry = { 0 };
1488
+ WGPUBindGroupEntry entry = { nullptr };
1449
1489
entry.binding = uniform.binding + binding_offset;
1450
1490
1451
1491
if (uniform.ids .size () == 1 ) {
@@ -1478,7 +1518,7 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
1478
1518
break ;
1479
1519
case RenderingDeviceCommons::UNIFORM_TYPE_UNIFORM_BUFFER:
1480
1520
case RenderingDeviceCommons::UNIFORM_TYPE_STORAGE_BUFFER: {
1481
- WGPUBindGroupEntry entry = { 0 };
1521
+ WGPUBindGroupEntry entry = { nullptr };
1482
1522
entry.binding = uniform.binding + binding_offset;
1483
1523
1484
1524
BufferInfo *buffer_info = (BufferInfo *)uniform.ids [0 ].id ;
@@ -1734,7 +1774,7 @@ Vector<uint8_t> RenderingDeviceDriverWebGpu::pipeline_cache_serialize() {
1734
1774
1735
1775
// ----- SUBPASS -----
1736
1776
1737
- RenderingDeviceDriver::RenderPassID RenderingDeviceDriverWebGpu::render_pass_create (VectorView<Attachment> p_attachments, VectorView<Subpass> _p_subpasses, VectorView<SubpassDependency> _p_subpass_dependencies, uint32_t p_view_count) {
1777
+ RenderingDeviceDriver::RenderPassID RenderingDeviceDriverWebGpu::render_pass_create (VectorView<Attachment> p_attachments, VectorView<Subpass> _p_subpasses, VectorView<SubpassDependency> _p_subpass_dependencies, uint32_t p_view_count, AttachmentReference p_fragment_density_map_attachment ) {
1738
1778
// WebGpu does not have subpasses so we will store this info until we create a render pipeline later.
1739
1779
RenderPassInfo *render_pass_info = memnew (RenderPassInfo);
1740
1780
@@ -1993,6 +2033,14 @@ void RenderingDeviceDriverWebGpu::command_bind_render_uniform_set(CommandBufferI
1993
2033
} }));
1994
2034
}
1995
2035
2036
+ void RenderingDeviceDriverWebGpu::command_bind_render_uniform_sets (CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count) {
2037
+ // TODO: impl
2038
+ // CRASH_NOW_MSG("TODO --> command_bind_render_uniform_sets");
2039
+ for (uint32_t i = 0 ; i < p_set_count; i++) {
2040
+ command_bind_render_uniform_set (p_cmd_buffer, p_uniform_sets[i], p_shader, p_first_set_index + i);
2041
+ }
2042
+ }
2043
+
1996
2044
// Drawing.
1997
2045
void RenderingDeviceDriverWebGpu::command_render_draw (CommandBufferID p_cmd_buffer, uint32_t p_vertex_count, uint32_t p_instance_count, uint32_t p_base_vertex, uint32_t p_first_instance) {
1998
2046
DEV_ASSERT (p_cmd_buffer != nullptr );
@@ -2194,7 +2242,7 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::render_pipeline_c
2194
2242
uint32_t p_render_subpass,
2195
2243
VectorView<PipelineSpecializationConstant> p_specialization_constants) {
2196
2244
ShaderInfo *shader_info = (ShaderInfo *)p_shader.id ;
2197
- WGPURenderPipelineDescriptor pipeline_descriptor = { 0 };
2245
+ WGPURenderPipelineDescriptor pipeline_descriptor = { nullptr };
2198
2246
2199
2247
// pipeline_descriptor.layout
2200
2248
pipeline_descriptor.layout = shader_info->pipeline_layout ;
@@ -2204,18 +2252,20 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::render_pipeline_c
2204
2252
2205
2253
for (int i = 0 ; i < p_specialization_constants.size (); i++) {
2206
2254
PipelineSpecializationConstant constant = p_specialization_constants[i];
2207
- union {
2208
- int i;
2209
- double d;
2210
- } val;
2211
-
2212
- val.i = constant.int_value ;
2213
-
2214
2255
CharString key_name = shader_info->override_keys [constant.constant_id ].ascii ();
2215
- constants[i] = (WGPUConstantEntry){
2216
- .key = { key_name, WGPU_STRLEN },
2217
- .value = val.d ,
2256
+ WGPUConstantEntry entry = (WGPUConstantEntry){
2257
+ .key = { key_name.ptr (), WGPU_STRLEN },
2218
2258
};
2259
+
2260
+ if (constant.type == PipelineSpecializationConstantType::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT) {
2261
+ entry.value = (double )constant.float_value ;
2262
+ } else if (constant.type == PipelineSpecializationConstantType::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT) {
2263
+ entry.value = (double )constant.int_value ;
2264
+ } else {
2265
+ entry.value = (double )constant.bool_value ;
2266
+ }
2267
+
2268
+ constants[i] = entry;
2219
2269
}
2220
2270
2221
2271
WGPUVertexState vertex_state = (WGPUVertexState){
@@ -2398,7 +2448,7 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::render_pipeline_c
2398
2448
uint32_t sample_count = pow (2 , (uint32_t )p_multisample_state.sample_count );
2399
2449
pipeline_descriptor.multisample = (WGPUMultisampleState){
2400
2450
.count = sample_count,
2401
- .mask = p_multisample_state.sample_mask .size () ? *p_multisample_state.sample_mask .ptr () : ! 0 ,
2451
+ .mask = p_multisample_state.sample_mask .size () ? *p_multisample_state.sample_mask .ptr () : ~ 0 ,
2402
2452
.alphaToCoverageEnabled = p_multisample_state.enable_alpha_to_coverage ,
2403
2453
};
2404
2454
@@ -2447,6 +2497,14 @@ void RenderingDeviceDriverWebGpu::command_bind_compute_uniform_set(CommandBuffer
2447
2497
});
2448
2498
}
2449
2499
2500
+ void RenderingDeviceDriverWebGpu::command_bind_compute_uniform_sets (CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count) {
2501
+ // TODO: impl
2502
+ // CRASH_NOW_MSG("TODO --> command_bind_compute_uniform_sets");
2503
+ for (uint32_t i = 0 ; i < p_set_count; i++) {
2504
+ command_bind_compute_uniform_set (p_cmd_buffer, p_uniform_sets[i], p_shader, p_first_set_index + i);
2505
+ }
2506
+ }
2507
+
2450
2508
// Dispatching.
2451
2509
void RenderingDeviceDriverWebGpu::command_compute_dispatch (CommandBufferID p_cmd_buffer, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) {
2452
2510
DEV_ASSERT (p_cmd_buffer != nullptr );
@@ -2488,18 +2546,20 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::compute_pipeline_
2488
2546
Vector<WGPUConstantEntry> constants;
2489
2547
for (int i = 0 ; i < p_specialization_constants.size (); i++) {
2490
2548
PipelineSpecializationConstant constant = p_specialization_constants[i];
2491
- union {
2492
- int i;
2493
- double d;
2494
- } val ;
2549
+ CharString key_name = shader_info-> override_keys [constant. constant_id ]. ascii ();
2550
+ WGPUConstantEntry entry = (WGPUConstantEntry){
2551
+ . key = { key_name. ptr (), WGPU_STRLEN },
2552
+ };
2495
2553
2496
- val.i = constant.int_value ;
2554
+ if (constant.type == PipelineSpecializationConstantType::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT) {
2555
+ entry.value = (double )constant.float_value ;
2556
+ } else if (constant.type == PipelineSpecializationConstantType::PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT) {
2557
+ entry.value = (double )constant.int_value ;
2558
+ } else {
2559
+ entry.value = (double )constant.bool_value ;
2560
+ }
2497
2561
2498
- CharString key_name = shader_info->override_keys [constant.constant_id ].ascii ();
2499
- constants.push_back ((WGPUConstantEntry){
2500
- .key = { key_name, WGPU_STRLEN },
2501
- .value = val.d ,
2502
- });
2562
+ constants.push_back (entry);
2503
2563
}
2504
2564
2505
2565
WGPUProgrammableStageDescriptor programmable_stage_desc = (WGPUProgrammableStageDescriptor){
@@ -2555,6 +2615,15 @@ void RenderingDeviceDriverWebGpu::command_timestamp_write(CommandBufferID p_cmd_
2555
2615
void RenderingDeviceDriverWebGpu::command_begin_label (CommandBufferID p_cmd_buffer, const char *p_label_name, const Color &p_color) {}
2556
2616
void RenderingDeviceDriverWebGpu::command_end_label (CommandBufferID p_cmd_buffer) {}
2557
2617
2618
+ /* ***************/
2619
+ /* *** DEBUG *****/
2620
+ /* ***************/
2621
+
2622
+ void RenderingDeviceDriverWebGpu::command_insert_breadcrumb (CommandBufferID p_cmd_buffer, uint32_t p_data) {
2623
+ // TODO: impl
2624
+ // CRASH_NOW_MSG("TODO --> command_insert_breadcrumb");
2625
+ }
2626
+
2558
2627
/* *******************/
2559
2628
/* *** SUBMISSION ****/
2560
2629
/* *******************/
@@ -2574,6 +2643,11 @@ uint64_t RenderingDeviceDriverWebGpu::get_total_memory_used() {
2574
2643
return 0 ;
2575
2644
}
2576
2645
2646
+ uint64_t RenderingDeviceDriverWebGpu::get_lazily_memory_used () {
2647
+ // TODO: impl
2648
+ return 0 ;
2649
+ }
2650
+
2577
2651
uint64_t RenderingDeviceDriverWebGpu::limit_get (Limit p_limit) {
2578
2652
WGPUNativeLimits extras;
2579
2653
WGPULimits limits;
@@ -2600,7 +2674,17 @@ bool RenderingDeviceDriverWebGpu::has_feature(Features p_feature) {
2600
2674
return false ;
2601
2675
}
2602
2676
2603
- const RenderingDeviceDriver::MultiviewCapabilities &RenderingDeviceDriverWebGpu::get_multiview_capabilities () {}
2677
+ const RenderingDeviceDriver::MultiviewCapabilities &RenderingDeviceDriverWebGpu::get_multiview_capabilities () {
2678
+ return multiview_capabilities;
2679
+ }
2680
+
2681
+ const RenderingDeviceDriver::FragmentShadingRateCapabilities &RenderingDeviceDriverWebGpu::get_fragment_shading_rate_capabilities () {
2682
+ return fsr_capabilities;
2683
+ }
2684
+
2685
+ const RenderingDeviceDriver::FragmentDensityMapCapabilities &RenderingDeviceDriverWebGpu::get_fragment_density_map_capabilities () {
2686
+ return fdm_capabilities;
2687
+ };
2604
2688
2605
2689
String RenderingDeviceDriverWebGpu::get_api_name () const {
2606
2690
return " WebGpu" ;
0 commit comments