Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support occlusion query #300

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ pub fn map_instance_descriptor(
backends: map_instance_backend_flags(extras.backends as native::WGPUInstanceBackend),
dx12_shader_compiler,
gles_minor_version: map_gles3_minor_version(extras.gles3MinorVersion),

}
} else {
wgt::InstanceDescriptor::default()
Expand Down
66 changes: 47 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use conv::{
map_device_descriptor, map_instance_backend_flags, map_instance_descriptor,
map_pipeline_layout_descriptor, map_primitive_state, map_shader_module, map_surface,
map_query_set_index,
CreateSurfaceParams,
map_pipeline_layout_descriptor, map_primitive_state, map_query_set_index, map_shader_module,
map_surface, CreateSurfaceParams,
};
use parking_lot::{Mutex, RwLock};
use smallvec::SmallVec;
Expand Down Expand Up @@ -997,19 +996,25 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginComputePass(
)
};

let timestamp_writes = descriptor.map(|descriptor| {
descriptor.timestampWrites.as_ref().map(|timestamp_write| {
wgc::command::ComputePassTimestampWrites {
query_set:
timestamp_write.querySet
.as_ref()
.expect("invalid query set in timestamp writes")
.id,
beginning_of_pass_write_index: map_query_set_index(timestamp_write.beginningOfPassWriteIndex),
end_of_pass_write_index: map_query_set_index(timestamp_write.endOfPassWriteIndex),
}
let timestamp_writes = descriptor
.map(|descriptor| {
descriptor.timestampWrites.as_ref().map(|timestamp_write| {
wgc::command::ComputePassTimestampWrites {
query_set: timestamp_write
.querySet
.as_ref()
.expect("invalid query set in timestamp writes")
.id,
beginning_of_pass_write_index: map_query_set_index(
timestamp_write.beginningOfPassWriteIndex,
),
end_of_pass_write_index: map_query_set_index(
timestamp_write.endOfPassWriteIndex,
),
}
})
})
}).flatten();
.flatten();

let desc = match descriptor {
Some(descriptor) => wgc::command::ComputePassDescriptor {
Expand Down Expand Up @@ -1065,12 +1070,14 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginRenderPass(

let timestamp_writes = descriptor.timestampWrites.as_ref().map(|timestamp_write| {
wgc::command::RenderPassTimestampWrites {
query_set:
timestamp_write.querySet
query_set: timestamp_write
.querySet
.as_ref()
.expect("invalid query set in timestamp writes")
.id,
beginning_of_pass_write_index: map_query_set_index(timestamp_write.beginningOfPassWriteIndex),
beginning_of_pass_write_index: map_query_set_index(
timestamp_write.beginningOfPassWriteIndex,
),
end_of_pass_write_index: map_query_set_index(timestamp_write.endOfPassWriteIndex),
}
});
Expand Down Expand Up @@ -1098,7 +1105,7 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginRenderPass(
),
depth_stencil_attachment: depth_stencil_attachment.as_ref(),
timestamp_writes: timestamp_writes.as_ref(),
occlusion_query_set: None, // TODO:
occlusion_query_set: descriptor.occlusionQuerySet.as_ref().map(|v| v.id),
};

Arc::into_raw(Arc::new(WGPURenderPassEncoderImpl {
Expand Down Expand Up @@ -3249,6 +3256,17 @@ pub unsafe extern "C" fn wgpuRenderBundleEncoderRelease(

// RenderPassEncoder methods

#[no_mangle]
pub unsafe extern "C" fn wgpuRenderPassEncoderBeginOcclusionQuery(
pass: native::WGPURenderPassEncoder,
query_index: u32,
) {
let pass = pass.as_ref().expect("invalid render pass");
let mut encoder = pass.encoder.write();

render_ffi::wgpu_render_pass_begin_occlusion_query(&mut encoder, query_index);
}

#[no_mangle]
pub unsafe extern "C" fn wgpuRenderPassEncoderBeginPipelineStatisticsQuery(
pass: native::WGPURenderPassEncoder,
Expand Down Expand Up @@ -3355,6 +3373,16 @@ pub unsafe extern "C" fn wgpuRenderPassEncoderEnd(pass: native::WGPURenderPassEn
}
}

#[no_mangle]
pub unsafe extern "C" fn wgpuRenderPassEncoderEndOcclusionQuery(
pass: native::WGPURenderPassEncoder,
) {
let pass = pass.as_ref().expect("invalid render pass");
let mut encoder = pass.encoder.write();

render_ffi::wgpu_render_pass_end_occlusion_query(&mut encoder);
}

#[no_mangle]
pub unsafe extern "C" fn wgpuRenderPassEncoderEndPipelineStatisticsQuery(
pass: native::WGPURenderPassEncoder,
Expand Down
15 changes: 0 additions & 15 deletions src/unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ pub extern "C" fn wgpuRenderBundleEncoderSetLabel(
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuRenderPassEncoderBeginOcclusionQuery(
_render_pass_encoder: native::WGPURenderPassEncoder,
_query_index: u32,
) {
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuRenderPassEncoderEndOcclusionQuery(
_render_pass_encoder: native::WGPURenderPassEncoder,
) {
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuRenderPassEncoderSetLabel(
_render_pass_encoder: native::WGPURenderPassEncoder,
Expand Down
Loading