Skip to content

Commit

Permalink
support for ext_conservative_rasterization (#2508)
Browse files Browse the repository at this point in the history
* disabled bad validation code

* conservative rasterization

* validation for conservative_rasterization

* rebuild

* extra_primitive_overestimation_size dynamic state

* safety fixed

* set builder state

* formatted

* unfixed fake bug fix

* actually unfixed fake bug fix

* fixed bad formatting

* deleted duplicate todo

* command buffer documentation

* formatted

* add vuid

Co-authored-by: Rua <ruawhitepaw@gmail.com>

* add vuid

Co-authored-by: Rua <ruawhitepaw@gmail.com>

* more validation

* Update vulkano/src/pipeline/graphics/mod.rs

Co-authored-by: Rua <ruawhitepaw@gmail.com>

* Update vulkano/src/pipeline/graphics/mod.rs

Co-authored-by: Rua <ruawhitepaw@gmail.com>

* Update vulkano/src/pipeline/graphics/mod.rs

Co-authored-by: Rua <ruawhitepaw@gmail.com>

* Update vulkano/src/pipeline/graphics/mod.rs

Co-authored-by: Rua <ruawhitepaw@gmail.com>

* put in block

* add todo

* fixed clippy

* removed redundant checks

---------

Co-authored-by: Rua <ruawhitepaw@gmail.com>
  • Loading branch information
LukeP0WERS and Rua authored Mar 29, 2024
1 parent 78f3f9f commit 5dab2df
Show file tree
Hide file tree
Showing 6 changed files with 560 additions and 25 deletions.
45 changes: 26 additions & 19 deletions vulkano/src/command_buffer/auto/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
pipeline::{
graphics::{
color_blend::LogicOp,
conservative_rasterization::ConservativeRasterizationMode,
depth_stencil::{CompareOp, StencilOps},
input_assembly::PrimitiveTopology,
rasterization::{CullMode, DepthBiasState, FrontFace, LineStipple},
Expand Down Expand Up @@ -1207,6 +1208,9 @@ pub(in crate::command_buffer) struct CommandBufferBuilderState {
pub(in crate::command_buffer) vertex_input: Option<VertexInputState>,
pub(in crate::command_buffer) viewport: HashMap<u32, Viewport>,
pub(in crate::command_buffer) viewport_with_count: Option<SmallVec<[Viewport; 2]>>,
pub(in crate::command_buffer) conservative_rasterization_mode:
Option<ConservativeRasterizationMode>,
pub(in crate::command_buffer) extra_primitive_overestimation_size: Option<f32>,

// Active queries
pub(in crate::command_buffer) queries: HashMap<QueryType, QueryState>,
Expand Down Expand Up @@ -1275,25 +1279,28 @@ impl CommandBufferBuilderState {
// DynamicState::ColorBlendEquation => todo!(),
// DynamicState::ColorWriteMask => todo!(),
// DynamicState::RasterizationStream => todo!(),
// DynamicState::ConservativeRasterizationMode => todo!(),
// DynamicState::ExtraPrimitiveOverestimationSize => todo!(),
// DynamicState::DepthClipEnable => todo!(),
// DynamicState::SampleLocationsEnable => todo!(),
// DynamicState::ColorBlendAdvanced => todo!(),
// DynamicState::ProvokingVertexMode => todo!(),
// DynamicState::LineRasterizationMode => todo!(),
// DynamicState::LineStippleEnable => todo!(),
// DynamicState::DepthClipNegativeOneToOne => todo!(),
// DynamicState::ViewportWScalingEnable => todo!(),
// DynamicState::ViewportSwizzle => todo!(),
// DynamicState::CoverageToColorEnable => todo!(),
// DynamicState::CoverageToColorLocation => todo!(),
// DynamicState::CoverageModulationMode => todo!(),
// DynamicState::CoverageModulationTableEnable => todo!(),
// DynamicState::CoverageModulationTable => todo!(),
// DynamicState::ShadingRateImageEnable => todo!(),
// DynamicState::RepresentativeFragmentTestEnable => todo!(),
// DynamicState::CoverageReductionMode => todo!(),
DynamicState::ConservativeRasterizationMode => {
self.conservative_rasterization_mode = None
}
DynamicState::ExtraPrimitiveOverestimationSize => {
self.extra_primitive_overestimation_size = None
} /* DynamicState::DepthClipEnable => todo!(),
* DynamicState::SampleLocationsEnable => todo!(),
* DynamicState::ColorBlendAdvanced => todo!(),
* DynamicState::ProvokingVertexMode => todo!(),
* DynamicState::LineRasterizationMode => todo!(),
* DynamicState::LineStippleEnable => todo!(),
* DynamicState::DepthClipNegativeOneToOne => todo!(),
* DynamicState::ViewportWScalingEnable => todo!(),
* DynamicState::ViewportSwizzle => todo!(),
* DynamicState::CoverageToColorEnable => todo!(),
* DynamicState::CoverageToColorLocation => todo!(),
* DynamicState::CoverageModulationMode => todo!(),
* DynamicState::CoverageModulationTableEnable => todo!(),
* DynamicState::CoverageModulationTable => todo!(),
* DynamicState::ShadingRateImageEnable => todo!(),
* DynamicState::RepresentativeFragmentTestEnable => todo!(),
* DynamicState::CoverageReductionMode => todo!(), */
}
}
}
Expand Down
226 changes: 226 additions & 0 deletions vulkano/src/command_buffer/commands/dynamic_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
pipeline::{
graphics::{
color_blend::LogicOp,
conservative_rasterization::ConservativeRasterizationMode,
depth_stencil::{CompareOp, StencilFaces, StencilOp, StencilOps},
input_assembly::PrimitiveTopology,
rasterization::{CullMode, DepthBiasState, FrontFace, LineStipple},
Expand Down Expand Up @@ -1196,6 +1197,91 @@ impl RecordingCommandBuffer {

self
}

/// Sets the dynamic conservative rasterization mode for future draw calls.
#[inline]
pub fn set_conservative_rasterization_mode(
&mut self,
conservative_rasterization_mode: ConservativeRasterizationMode,
) -> Result<&mut Self, Box<ValidationError>> {
self.validate_set_conservative_rasterization_mode()?;

unsafe {
Ok(self.set_conservative_rasterization_mode_unchecked(conservative_rasterization_mode))
}
}

fn validate_set_conservative_rasterization_mode(&self) -> Result<(), Box<ValidationError>> {
self.inner.validate_set_conservative_rasterization_mode()?;

self.validate_graphics_pipeline_fixed_state(DynamicState::ConservativeRasterizationMode)?;

Ok(())
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn set_conservative_rasterization_mode_unchecked(
&mut self,
conservative_rasterization_mode: ConservativeRasterizationMode,
) -> &mut Self {
self.builder_state.conservative_rasterization_mode = Some(conservative_rasterization_mode);

self.add_command(
"set_conservative_rasterization_mode",
Default::default(),
move |out: &mut RawRecordingCommandBuffer| {
out.set_conservative_rasterization_mode_unchecked(conservative_rasterization_mode);
},
);

self
}

/// Sets the dynamic extra primitive overestimation size for future draw calls.
#[inline]
pub fn set_extra_primitive_overestimation_size(
&mut self,
extra_primitive_overestimation_size: f32,
) -> Result<&mut Self, Box<ValidationError>> {
self.validate_set_extra_primitive_overestimation_size()?;

unsafe {
Ok(self.set_extra_primitive_overestimation_size_unchecked(
extra_primitive_overestimation_size,
))
}
}

fn validate_set_extra_primitive_overestimation_size(&self) -> Result<(), Box<ValidationError>> {
self.inner.validate_set_conservative_rasterization_mode()?;

self.validate_graphics_pipeline_fixed_state(
DynamicState::ExtraPrimitiveOverestimationSize,
)?;

Ok(())
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn set_extra_primitive_overestimation_size_unchecked(
&mut self,
extra_primitive_overestimation_size: f32,
) -> &mut Self {
self.builder_state.extra_primitive_overestimation_size =
Some(extra_primitive_overestimation_size);

self.add_command(
"set_extra_primitive_overestimation_size",
Default::default(),
move |out: &mut RawRecordingCommandBuffer| {
out.set_extra_primitive_overestimation_size_unchecked(
extra_primitive_overestimation_size,
);
},
);

self
}
}

impl RawRecordingCommandBuffer {
Expand Down Expand Up @@ -3186,4 +3272,144 @@ impl RawRecordingCommandBuffer {

self
}

#[inline]
pub unsafe fn set_conservative_rasterization_mode(
&mut self,
conservative_rasterization_mode: ConservativeRasterizationMode,
) -> Result<&mut Self, Box<ValidationError>> {
self.validate_set_conservative_rasterization_mode()?;

Ok(self.set_conservative_rasterization_mode_unchecked(conservative_rasterization_mode))
}

fn validate_set_conservative_rasterization_mode(&self) -> Result<(), Box<ValidationError>> {
if !(self
.device()
.enabled_features()
.extended_dynamic_state3_conservative_rasterization_mode)
{
return Err(Box::new(ValidationError {
requires_one_of: RequiresOneOf(&[
RequiresAllOf(&[Requires::DeviceFeature(
"extended_dynamic_state3_conservative_rasterization_mode",
)]),
RequiresAllOf(&[Requires::DeviceFeature("shader_object")]),
]),
vuids: &["VUID-vkCmdSetConservativeRasterizationModeEXT-None-09423"],
..Default::default()
}));
}

if !self
.queue_family_properties()
.queue_flags
.intersects(QueueFlags::GRAPHICS)
{
return Err(Box::new(ValidationError {
problem: "the queue family of the command buffer does not support \
graphics operations"
.into(),
vuids: &["VUID-vkCmdSetConservativeRasterizationModeEXT-commandBuffer-cmdpool"],
..Default::default()
}));
}

Ok(())
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn set_conservative_rasterization_mode_unchecked(
&mut self,
conservative_rasterization_mode: ConservativeRasterizationMode,
) -> &mut Self {
let fns = self.device().fns();
(fns.ext_extended_dynamic_state3
.cmd_set_conservative_rasterization_mode_ext)(
self.handle(),
conservative_rasterization_mode.into(),
);

self
}

#[inline]
pub unsafe fn set_extra_primitive_overestimation_size(
&mut self,
extra_primitive_overestimation_size: f32,
) -> Result<&mut Self, Box<ValidationError>> {
self.validate_set_extra_primitive_overestimation_size(extra_primitive_overestimation_size)?;

Ok(self
.set_extra_primitive_overestimation_size_unchecked(extra_primitive_overestimation_size))
}

fn validate_set_extra_primitive_overestimation_size(
&self,
extra_primitive_overestimation_size: f32,
) -> Result<(), Box<ValidationError>> {
let properties = self.device().physical_device().properties();

if !(self
.device()
.enabled_features()
.extended_dynamic_state3_extra_primitive_overestimation_size)
{
return Err(Box::new(ValidationError {
requires_one_of: RequiresOneOf(&[
RequiresAllOf(&[Requires::DeviceFeature(
"extended_dynamic_state3_extra_primitive_overestimation_size",
)]),
RequiresAllOf(&[Requires::DeviceFeature("shader_object")]),
]),
vuids: &["VUID-vkCmdSetExtraPrimitiveOverestimationSizeEXT-None-09423"],
..Default::default()
}));
}

if !self
.queue_family_properties()
.queue_flags
.intersects(QueueFlags::GRAPHICS)
{
return Err(Box::new(ValidationError {
problem: "the queue family of the command buffer does not support \
graphics operations"
.into(),
vuids: &["VUID-vkCmdSetExtraPrimitiveOverestimationSizeEXT-commandBuffer-cmdpool"],
..Default::default()
}));
}

if extra_primitive_overestimation_size < 0.0
|| extra_primitive_overestimation_size
> properties.max_extra_primitive_overestimation_size.unwrap()
{
return Err(Box::new(ValidationError {
context: "overestimation size".into(),
problem: "the overestimation size is not in the range of 0.0 to `max_extra_primitive_overestimation_size` inclusive".into(),
vuids: &[
"VUID-vkCmdSetExtraPrimitiveOverestimationSizeEXT-extraPrimitiveOverestimationSize-07428",
],
..Default::default()
}));
}

Ok(())
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn set_extra_primitive_overestimation_size_unchecked(
&mut self,
extra_primitive_overestimation_size: f32,
) -> &mut Self {
let fns = self.device().fns();
(fns.ext_extended_dynamic_state3
.cmd_set_extra_primitive_overestimation_size_ext)(
self.handle(),
extra_primitive_overestimation_size,
);

self
}
}
37 changes: 37 additions & 0 deletions vulkano/src/command_buffer/commands/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,43 @@ impl RecordingCommandBuffer {
// the viewportCount parameter of
// vkCmdSetViewportWithCountEXT must be 1
}
DynamicState::ConservativeRasterizationMode => {
if self.builder_state.conservative_rasterization_mode.is_none() {
return Err(Box::new(ValidationError {
problem: format!(
"the currently bound graphics pipeline requires the \
`DynamicState::{:?}` dynamic state, but \
this state was either not set, or it was overwritten by a \
more recent `bind_pipeline_graphics` command",
dynamic_state
)
.into(),
vuids: vuids!(vuid_type, "None-07631"),
..Default::default()
}));
}
// TODO: VUID-vkCmdDraw-conservativePointAndLineRasterization-07499
}
DynamicState::ExtraPrimitiveOverestimationSize => {
if self
.builder_state
.extra_primitive_overestimation_size
.is_none()
{
return Err(Box::new(ValidationError {
problem: format!(
"the currently bound graphics pipeline requires the \
`DynamicState::{:?}` dynamic state, but \
this state was either not set, or it was overwritten by a \
more recent `bind_pipeline_graphics` command",
dynamic_state
)
.into(),
vuids: vuids!(vuid_type, "None-07632"),
..Default::default()
}));
}
}
}
}

Expand Down
Loading

0 comments on commit 5dab2df

Please sign in to comment.