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

Implement some QuerySet getters #314

Merged
merged 3 commits into from
Nov 5, 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
45 changes: 12 additions & 33 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,14 @@ use crate::{follow_chain, map_enum};
use std::num::{NonZeroU32, NonZeroU64};
use std::{borrow::Cow, ffi::CStr};

// Ultimately map_load_op and map_store_op should be able to use the map_enum!
// macro, but not until wgc supports "Undefined" as a valid value. For now the
// "_raw_" map enum version is wrapped into a function that falls back to an
// arbitrary default value.
// (This is the easyfix of https://github.com/gfx-rs/wgpu-native/issues/290)
map_enum!(map_load_op, WGPULoadOp, wgc::command::LoadOp, Clear, Load);
map_enum!(
_raw_map_load_op,
WGPULoadOp,
wgc::command::LoadOp,
//"Unknown load op",
Clear,
Load
);
map_enum!(
_raw_map_store_op,
map_store_op,
WGPUStoreOp,
wgc::command::StoreOp,
//"Unknown store op",
Discard,
Store
);
#[inline]
pub fn map_load_op(value: native::WGPULoadOp) -> wgc::command::LoadOp {
return _raw_map_load_op(value).unwrap_or(wgc::command::LoadOp::Clear);
}
#[inline]
pub fn map_store_op(value: native::WGPUStoreOp) -> wgc::command::StoreOp {
return _raw_map_store_op(value).unwrap_or(wgc::command::StoreOp::Discard);
}
map_enum!(
map_address_mode,
WGPUAddressMode,
Expand Down Expand Up @@ -426,11 +405,12 @@ pub fn write_limits_struct(
limits.maxComputeWorkgroupsPerDimension = wgt_limits.max_compute_workgroups_per_dimension;
supported_limits.limits = limits;

match unsafe { supported_limits.nextInChain.as_ref() } {
Some(native::WGPUChainedStructOut {
sType: native::WGPUSType_SupportedLimitsExtras,
..
}) => unsafe {
if let Some(native::WGPUChainedStructOut {
sType: native::WGPUSType_SupportedLimitsExtras,
..
}) = unsafe { supported_limits.nextInChain.as_ref() }
{
unsafe {
let extras = std::mem::transmute::<
*mut native::WGPUChainedStructOut,
*mut native::WGPUSupportedLimitsExtras,
Expand All @@ -439,8 +419,7 @@ pub fn write_limits_struct(
maxPushConstantSize: wgt_limits.max_push_constant_size,
maxNonSamplerBindings: wgt_limits.max_non_sampler_bindings,
};
},
_ => {}
}
};
}

Expand Down Expand Up @@ -1266,8 +1245,8 @@ pub fn map_bind_group_entry<'a>(
}

#[inline]
pub fn map_bind_group_layout_entry<'a>(
entry: &'a native::WGPUBindGroupLayoutEntry,
pub fn map_bind_group_layout_entry(
entry: &native::WGPUBindGroupLayoutEntry,
extras: Option<&native::WGPUBindGroupLayoutEntryExtras>,
) -> wgt::BindGroupLayoutEntry {
let is_buffer = entry.buffer.type_ != native::WGPUBufferBindingType_Undefined;
Expand Down Expand Up @@ -1368,7 +1347,7 @@ pub fn map_bind_group_layout_entry<'a>(
binding: entry.binding,
visibility: wgt::ShaderStages::from_bits(entry.visibility)
.expect("invalid visibility for bind group layout entry"),
count: extras.map(|v| NonZeroU32::new(v.count)).flatten(),
count: extras.and_then(|v| NonZeroU32::new(v.count)),
}
}

Expand Down
72 changes: 48 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,14 @@ impl Drop for WGPUPipelineLayoutImpl {
}
}

