Skip to content

Commit e2f762a

Browse files
committed
Fix all crashes for non MSAA 2d samples
- add use of push constant stage flags - extra checking for depth attachment - fix warning regarding get_pipeline_cache_uuid - all 2d samples fixed as long as msaa disabled
1 parent 73763db commit e2f762a

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

drivers/webgpu/rendering_device_driver_webgpu.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,10 @@ RenderingDeviceDriver::TextureID RenderingDeviceDriverWebGpu::texture_create(con
335335
},
336336
};
337337

338-
// HACK: You cannot have a Depth24PlusStencil8 or Depth32FloatStencil8 texture view.
338+
// HACK: You cannot have a Depth24PlusStencil8 or Depth32FloatStencil8 texture view be bound.
339339
if (view_format == WGPUTextureFormat_Depth24PlusStencil8) {
340340
view_format = WGPUTextureFormat_Depth24Plus;
341341
aspect = WGPUTextureAspect_DepthOnly;
342-
343342
} else if (view_format == WGPUTextureFormat_Depth32FloatStencil8) {
344343
view_format = WGPUTextureFormat_Depth32Float;
345344
aspect = WGPUTextureAspect_DepthOnly;
@@ -1397,6 +1396,7 @@ RenderingDeviceDriver::ShaderID RenderingDeviceDriverWebGpu::shader_create_from_
13971396
.end = binary_data.push_constant_size,
13981397
};
13991398
}
1399+
shader_info->push_constant_stage_flags = binary_data.push_constant_stages;
14001400

14011401
WGPUPipelineLayoutExtras wgpu_pipeline_extras = (WGPUPipelineLayoutExtras){
14021402
.chain = (WGPUChainedStruct){
@@ -1794,18 +1794,18 @@ void RenderingDeviceDriverWebGpu::command_bind_push_constants(CommandBufferID p_
17941794
data.resize(byte_size);
17951795
memcpy(data.ptrw(), p_data.ptr(), byte_size);
17961796

1797-
if (shader_info->stage_flags & WGPUShaderStage_Compute) {
1797+
if (shader_info->push_constant_stage_flags & WGPUShaderStage_Compute) {
17981798
command_buffer_info->active_compute_pass_info.commands.push_back((ComputePassEncoderCommand){
17991799
.type = ComputePassEncoderCommand::CommandType::SET_PUSH_CONSTANTS,
18001800
.set_push_constants = (ComputePassEncoderCommand::SetPushConstants){
18011801
.offset = p_first_index },
18021802
.push_constant_data = data,
18031803
});
1804-
} else if (shader_info->stage_flags & WGPUShaderStage_Vertex || shader_info->stage_flags & WGPUShaderStage_Fragment) {
1804+
} else if (shader_info->push_constant_stage_flags & WGPUShaderStage_Vertex || shader_info->push_constant_stage_flags & WGPUShaderStage_Fragment) {
18051805
command_buffer_info->active_render_pass_info.commands.push_back((RenderPassEncoderCommand){
18061806
.type = RenderPassEncoderCommand::CommandType::SET_PUSH_CONSTANTS,
18071807
.set_push_constants = (RenderPassEncoderCommand::SetPushConstants){
1808-
.stages = shader_info->stage_flags,
1808+
.stages = shader_info->push_constant_stage_flags,
18091809
.offset = p_first_index },
18101810
.push_constant_data = data });
18111811
}
@@ -1887,7 +1887,7 @@ void RenderingDeviceDriverWebGpu::command_begin_render_pass(CommandBufferID p_cm
18871887
for (uint32_t i = 0; i < render_pass_info->attachments.size(); i++) {
18881888
RenderPassAttachmentInfo attachment = render_pass_info->attachments[i];
18891889

1890-
if (attachment.is_depth_stencil) {
1890+
if (attachment.is_depth_stencil || attachment.is_depth_stencil_read_only) {
18911891
TextureID attachment_texture_id = framebuffer_info->attachments[i];
18921892
TextureInfo *attachment_texture = (TextureInfo *)attachment_texture_id.id;
18931893
maybe_depth_stencil_attachment.first = (WGPURenderPassDepthStencilAttachment){
@@ -2491,9 +2491,22 @@ RenderingDeviceDriver::PipelineID RenderingDeviceDriverWebGpu::render_pipeline_c
24912491
pipeline_descriptor.primitive = primitive_state;
24922492

24932493
// pipeline_descriptor.depth_stencil
2494-
// HACK: This behavior isn't accurate?
2495-
if (p_depth_stencil_state.enable_depth_write) {
2496-
WGPUDepthStencilState depth_stencil_state = (WGPUDepthStencilState){
2494+
WGPUDepthStencilState depth_stencil_state;
2495+
2496+
// HACK: Whether a depth stencil state should be attached isn't always reported, so let's walk the render pass'
2497+
// attachments to double check.
2498+
bool use_depth = p_depth_stencil_state.enable_depth_write || p_depth_stencil_state.enable_depth_test || p_depth_stencil_state.enable_depth_range || p_depth_stencil_state.enable_stencil;
2499+
2500+
for (uint32_t i = 0; i < render_pass_info->attachments.size(); i++) {
2501+
const RenderPassAttachmentInfo &attachment = render_pass_info->attachments[i];
2502+
if (attachment.is_depth_stencil || attachment.is_depth_stencil_read_only) {
2503+
use_depth = true;
2504+
break;
2505+
}
2506+
}
2507+
2508+
if (use_depth) {
2509+
depth_stencil_state = (WGPUDepthStencilState){
24972510
// TODO: We do not have info on depth target format.
24982511
.format = WGPUTextureFormat_Depth32Float,
24992512
.depthWriteEnabled = p_depth_stencil_state.enable_depth_write ? WGPUOptionalBool_True : WGPUOptionalBool_False,
@@ -2781,7 +2794,10 @@ String RenderingDeviceDriverWebGpu::get_api_version() const {
27812794
return "v24.0.0 (wgpu)";
27822795
}
27832796

2784-
String RenderingDeviceDriverWebGpu::get_pipeline_cache_uuid() const {}
2797+
String RenderingDeviceDriverWebGpu::get_pipeline_cache_uuid() const {
2798+
// TODO: impl
2799+
return "webgpu";
2800+
}
27852801

27862802
const RenderingDeviceDriver::Capabilities &RenderingDeviceDriverWebGpu::get_capabilities() const {
27872803
return capabilties;

drivers/webgpu/rendering_device_driver_webgpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ class RenderingDeviceDriverWebGpu : public RenderingDeviceDriver {
448448
WGPU_NULLABLE WGPUShaderModule compute_shader;
449449

450450
WGPUShaderStage stage_flags;
451+
WGPUShaderStage push_constant_stage_flags;
451452

452453
Vector<WGPUBindGroupLayout> bind_group_layouts;
453454
// Maps `constant_id` to override key name

thirdparty/wgpu/wgpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ typedef struct WGPUTextureViewSwizzle {
270270

271271
typedef struct WGPUTextureViewDescriptorExtras {
272272
WGPUChainedStruct chain;
273-
WGPUTextureViewSwizzle swizzle;
273+
WGPUTextureViewSwizzle swizzle;
274274
} WGPUTextureViewExtras;
275275

276276
#ifdef __cplusplus

0 commit comments

Comments
 (0)