Skip to content

Commit

Permalink
Add Conservative Rasterization support to RenderingDevice (Vulkan and…
Browse files Browse the repository at this point in the history
… D3D12)
  • Loading branch information
Lateasusual committed Oct 7, 2024
1 parent db66bd3 commit 43cca94
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/classes/RDPipelineRasterizationState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<member name="discard_primitives" type="bool" setter="set_discard_primitives" getter="get_discard_primitives" default="false">
If [code]true[/code], primitives are discarded immediately before the rasterization stage.
</member>
<member name="enable_conservative_rasterization" type="bool" setter="set_enable_conservative_rasterization" getter="get_enable_conservative_rasterization" default="false">
If [code]true[/code], primitive coverage is over-estimated during rasterization (any fragment containing part of the primitive will be included). May not be supported on all hardware.
</member>
<member name="enable_depth_clamp" type="bool" setter="set_enable_depth_clamp" getter="get_enable_depth_clamp" default="false">
If [code]true[/code], clamps depth values according to the minimum and maximum depth of the associated viewport.
</member>
Expand Down
2 changes: 1 addition & 1 deletion drivers/d3d12/rendering_device_driver_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5634,7 +5634,7 @@ RDD::PipelineID RenderingDeviceDriverD3D12::render_pipeline_create(
(&pipeline_desc.RasterizerState)->SlopeScaledDepthBias = 0.0f;
}
(&pipeline_desc.RasterizerState)->ForcedSampleCount = 0;
(&pipeline_desc.RasterizerState)->ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
(&pipeline_desc.RasterizerState)->ConservativeRaster = p_rasterization_state.enable_conservative_rasterization ? D3D12_CONSERVATIVE_RASTERIZATION_MODE_ON : D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
(&pipeline_desc.RasterizerState)->MultisampleEnable = TEXTURE_SAMPLES_COUNT[p_multisample_state.sample_count] != 1;
(&pipeline_desc.RasterizerState)->AntialiasedLineEnable = true;

Expand Down
12 changes: 12 additions & 0 deletions drivers/vulkan/rendering_device_driver_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ Error RenderingDeviceDriverVulkan::_initialize_device_extensions() {
_register_requested_device_extension(VK_EXT_PIPELINE_CREATION_CACHE_CONTROL_EXTENSION_NAME, false);
_register_requested_device_extension(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false);
_register_requested_device_extension(VK_EXT_ASTC_DECODE_MODE_EXTENSION_NAME, false);
_register_requested_device_extension(VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME, false);

if (Engine::get_singleton()->is_generate_spirv_debug_info_enabled()) {
_register_requested_device_extension(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, true);
Expand Down Expand Up @@ -4585,6 +4586,17 @@ RDD::PipelineID RenderingDeviceDriverVulkan::render_pipeline_create(
rasterization_state_create_info.depthBiasSlopeFactor = p_rasterization_state.depth_bias_slope_factor;
rasterization_state_create_info.lineWidth = p_rasterization_state.line_width;

VkPipelineRasterizationConservativeStateCreateInfoEXT conservativeStateCreateInfoExt = {};
if (p_rasterization_state.enable_conservative_rasterization) {
if (enabled_device_extension_names.has(VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME)) {
conservativeStateCreateInfoExt.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT;
conservativeStateCreateInfoExt.conservativeRasterizationMode = VkConservativeRasterizationModeEXT::VK_CONSERVATIVE_RASTERIZATION_MODE_OVERESTIMATE_EXT;
rasterization_state_create_info.pNext = &conservativeStateCreateInfoExt;
} else {
WARN_PRINT(vformat("enable_conservative_rasterization is true but %s is not available.", VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME));
}
}

// Multisample.
VkPipelineMultisampleStateCreateInfo multisample_state_create_info = {};
multisample_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Expand Down
2 changes: 2 additions & 0 deletions servers/rendering/rendering_device_binds.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ class RDPipelineRasterizationState : public RefCounted {
RD_SETGET(float, depth_bias_slope_factor)
RD_SETGET(float, line_width)
RD_SETGET(uint32_t, patch_control_points)
RD_SETGET(bool, enable_conservative_rasterization)

protected:
static void _bind_methods() {
Expand All @@ -547,6 +548,7 @@ class RDPipelineRasterizationState : public RefCounted {
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, depth_bias_slope_factor);
RD_BIND(Variant::FLOAT, RDPipelineRasterizationState, line_width);
RD_BIND(Variant::INT, RDPipelineRasterizationState, patch_control_points);
RD_BIND(Variant::BOOL, RDPipelineRasterizationState, enable_conservative_rasterization);
}
};

Expand Down
1 change: 1 addition & 0 deletions servers/rendering/rendering_device_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ class RenderingDeviceCommons : public Object {
float depth_bias_slope_factor = 0.0f;
float line_width = 1.0f;
uint32_t patch_control_points = 1;
bool enable_conservative_rasterization = false;
};

struct PipelineMultisampleState {
Expand Down

0 comments on commit 43cca94

Please sign in to comment.