Skip to content

Commit

Permalink
Make QueryType a regular Vulkan enum (vulkano-rs#2438)
Browse files Browse the repository at this point in the history
* Make `QueryType` a regular Vulkan enum

* More consistency with Vulkan
  • Loading branch information
Rua authored and hakolao committed Feb 20, 2024
1 parent 62f6df1 commit 00fc35b
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 291 deletions.
6 changes: 3 additions & 3 deletions vulkano/src/command_buffer/auto/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
},
ComputePipeline, DynamicState, GraphicsPipeline, PipelineBindPoint, PipelineLayout,
},
query::{QueryControlFlags, QueryPool},
query::{QueryControlFlags, QueryPool, QueryType},
range_map::RangeMap,
range_set::RangeSet,
render_pass::{Framebuffer, Subpass},
Expand Down Expand Up @@ -108,7 +108,7 @@ impl RecordingCommandBuffer {
let &CommandBufferInheritanceInfo {
ref render_pass,
occlusion_query: _,
query_statistics_flags: _,
pipeline_statistics: _,
_ne: _,
} = inheritance_info;

Expand Down Expand Up @@ -1209,7 +1209,7 @@ pub(in crate::command_buffer) struct CommandBufferBuilderState {
pub(in crate::command_buffer) viewport_with_count: Option<SmallVec<[Viewport; 2]>>,

// Active queries
pub(in crate::command_buffer) queries: HashMap<ash::vk::QueryType, QueryState>,
pub(in crate::command_buffer) queries: HashMap<QueryType, QueryState>,
}

impl CommandBufferBuilderState {
Expand Down
34 changes: 15 additions & 19 deletions vulkano/src/command_buffer/commands/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ impl RecordingCommandBuffer {
if self
.builder_state
.queries
.contains_key(&ash::vk::QueryType::MESH_PRIMITIVES_GENERATED_EXT)
.contains_key(&QueryType::MeshPrimitivesGenerated)
{
return Err(Box::new(ValidationError {
problem: "a `MeshPrimitivesGenerated` query is currently active".into(),
Expand All @@ -2320,17 +2320,15 @@ impl RecordingCommandBuffer {
if let Some(query_state) = self
.builder_state
.queries
.get(&ash::vk::QueryType::PIPELINE_STATISTICS)
.get(&QueryType::PipelineStatistics)
{
let &QueryType::PipelineStatistics(pipeline_statistics_flags) =
query_state.query_pool.query_type()
else {
unreachable!()
};

if pipeline_statistics_flags.is_mesh_shading_graphics() {
if query_state
.query_pool
.pipeline_statistics()
.is_mesh_shading_graphics()
{
return Err(Box::new(ValidationError {
problem: "a pipeline statistics query is currently active, and its \
problem: "a `PipelineStatistics` query is currently active, and its \
pipeline statistics flags include statistics for mesh shading"
.into(),
vuids: vuids!(vuid_type, "stage-07073"),
Expand Down Expand Up @@ -2385,17 +2383,15 @@ impl RecordingCommandBuffer {
if let Some(query_state) = self
.builder_state
.queries
.get(&ash::vk::QueryType::PIPELINE_STATISTICS)
.get(&QueryType::PipelineStatistics)
{
let &QueryType::PipelineStatistics(pipeline_statistics_flags) =
query_state.query_pool.query_type()
else {
unreachable!()
};

if pipeline_statistics_flags.is_primitive_shading_graphics() {
if query_state
.query_pool
.pipeline_statistics()
.is_primitive_shading_graphics()
{
return Err(Box::new(ValidationError {
problem: "a pipeline statistics query is currently active, and its \
problem: "a `PipelineStatistics` query is currently active, and its \
pipeline statistics flags include statistics for primitive shading"
.into(),
vuids: vuids!(vuid_type, "pipelineStatistics-07076"),
Expand Down
31 changes: 13 additions & 18 deletions vulkano/src/command_buffer/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl RecordingCommandBuffer {
if self
.builder_state
.queries
.contains_key(&query_pool.query_type().into())
.contains_key(&query_pool.query_type())
{
return Err(Box::new(ValidationError {
problem: "a query with the same type as `query_pool.query_type()` is \
Expand Down Expand Up @@ -85,7 +85,7 @@ impl RecordingCommandBuffer {
flags: QueryControlFlags,
) -> &mut Self {
self.builder_state.queries.insert(
query_pool.query_type().into(),
query_pool.query_type(),
QueryState {
query_pool: query_pool.clone(),
query,
Expand Down Expand Up @@ -126,7 +126,7 @@ impl RecordingCommandBuffer {
if !self
.builder_state
.queries
.get(&query_pool.query_type().into())
.get(&query_pool.query_type())
.map_or(false, |state| {
*state.query_pool == *query_pool && state.query == query
})
Expand Down Expand Up @@ -163,8 +163,7 @@ impl RecordingCommandBuffer {
query_pool: Arc<QueryPool>,
query: u32,
) -> &mut Self {
let raw_ty = query_pool.query_type().into();
self.builder_state.queries.remove(&raw_ty);
self.builder_state.queries.remove(&query_pool.query_type());

self.add_command(
"end_query",
Expand Down Expand Up @@ -470,16 +469,15 @@ impl RawRecordingCommandBuffer {
}));
}
}
QueryType::PipelineStatistics(statistic_flags) => {
if statistic_flags.is_graphics()
QueryType::PipelineStatistics => {
if query_pool.pipeline_statistics().is_graphics()
&& !queue_family_properties
.queue_flags
.intersects(QueueFlags::GRAPHICS)
{
return Err(Box::new(ValidationError {
context: "query_pool.query_type()".into(),
problem: "is `QueryType::PipelineStatistics`, and the \
pipeline statistics flags include a graphics flag, but \
problem: "`query_pool.query_type()` is `QueryType::PipelineStatistics`, \
and `query_pool.pipeline_statistics()` includes a graphics flag, but \
the queue family of the command buffer does not support \
graphics operations"
.into(),
Expand All @@ -488,15 +486,14 @@ impl RawRecordingCommandBuffer {
}));
}

if statistic_flags.is_compute()
if query_pool.pipeline_statistics().is_compute()
&& !queue_family_properties
.queue_flags
.intersects(QueueFlags::COMPUTE)
{
return Err(Box::new(ValidationError {
context: "query_pool.query_type()".into(),
problem: "is `QueryType::PipelineStatistics`, and the \
pipeline statistics flags include a compute flag, but \
problem: "`query_pool.query_type()` is `QueryType::PipelineStatistics`, \
and `query_pool.pipeline_statistics()` includes a compute flag, but \
the queue family of the command buffer does not support \
compute operations"
.into(),
Expand Down Expand Up @@ -965,8 +962,7 @@ impl RawRecordingCommandBuffer {
}

let count = queries.end - queries.start;
let per_query_len = query_pool.query_type().result_len()
+ flags.intersects(QueryResultFlags::WITH_AVAILABILITY) as DeviceSize;
let per_query_len = query_pool.result_len(flags);
let required_len = per_query_len * count as DeviceSize;

if destination.len() < required_len {
Expand Down Expand Up @@ -1017,8 +1013,7 @@ impl RawRecordingCommandBuffer {
where
T: QueryResultElement,
{
let per_query_len = query_pool.query_type().result_len()
+ flags.intersects(QueryResultFlags::WITH_AVAILABILITY) as DeviceSize;
let per_query_len = query_pool.result_len(flags);
let stride = per_query_len * std::mem::size_of::<T>() as DeviceSize;

let fns = self.device().fns();
Expand Down
10 changes: 5 additions & 5 deletions vulkano/src/command_buffer/commands/secondary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,18 +422,18 @@ impl RecordingCommandBuffer {
}));
}
}
&QueryType::PipelineStatistics(state_flags) => {
let inherited_flags = inheritance_info.query_statistics_flags;
QueryType::PipelineStatistics => {
let inherited_flags = inheritance_info.pipeline_statistics;

if !inherited_flags.contains(state_flags) {
if !inherited_flags.contains(state.query_pool.pipeline_statistics()) {
return Err(Box::new(ValidationError {
context: format!(
"command_buffers[{}].inheritance_info().query_statistics_flags",
"command_buffers[{}].inheritance_info().pipeline_statistics",
command_buffer_index
)
.into(),
problem: "is not a superset of the flags of the active \
pipeline statistics query"
`PipelineStatistics` query"
.into(),
vuids: &["VUID-vkCmdExecuteCommands-commandBuffer-00104"],
..Default::default()
Expand Down
24 changes: 10 additions & 14 deletions vulkano/src/command_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub struct CommandBufferInheritanceInfo {
/// The default value is `None`.
pub occlusion_query: Option<QueryControlFlags>,

/// Which pipeline statistics queries are allowed to be active on the primary command buffer
/// Which `PipelineStatistics` queries are allowed to be active on the primary command buffer
/// when this secondary command buffer is executed.
///
/// If this value is not empty, the [`pipeline_statistics_query`] feature must be enabled on
Expand All @@ -294,7 +294,7 @@ pub struct CommandBufferInheritanceInfo {
/// The default value is [`QueryPipelineStatisticFlags::empty()`].
///
/// [`pipeline_statistics_query`]: crate::device::Features::pipeline_statistics_query
pub query_statistics_flags: QueryPipelineStatisticFlags,
pub pipeline_statistics: QueryPipelineStatisticFlags,

pub _ne: crate::NonExhaustive,
}
Expand All @@ -305,7 +305,7 @@ impl Default for CommandBufferInheritanceInfo {
Self {
render_pass: None,
occlusion_query: None,
query_statistics_flags: QueryPipelineStatisticFlags::empty(),
pipeline_statistics: QueryPipelineStatisticFlags::empty(),
_ne: crate::NonExhaustive(()),
}
}
Expand All @@ -316,7 +316,7 @@ impl CommandBufferInheritanceInfo {
let &Self {
ref render_pass,
occlusion_query,
query_statistics_flags,
pipeline_statistics,
_ne: _,
} = self;

Expand Down Expand Up @@ -370,18 +370,14 @@ impl CommandBufferInheritanceInfo {
}
}

query_statistics_flags
.validate_device(device)
.map_err(|err| {
err.add_context("query_statistics_flags")
.set_vuids(&["VUID-VkCommandBufferInheritanceInfo-pipelineStatistics-02789"])
})?;
pipeline_statistics.validate_device(device).map_err(|err| {
err.add_context("pipeline_statistics")
.set_vuids(&["VUID-VkCommandBufferInheritanceInfo-pipelineStatistics-02789"])
})?;

if query_statistics_flags.count() > 0
&& !device.enabled_features().pipeline_statistics_query
{
if pipeline_statistics.count() > 0 && !device.enabled_features().pipeline_statistics_query {
return Err(Box::new(ValidationError {
context: "query_statistics_flags".into(),
context: "pipeline_statistics".into(),
problem: "is not empty".into(),
requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature(
"pipeline_statistics_query",
Expand Down
4 changes: 2 additions & 2 deletions vulkano/src/command_buffer/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl RawRecordingCommandBuffer {
let &CommandBufferInheritanceInfo {
ref render_pass,
occlusion_query,
query_statistics_flags,
pipeline_statistics,
_ne: _,
} = inheritance_info;

Expand All @@ -109,7 +109,7 @@ impl RawRecordingCommandBuffer {
framebuffer: ash::vk::Framebuffer::null(),
occlusion_query_enable: ash::vk::FALSE,
query_flags: ash::vk::QueryControlFlags::empty(),
pipeline_statistics: query_statistics_flags.into(),
pipeline_statistics: pipeline_statistics.into(),
..Default::default()
});

Expand Down
Loading

0 comments on commit 00fc35b

Please sign in to comment.