Skip to content

Commit 0dc499c

Browse files
committed
Fixups for master rebase
1 parent 36ea331 commit 0dc499c

4 files changed

+149
-43
lines changed

drivers/webgpu/rendering_context_driver_webgpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void handle_request_adapter(WGPURequestAdapterStatus status,
2020

2121
RenderingContextDriver::Device device;
2222
device.name = String(info.device.data);
23-
device.vendor = (RenderingContextDriver::Vendor)info.vendorID;
23+
device.vendor = info.vendorID;
2424
device.type = (RenderingContextDriver::DeviceType)info.adapterType;
2525

2626
RenderingContextDriverWebGpu *context = (RenderingContextDriverWebGpu *)userdata;

drivers/webgpu/rendering_device_driver_webgpu.cpp

Lines changed: 119 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,27 @@ Error RenderingDeviceDriverWebGpu::initialize(uint32_t p_device_index, uint32_t
109109
queue = wgpuDeviceGetQueue(device);
110110
ERR_FAIL_COND_V(!this->queue, FAILED);
111111

112-
capabilties = (RenderingDeviceDriver::Capabilities){
112+
capabilties = (Capabilities){
113113
// TODO: This information is not accurate, see modules/glslang/register_types.cpp:78.
114114
.device_family = DEVICE_WEBGPU,
115115
.version_major = 24,
116116
.version_minor = 0,
117117
};
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+
};
118133

119134
return OK;
120135
}
@@ -206,6 +221,11 @@ void RenderingDeviceDriverWebGpu::buffer_unmap(BufferID p_buffer) {
206221
wgpuBufferUnmap(buffer_info->buffer);
207222
}
208223

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+
209229
/*****************/
210230
/**** TEXTURE ****/
211231
/*****************/
@@ -329,7 +349,7 @@ RenderingDeviceDriver::TextureID RenderingDeviceDriverWebGpu::texture_create(con
329349
return TextureID(texture_info);
330350
}
331351

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) {
333353
// TODO: impl
334354
CRASH_NOW_MSG("TODO --> texture_create_from_extension");
335355
}
@@ -462,6 +482,12 @@ BitField<RenderingDeviceDriver::TextureUsageBits> RenderingDeviceDriverWebGpu::t
462482
return supported;
463483
}
464484

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+
465491
/*****************/
466492
/**** SAMPLER ****/
467493
/*****************/
@@ -645,6 +671,11 @@ RenderingDeviceDriver::CommandPoolID RenderingDeviceDriverWebGpu::command_pool_c
645671
return CommandPoolID(command_pool);
646672
}
647673