struct QuerySetData {
query_type: native::WGPUQueryType,
query_count: u32,
}
pub struct WGPUQuerySetImpl {
context: Arc<Context>,
id: id::QuerySetId,
data: QuerySetData,
}
impl Drop for WGPUQuerySetImpl {
fn drop(&mut self) {
Expand Down Expand Up @@ -1023,25 +1028,21 @@ 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.and_then(|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();
});

let desc = match descriptor {
Some(descriptor) => wgc::command::ComputePassDescriptor {
Expand Down Expand Up @@ -1081,14 +1082,17 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginRenderPass(
.expect("invalid texture view for depth stencil attachment")
.id,
depth: wgc::command::PassChannel {
load_op: conv::map_load_op(desc.depthLoadOp),
store_op: conv::map_store_op(desc.depthStoreOp),
load_op: conv::map_load_op(desc.depthLoadOp).unwrap_or(wgc::command::LoadOp::Load),
store_op: conv::map_store_op(desc.depthStoreOp)
.unwrap_or(wgc::command::StoreOp::Store),
clear_value: desc.depthClearValue,
read_only: desc.depthReadOnly != 0,
},
stencil: wgc::command::PassChannel {
load_op: conv::map_load_op(desc.stencilLoadOp),
store_op: conv::map_store_op(desc.stencilStoreOp),
load_op: conv::map_load_op(desc.stencilLoadOp)
.unwrap_or(wgc::command::LoadOp::Load),
store_op: conv::map_store_op(desc.stencilStoreOp)
.unwrap_or(wgc::command::StoreOp::Store),
clear_value: desc.stencilClearValue,
read_only: desc.stencilReadOnly != 0,
},
Expand Down Expand Up @@ -1120,8 +1124,10 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginRenderPass(
view: view.id,
resolve_target: color_attachment.resolveTarget.as_ref().map(|v| v.id),
channel: wgc::command::PassChannel {
load_op: conv::map_load_op(color_attachment.loadOp),
store_op: conv::map_store_op(color_attachment.storeOp),
load_op: conv::map_load_op(color_attachment.loadOp)
.expect("invalid load op for render pass color attachment"),
store_op: conv::map_store_op(color_attachment.storeOp)
.expect("invalid store op for render pass color attachment"),
rajveermalviya marked this conversation as resolved.
Show resolved Hide resolved
clear_value: conv::map_color(&color_attachment.clearValue),
read_only: false,
},
Expand Down Expand Up @@ -2010,6 +2016,10 @@ pub unsafe extern "C" fn wgpuDeviceCreateQuerySet(
Arc::into_raw(Arc::new(WGPUQuerySetImpl {
context: context.clone(),
id: query_set_id,
data: QuerySetData {
query_type: descriptor.type_,
query_count: descriptor.count,
},
}))
}

Expand Down Expand Up @@ -2753,6 +2763,20 @@ pub unsafe extern "C" fn wgpuQuerySetDestroy(_query_set: native::WGPUQuerySet) {
//TODO: needs to be implemented in wgpu-core
}

#[no_mangle]
pub unsafe extern "C" fn wgpuQuerySetGetCount(query_set: native::WGPUQuerySet) -> u32 {
let query_set = query_set.as_ref().expect("invalid query set");
query_set.data.query_count
}

#[no_mangle]
pub unsafe extern "C" fn wgpuQuerySetGetType(
query_set: native::WGPUQuerySet,
) -> native::WGPUQueryType {
let query_set = query_set.as_ref().expect("invalid query set");
query_set.data.query_type
}

#[no_mangle]
pub unsafe extern "C" fn wgpuQuerySetReference(query_set: native::WGPUQuerySet) {
assert!(!query_set.is_null(), "invalid query set");
Expand Down
10 changes: 0 additions & 10 deletions src/unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,6 @@ pub extern "C" fn wgpuPipelineLayoutSetLabel(
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuQuerySetGetCount(_query_set: native::WGPUQuerySet) -> u32 {
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuQuerySetGetType(_query_set: native::WGPUQuerySet) -> native::WGPUQueryType {
unimplemented!();
}

#[no_mangle]
pub extern "C" fn wgpuQuerySetSetLabel(
_query_set: native::WGPUQuerySet,
Expand Down
Loading