3
0
Fork 0
forked from suyu/suyu

vk_graphics_pipeline: Implement smooth lines

This commit is contained in:
ReinUsesLisp 2021-06-25 05:25:19 -03:00 committed by ameerj
parent 57a8921e01
commit f94f0be521
5 changed files with 65 additions and 5 deletions

View file

@ -88,6 +88,7 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d,
y_negate.Assign(regs.screen_y_control.y_negate != 0 ? 1 : 0); y_negate.Assign(regs.screen_y_control.y_negate != 0 ? 1 : 0);
provoking_vertex_last.Assign(regs.provoking_vertex_last != 0 ? 1 : 0); provoking_vertex_last.Assign(regs.provoking_vertex_last != 0 ? 1 : 0);
conservative_raster_enable.Assign(regs.conservative_raster_enable != 0 ? 1 : 0); conservative_raster_enable.Assign(regs.conservative_raster_enable != 0 ? 1 : 0);
smooth_lines.Assign(regs.line_smooth_enable != 0 ? 1 : 0);
for (size_t i = 0; i < regs.rt.size(); ++i) { for (size_t i = 0; i < regs.rt.size(); ++i) {
color_formats[i] = static_cast<u8>(regs.rt[i].format); color_formats[i] = static_cast<u8>(regs.rt[i].format);

View file

@ -195,6 +195,7 @@ struct FixedPipelineState {
BitField<11, 1, u32> y_negate; BitField<11, 1, u32> y_negate;
BitField<12, 1, u32> provoking_vertex_last; BitField<12, 1, u32> provoking_vertex_last;
BitField<13, 1, u32> conservative_raster_enable; BitField<13, 1, u32> conservative_raster_enable;
BitField<14, 1, u32> smooth_lines;
}; };
std::array<u8, Maxwell::NumRenderTargets> color_formats; std::array<u8, Maxwell::NumRenderTargets> color_formats;

View file

@ -80,6 +80,14 @@ bool SupportsPrimitiveRestart(VkPrimitiveTopology topology) {
return std::ranges::find(unsupported_topologies, topology) == unsupported_topologies.end(); return std::ranges::find(unsupported_topologies, topology) == unsupported_topologies.end();
} }
bool IsLine(VkPrimitiveTopology topology) {
static constexpr std::array line_topologies{
VK_PRIMITIVE_TOPOLOGY_LINE_LIST, VK_PRIMITIVE_TOPOLOGY_LINE_STRIP,
// VK_PRIMITIVE_TOPOLOGY_LINE_LOOP_EXT,
};
return std::ranges::find(line_topologies, topology) == line_topologies.end();
}
VkViewportSwizzleNV UnpackViewportSwizzle(u16 swizzle) { VkViewportSwizzleNV UnpackViewportSwizzle(u16 swizzle) {
union Swizzle { union Swizzle {
u32 raw; u32 raw;
@ -616,6 +624,16 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
.depthBiasSlopeFactor = 0.0f, .depthBiasSlopeFactor = 0.0f,
.lineWidth = 1.0f, .lineWidth = 1.0f,
}; };
VkPipelineRasterizationLineStateCreateInfoEXT line_state{
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT,
.pNext = nullptr,
.lineRasterizationMode = key.state.smooth_lines != 0
? VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT
: VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT,
.stippledLineEnable = VK_FALSE, // TODO
.lineStippleFactor = 0,
.lineStipplePattern = 0,
};
VkPipelineRasterizationConservativeStateCreateInfoEXT conservative_raster{ VkPipelineRasterizationConservativeStateCreateInfoEXT conservative_raster{
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT, .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT,
.pNext = nullptr, .pNext = nullptr,
@ -632,6 +650,9 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
? VK_PROVOKING_VERTEX_MODE_LAST_VERTEX_EXT ? VK_PROVOKING_VERTEX_MODE_LAST_VERTEX_EXT
: VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT, : VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT,
}; };
if (IsLine(input_assembly_topology) && device.IsExtLineRasterizationSupported()) {
line_state.pNext = std::exchange(rasterization_ci.pNext, &line_state);
}
if (device.IsExtConservativeRasterizationSupported()) { if (device.IsExtConservativeRasterizationSupported()) {
conservative_raster.pNext = std::exchange(rasterization_ci.pNext, &conservative_raster); conservative_raster.pNext = std::exchange(rasterization_ci.pNext, &conservative_raster);
} }

View file

@ -416,6 +416,23 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state"); LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state");
} }
VkPhysicalDeviceLineRasterizationFeaturesEXT line_raster;
if (ext_line_rasterization) {
line_raster = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT,
.pNext = nullptr,
.rectangularLines = VK_TRUE,
.bresenhamLines = VK_FALSE,
.smoothLines = VK_TRUE,
.stippledRectangularLines = VK_FALSE,
.stippledBresenhamLines = VK_FALSE,
.stippledSmoothLines = VK_FALSE,
};
SetNext(next, line_raster);
} else {
LOG_INFO(Render_Vulkan, "Device doesn't support smooth lines");
}
if (!ext_conservative_rasterization) { if (!ext_conservative_rasterization) {
LOG_INFO(Render_Vulkan, "Device doesn't support conservative rasterization"); LOG_INFO(Render_Vulkan, "Device doesn't support conservative rasterization");
} }
@ -757,6 +774,7 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) {
bool has_ext_shader_atomic_int64{}; bool has_ext_shader_atomic_int64{};
bool has_ext_provoking_vertex{}; bool has_ext_provoking_vertex{};
bool has_ext_vertex_input_dynamic_state{}; bool has_ext_vertex_input_dynamic_state{};
bool has_ext_line_rasterization{};
for (const VkExtensionProperties& extension : physical.EnumerateDeviceExtensionProperties()) { for (const VkExtensionProperties& extension : physical.EnumerateDeviceExtensionProperties()) {
const auto test = [&](std::optional<std::reference_wrapper<bool>> status, const char* name, const auto test = [&](std::optional<std::reference_wrapper<bool>> status, const char* name,
bool push) { bool push) {
@ -798,6 +816,7 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) {
test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false); test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false);
test(has_khr_workgroup_memory_explicit_layout, test(has_khr_workgroup_memory_explicit_layout,
VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false); VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false);
test(has_ext_line_rasterization, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, false);
if (Settings::values.enable_nsight_aftermath) { if (Settings::values.enable_nsight_aftermath) {
test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME, test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME,
true); true);
@ -918,17 +937,29 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) {
} }
} }
if (has_ext_extended_dynamic_state) { if (has_ext_extended_dynamic_state) {
VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state; VkPhysicalDeviceExtendedDynamicStateFeaturesEXT extended_dynamic_state;
dynamic_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT; extended_dynamic_state.sType =
dynamic_state.pNext = nullptr; VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
features.pNext = &dynamic_state; extended_dynamic_state.pNext = nullptr;
features.pNext = &extended_dynamic_state;
physical.GetFeatures2KHR(features); physical.GetFeatures2KHR(features);
if (dynamic_state.extendedDynamicState) { if (extended_dynamic_state.extendedDynamicState) {
extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME); extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
ext_extended_dynamic_state = true; ext_extended_dynamic_state = true;
} }
} }
if (has_ext_line_rasterization) {
VkPhysicalDeviceLineRasterizationFeaturesEXT line_raster;
line_raster.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT;
line_raster.pNext = nullptr;
features.pNext = &line_raster;
physical.GetFeatures2KHR(features);
if (line_raster.rectangularLines && line_raster.smoothLines) {
extensions.push_back(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
ext_line_rasterization = true;
}
}
if (has_khr_workgroup_memory_explicit_layout) { if (has_khr_workgroup_memory_explicit_layout) {
VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR layout; VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR layout;
layout.sType = layout.sType =

View file

@ -259,6 +259,11 @@ public:
return ext_extended_dynamic_state; return ext_extended_dynamic_state;
} }
/// Returns true if the device supports VK_EXT_line_rasterization.
bool IsExtLineRasterizationSupported() const {
return ext_line_rasterization;
}
/// Returns true if the device supports VK_EXT_vertex_input_dynamic_state. /// Returns true if the device supports VK_EXT_vertex_input_dynamic_state.
bool IsExtVertexInputDynamicStateSupported() const { bool IsExtVertexInputDynamicStateSupported() const {
return ext_vertex_input_dynamic_state; return ext_vertex_input_dynamic_state;
@ -382,6 +387,7 @@ private:
bool ext_transform_feedback{}; ///< Support for VK_EXT_transform_feedback. bool ext_transform_feedback{}; ///< Support for VK_EXT_transform_feedback.
bool ext_custom_border_color{}; ///< Support for VK_EXT_custom_border_color. bool ext_custom_border_color{}; ///< Support for VK_EXT_custom_border_color.
bool ext_extended_dynamic_state{}; ///< Support for VK_EXT_extended_dynamic_state. bool ext_extended_dynamic_state{}; ///< Support for VK_EXT_extended_dynamic_state.
bool ext_line_rasterization{}; ///< Support for VK_EXT_line_rasterization.
bool ext_vertex_input_dynamic_state{}; ///< Support for VK_EXT_vertex_input_dynamic_state. bool ext_vertex_input_dynamic_state{}; ///< Support for VK_EXT_vertex_input_dynamic_state.
bool ext_shader_stencil_export{}; ///< Support for VK_EXT_shader_stencil_export. bool ext_shader_stencil_export{}; ///< Support for VK_EXT_shader_stencil_export.
bool ext_shader_atomic_int64{}; ///< Support for VK_KHR_shader_atomic_int64. bool ext_shader_atomic_int64{}; ///< Support for VK_KHR_shader_atomic_int64.