674+
bool RenderingDeviceDriverWebGpu::command_pool_reset(CommandPoolID p_cmd_pool) {
675+
// TODO: impl
676+
return true;
677+
}
678+
648679
void RenderingDeviceDriverWebGpu::command_pool_free(CommandPoolID p_cmd_pool) {
649680
TightLocalVector<CommandBufferInfo *> *command_pool = (TightLocalVector<CommandBufferInfo *> *)p_cmd_pool.id;
650681
for (uint32_t i = 0; i < command_pool->size(); i++) {
@@ -891,8 +922,10 @@ Vector<uint8_t> RenderingDeviceDriverWebGpu::shader_compile_binary_from_spirv(Ve
891922

892923
for (const ShaderSpecializationConstant &refl_sc : shader_refl.specialization_constants) {
893924
ShaderBinary::SpecializationConstant spec_constant;
925+
spec_constant.type = refl_sc.type;
894926
spec_constant.constant_id = refl_sc.constant_id;
895927
spec_constant.int_value = refl_sc.int_value;
928+
spec_constant.stage_flags = refl_sc.stages;
896929

897930
CharString ascii_name = refl_sc.name.ascii();
898931
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
10251058
return ret;
10261059
}
10271060

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) {
10291062
r_shader_desc = {};
10301063

10311064
// TODO: We allocate memory and call wgpuDeviceCreate*. Perhaps, we should free that memory if we fail.
10321065
ShaderInfo *shader_info = memnew(ShaderInfo);
1033-
*shader_info = { 0 };
1066+
*shader_info = { nullptr };
10341067

10351068
const uint8_t *binptr = p_shader_binary.ptr();
10361069
uint32_t binsize = p_shader_binary.size();
@@ -1059,7 +1092,7 @@ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_
10591092
read_offset += sizeof(uint32_t) * 3 + bin_data_size;
10601093

10611094
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);
10631096
read_offset += STEPIFY(binary_data.shader_name_len, 4);
10641097
}
10651098

@@ -1215,8 +1248,10 @@ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_
12151248
for (uint32_t i = 0; i < binary_data.specialization_constants_count; i++) {
12161249
const ShaderBinary::SpecializationConstant &src_sc = *(reinterpret_cast<const ShaderBinary::SpecializationConstant *>(binptr + read_offset));
12171250
ShaderSpecializationConstant sc;
1251+
sc.type = (PipelineSpecializationConstantType)src_sc.type;
12181252
sc.constant_id = src_sc.constant_id;
12191253
sc.int_value = src_sc.int_value;
1254+
sc.stages = src_sc.stage_flags;
12201255
sc.name = String((char *)src_sc.value_name);
12211256
r_shader_desc.specialization_constants.write[i] = sc;
12221257

@@ -1351,11 +1386,16 @@ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_
13511386
void RenderingDeviceDriverWebGpu::shader_free(ShaderID p_shader) {
13521387
}
13531388

1389+
void RenderingDeviceDriverWebGpu::shader_destroy_modules(ShaderID p_shader) {
1390+
// TODO: impl
1391+
// CRASH_NOW_MSG("TODO --> shader_destroy_modules");
1392+
}
1393+
13541394
/*********************/
13551395
/**** UNIFORM SET ****/
13561396
/*********************/
13571397

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) {
13591399
ShaderInfo *shader_info = (ShaderInfo *)p_shader.id;
13601400

13611401
Vector<WGPUBindGroupEntry> entries;
@@ -1366,7 +1406,7 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
13661406

13671407
switch (uniform.type) {
13681408
case RenderingDeviceCommons::UNIFORM_TYPE_SAMPLER: {
1369-
WGPUBindGroupEntry entry = { 0 };
1409+
WGPUBindGroupEntry entry = { nullptr };
13701410
entry.binding = uniform.binding + binding_offset;
13711411
if (uniform.ids.size() == 1) {
13721412
entry.sampler = (WGPUSampler)uniform.ids[0].id;
@@ -1391,12 +1431,12 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
13911431
entries.push_back(entry);
13921432
} break;
13931433
case RenderingDeviceCommons::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE: {
1394-
WGPUBindGroupEntry texture_entry = { 0 };
1434+
WGPUBindGroupEntry texture_entry = { nullptr };
13951435
texture_entry.binding = uniform.binding + binding_offset;
13961436

13971437
binding_offset += 1;
13981438

1399-
WGPUBindGroupEntry sampler_entry = { 0 };
1439+
WGPUBindGroupEntry sampler_entry = { nullptr };
14001440
sampler_entry.binding = uniform.binding + binding_offset;
14011441

14021442
if (uniform.ids.size() == 2) {
@@ -1445,7 +1485,7 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
14451485
case RenderingDeviceCommons::UNIFORM_TYPE_TEXTURE:
14461486
case RenderingDeviceCommons::UNIFORM_TYPE_IMAGE:
14471487
case RenderingDeviceCommons::UNIFORM_TYPE_INPUT_ATTACHMENT: {
1448-
WGPUBindGroupEntry entry = { 0 };
1488+
WGPUBindGroupEntry entry = { nullptr };
14491489
entry.binding = uniform.binding + binding_offset;
14501490

14511491
if (uniform.ids.size() == 1) {
@@ -1478,7 +1518,7 @@ RenderingDeviceDriver::UniformSetID RenderingDeviceDriverWebGpu::uniform_set_cre
14781518
break;
14791519
case RenderingDeviceCommons::UNIFORM_TYPE_UNIFORM_BUFFER:
14801520
case RenderingDeviceCommons::UNIFORM_TYPE_STORAGE_BUFFER: {
1481-
WGPUBindGroupEntry entry = { 0 };
1521+
WGPUBindGroupEntry entry = { nullptr };
14821522
entry.binding = uniform.binding + binding_offset;
14831523

14841524
BufferInfo *buffer_info = (BufferInfo *)uniform.ids[0].id;
@@ -1734,7 +1774,7 @@ Vector<uint8_t> RenderingDeviceDriverWebGpu::pipeline_cache_serialize() {
17341774

17351775
// ----- SUBPASS -----
17361776

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) {
17381778
// WebGpu does not have subpasses so we will store this info until we create a render pipeline later.
17391779
RenderPassInfo *render_pass_info = memnew(RenderPassInfo);
17401780

@@ -1993,6 +2033,14 @@ void RenderingDeviceDriverWebGpu::command_bind_render_uniform_set(CommandBufferI
19932033
} }));
19942034
}
19952035

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+
19962044
// Drawing.
19972045
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) {
19982046
DEV_ASSERT(p_cmd_buffer != nullptr);
@@ -2194,7 +2242,7 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::render_pipeline_c
21942242
uint32_t p_render_subpass,
21952243
VectorView<PipelineSpecializationConstant> p_specialization_constants) {
21962244
ShaderInfo *shader_info = (ShaderInfo *)p_shader.id;
2197-
WGPURenderPipelineDescriptor pipeline_descriptor = { 0 };
2245+
WGPURenderPipelineDescriptor pipeline_descriptor = { nullptr };
21982246

21992247
// pipeline_descriptor.layout
22002248
pipeline_descriptor.layout = shader_info->pipeline_layout;
@@ -2204,18 +2252,20 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::render_pipeline_c
22042252

22052253
for (int i = 0; i < p_specialization_constants.size(); i++) {
22062254
PipelineSpecializationConstant constant = p_specialization_constants[i];
2207-
union {
2208-
int i;
2209-
double d;
2210-
} val;
2211-
2212-
val.i = constant.int_value;
2213-
22142255
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 },
22182258
};
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;
22192269
}
22202270

22212271
WGPUVertexState vertex_state = (WGPUVertexState){
@@ -2398,7 +2448,7 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::render_pipeline_c
23982448
uint32_t sample_count = pow(2, (uint32_t)p_multisample_state.sample_count);
23992449
pipeline_descriptor.multisample = (WGPUMultisampleState){
24002450
.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,
24022452
.alphaToCoverageEnabled = p_multisample_state.enable_alpha_to_coverage,
24032453
};
24042454

@@ -2447,6 +2497,14 @@ void RenderingDeviceDriverWebGpu::command_bind_compute_uniform_set(CommandBuffer
24472497
});
24482498
}
24492499

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+
24502508
// Dispatching.
24512509
void RenderingDeviceDriverWebGpu::command_compute_dispatch(CommandBufferID p_cmd_buffer, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) {
24522510
DEV_ASSERT(p_cmd_buffer != nullptr);
@@ -2488,18 +2546,20 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::compute_pipeline_
24882546
Vector<WGPUConstantEntry> constants;
24892547
for (int i = 0; i < p_specialization_constants.size(); i++) {
24902548
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+
};
24952553

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+
}
24972561

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);
25032563
}
25042564

25052565
WGPUProgrammableStageDescriptor programmable_stage_desc = (WGPUProgrammableStageDescriptor){
@@ -2555,6 +2615,15 @@ void RenderingDeviceDriverWebGpu::command_timestamp_write(CommandBufferID p_cmd_
25552615
void RenderingDeviceDriverWebGpu::command_begin_label(CommandBufferID p_cmd_buffer, const char *p_label_name, const Color &p_color) {}
25562616
void RenderingDeviceDriverWebGpu::command_end_label(CommandBufferID p_cmd_buffer) {}
25572617

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+
25582627
/********************/
25592628
/**** SUBMISSION ****/
25602629
/********************/
@@ -2574,6 +2643,11 @@ uint64_t RenderingDeviceDriverWebGpu::get_total_memory_used() {
25742643
return 0;
25752644
}
25762645

2646+
uint64_t RenderingDeviceDriverWebGpu::get_lazily_memory_used() {
2647+
// TODO: impl
2648+
return 0;
2649+
}
2650+
25772651
uint64_t RenderingDeviceDriverWebGpu::limit_get(Limit p_limit) {
25782652
WGPUNativeLimits extras;
25792653
WGPULimits limits;
@@ -2600,7 +2674,17 @@ bool RenderingDeviceDriverWebGpu::has_feature(Features p_feature) {
26002674
return false;
26012675
}
26022676

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+
};
26042688

26052689
String RenderingDeviceDriverWebGpu::get_api_name() const {
26062690
return "WebGpu";

0 commit comments

Comments
 (0)