summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2022-12-06 00:40:01 +0100
committerFernando Sahmkow <fsahmkow27@gmail.com>2023-01-01 22:43:58 +0100
commitd33251db9300e29ae830ec74e0b39ec0aa202b30 (patch)
tree3f17cbd40dcd970d152001d61aa1d275dbe11280 /src/video_core/renderer_vulkan
parentVulkan Implement Dynamic State 2 LogicOp and PatchVertices (diff)
downloadyuzu-d33251db9300e29ae830ec74e0b39ec0aa202b30.tar
yuzu-d33251db9300e29ae830ec74e0b39ec0aa202b30.tar.gz
yuzu-d33251db9300e29ae830ec74e0b39ec0aa202b30.tar.bz2
yuzu-d33251db9300e29ae830ec74e0b39ec0aa202b30.tar.lz
yuzu-d33251db9300e29ae830ec74e0b39ec0aa202b30.tar.xz
yuzu-d33251db9300e29ae830ec74e0b39ec0aa202b30.tar.zst
yuzu-d33251db9300e29ae830ec74e0b39ec0aa202b30.zip
Diffstat (limited to 'src/video_core/renderer_vulkan')
-rw-r--r--src/video_core/renderer_vulkan/fixed_pipeline_state.cpp70
-rw-r--r--src/video_core/renderer_vulkan/fixed_pipeline_state.h35
-rw-r--r--src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp36
-rw-r--r--src/video_core/renderer_vulkan/vk_pipeline_cache.cpp9
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.cpp94
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.h3
-rw-r--r--src/video_core/renderer_vulkan/vk_state_tracker.cpp14
-rw-r--r--src/video_core/renderer_vulkan/vk_state_tracker.h29
8 files changed, 224 insertions, 66 deletions
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
index b1623b882..3d328a250 100644
--- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
+++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
@@ -56,22 +56,16 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
extended_dynamic_state.Assign(features.has_extended_dynamic_state ? 1 : 0);
extended_dynamic_state_2.Assign(features.has_extended_dynamic_state_2 ? 1 : 0);
extended_dynamic_state_2_extra.Assign(features.has_extended_dynamic_state_2_extra ? 1 : 0);
- extended_dynamic_state_3.Assign(features.has_extended_dynamic_state_3 ? 1 : 0);
+ extended_dynamic_state_3_blend.Assign(features.has_extended_dynamic_state_3_blend ? 1 : 0);
+ extended_dynamic_state_3_enables.Assign(features.has_extended_dynamic_state_3_enables ? 1 : 0);
dynamic_vertex_input.Assign(features.has_dynamic_vertex_input ? 1 : 0);
xfb_enabled.Assign(regs.transform_feedback_enabled != 0);
- depth_clamp_disabled.Assign(regs.viewport_clip_control.geometry_clip ==
- Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
- regs.viewport_clip_control.geometry_clip ==
- Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
- regs.viewport_clip_control.geometry_clip ==
- Maxwell::ViewportClipControl::GeometryClip::FrustumZ);
ndc_minus_one_to_one.Assign(regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1 : 0);
polygon_mode.Assign(PackPolygonMode(regs.polygon_mode_front));
tessellation_primitive.Assign(static_cast<u32>(regs.tessellation.params.domain_type.Value()));
tessellation_spacing.Assign(static_cast<u32>(regs.tessellation.params.spacing.Value()));
tessellation_clockwise.Assign(regs.tessellation.params.output_primitives.Value() ==
Maxwell::Tessellation::OutputPrimitives::Triangles_CW);
- logic_op_enable.Assign(regs.logic_op.enable != 0 ? 1 : 0);
patch_control_points_minus_one.Assign(regs.patch_vertices - 1);
topology.Assign(topology_);
msaa_mode.Assign(regs.anti_alias_samples_mode);
@@ -138,12 +132,6 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
}
}
}
- if (maxwell3d.dirty.flags[Dirty::Blending]) {
- maxwell3d.dirty.flags[Dirty::Blending] = false;
- for (size_t index = 0; index < attachments.size(); ++index) {
- attachments[index].Refresh(regs, index);
- }
- }
if (maxwell3d.dirty.flags[Dirty::ViewportSwizzles]) {
maxwell3d.dirty.flags[Dirty::ViewportSwizzles] = false;
const auto& transform = regs.viewport_transform;
@@ -155,11 +143,22 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
dynamic_state.raw2 = 0;
if (!extended_dynamic_state) {
dynamic_state.Refresh(regs);
+ std::ranges::transform(regs.vertex_streams, vertex_strides.begin(), [](const auto& array) {
+ return static_cast<u16>(array.stride.Value());
+ });
}
if (!extended_dynamic_state_2_extra) {
dynamic_state.Refresh2(regs, topology, extended_dynamic_state_2);
}
- if (!extended_dynamic_state_3) {
+ if (!extended_dynamic_state_3_blend) {
+ if (maxwell3d.dirty.flags[Dirty::Blending]) {
+ maxwell3d.dirty.flags[Dirty::Blending] = false;
+ for (size_t index = 0; index < attachments.size(); ++index) {
+ attachments[index].Refresh(regs, index);
+ }
+ }
+ }
+ if (!extended_dynamic_state_3_enables) {
dynamic_state.Refresh3(regs);
}
if (xfb_enabled) {
@@ -177,12 +176,11 @@ void FixedPipelineState::BlendingAttachment::Refresh(const Maxwell& regs, size_t
mask_a.Assign(mask.A);
// TODO: C++20 Use templated lambda to deduplicate code
+ if (!regs.blend.enable[index]) {
+ return;
+ }
- if (!regs.blend_per_target_enabled) {
- if (!regs.blend.enable[index]) {
- return;
- }
- const auto& src = regs.blend;
+ const auto setup_blend = [&]<typename T>(const T& src) {
equation_rgb.Assign(PackBlendEquation(src.color_op));
equation_a.Assign(PackBlendEquation(src.alpha_op));
factor_source_rgb.Assign(PackBlendFactor(src.color_source));
@@ -190,20 +188,13 @@ void FixedPipelineState::BlendingAttachment::Refresh(const Maxwell& regs, size_t
factor_source_a.Assign(PackBlendFactor(src.alpha_source));
factor_dest_a.Assign(PackBlendFactor(src.alpha_dest));
enable.Assign(1);
- return;
- }
+ };
- if (!regs.blend.enable[index]) {
+ if (!regs.blend_per_target_enabled) {
+ setup_blend(regs.blend);
return;
}
- const auto& src = regs.blend_per_target[index];
- equation_rgb.Assign(PackBlendEquation(src.color_op));
- equation_a.Assign(PackBlendEquation(src.alpha_op));
- factor_source_rgb.Assign(PackBlendFactor(src.color_source));
- factor_dest_rgb.Assign(PackBlendFactor(src.color_dest));
- factor_source_a.Assign(PackBlendFactor(src.alpha_source));
- factor_dest_a.Assign(PackBlendFactor(src.alpha_dest));
- enable.Assign(1);
+ setup_blend(regs.blend_per_target[index]);
}
void FixedPipelineState::DynamicState::Refresh(const Maxwell& regs) {
@@ -236,12 +227,11 @@ void FixedPipelineState::DynamicState::Refresh(const Maxwell& regs) {
depth_test_func.Assign(PackComparisonOp(regs.depth_test_func));
cull_face.Assign(PackCullFace(regs.gl_cull_face));
cull_enable.Assign(regs.gl_cull_test_enabled != 0 ? 1 : 0);
- std::ranges::transform(regs.vertex_streams, vertex_strides.begin(), [](const auto& array) {
- return static_cast<u16>(array.stride.Value());
- });
}
-void FixedPipelineState::DynamicState::Refresh2(const Maxwell& regs, Maxwell::PrimitiveTopology topology_, bool base_feautures_supported) {
+void FixedPipelineState::DynamicState::Refresh2(const Maxwell& regs,
+ Maxwell::PrimitiveTopology topology_,
+ bool base_feautures_supported) {
logic_op.Assign(PackLogicOp(regs.logic_op.op));
if (base_feautures_supported) {
@@ -260,7 +250,15 @@ void FixedPipelineState::DynamicState::Refresh2(const Maxwell& regs, Maxwell::Pr
depth_bias_enable.Assign(enabled_lut[POLYGON_OFFSET_ENABLE_LUT[topology_index]] != 0 ? 1 : 0);
}
-void FixedPipelineState::DynamicState::Refresh3(const Maxwell&) {}
+void FixedPipelineState::DynamicState::Refresh3(const Maxwell& regs) {
+ logic_op_enable.Assign(regs.logic_op.enable != 0 ? 1 : 0);
+ depth_clamp_disabled.Assign(regs.viewport_clip_control.geometry_clip ==
+ Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
+ regs.viewport_clip_control.geometry_clip ==
+ Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
+ regs.viewport_clip_control.geometry_clip ==
+ Maxwell::ViewportClipControl::GeometryClip::FrustumZ);
+}
size_t FixedPipelineState::Hash() const noexcept {
const u64 hash = Common::CityHash64(reinterpret_cast<const char*>(this), Size());
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.h b/src/video_core/renderer_vulkan/fixed_pipeline_state.h
index 88680e448..f47406347 100644
--- a/src/video_core/renderer_vulkan/fixed_pipeline_state.h
+++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.h
@@ -21,7 +21,8 @@ struct DynamicFeatures {
bool has_extended_dynamic_state;
bool has_extended_dynamic_state_2;
bool has_extended_dynamic_state_2_extra;
- bool has_extended_dynamic_state_3;
+ bool has_extended_dynamic_state_3_blend;
+ bool has_extended_dynamic_state_3_enables;
bool has_dynamic_vertex_input;
};
@@ -147,6 +148,8 @@ struct FixedPipelineState {
BitField<4, 1, u32> depth_bias_enable;
BitField<5, 1, u32> rasterize_enable;
BitField<6, 4, u32> logic_op;
+ BitField<10, 1, u32> logic_op_enable;
+ BitField<11, 1, u32> depth_clamp_disabled;
};
union {
u32 raw2;
@@ -159,8 +162,6 @@ struct FixedPipelineState {
BitField<28, 1, u32> front_face;
BitField<29, 3, u32> depth_test_func;
};
- // Vertex stride is a 12 bits value, we have 4 bits to spare per element
- std::array<u16, Maxwell::NumVertexArrays> vertex_strides;
void Refresh(const Maxwell& regs);
void Refresh2(const Maxwell& regs, Maxwell::PrimitiveTopology topology, bool base_feautures_supported);
@@ -184,17 +185,16 @@ struct FixedPipelineState {
BitField<0, 1, u32> extended_dynamic_state;
BitField<1, 1, u32> extended_dynamic_state_2;
BitField<2, 1, u32> extended_dynamic_state_2_extra;
- BitField<3, 1, u32> extended_dynamic_state_3;
- BitField<4, 1, u32> dynamic_vertex_input;
- BitField<5, 1, u32> xfb_enabled;
- BitField<6, 1, u32> depth_clamp_disabled;
+ BitField<3, 1, u32> extended_dynamic_state_3_blend;
+ BitField<4, 1, u32> extended_dynamic_state_3_enables;
+ BitField<5, 1, u32> dynamic_vertex_input;
+ BitField<6, 1, u32> xfb_enabled;
BitField<7, 1, u32> ndc_minus_one_to_one;
BitField<8, 2, u32> polygon_mode;
BitField<10, 2, u32> tessellation_primitive;
BitField<12, 2, u32> tessellation_spacing;
BitField<14, 1, u32> tessellation_clockwise;
- BitField<15, 1, u32> logic_op_enable;
- BitField<16, 5, u32> patch_control_points_minus_one;
+ BitField<15, 5, u32> patch_control_points_minus_one;
BitField<24, 4, Maxwell::PrimitiveTopology> topology;
BitField<28, 4, Tegra::Texture::MsaaMode> msaa_mode;
@@ -217,16 +217,19 @@ struct FixedPipelineState {
u32 alpha_test_ref;
u32 point_size;
- std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments;
std::array<u16, Maxwell::NumViewports> viewport_swizzles;
union {
u64 attribute_types; // Used with VK_EXT_vertex_input_dynamic_state
u64 enabled_divisors;
};
+
+ DynamicState dynamic_state;
+ std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments;
std::array<VertexAttribute, Maxwell::NumVertexAttributes> attributes;
std::array<u32, Maxwell::NumVertexArrays> binding_divisors;
+ // Vertex stride is a 12 bits value, we have 4 bits to spare per element
+ std::array<u16, Maxwell::NumVertexArrays> vertex_strides;
- DynamicState dynamic_state;
VideoCommon::TransformFeedbackState xfb_state;
void Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFeatures& features);
@@ -244,17 +247,17 @@ struct FixedPipelineState {
// When transform feedback is enabled, use the whole struct
return sizeof(*this);
}
- if (dynamic_vertex_input && extended_dynamic_state_2) {
+ if (dynamic_vertex_input && extended_dynamic_state_3_blend) {
// Exclude dynamic state and attributes
- return offsetof(FixedPipelineState, attributes);
+ return offsetof(FixedPipelineState, dynamic_state);
}
- if (extended_dynamic_state_2_extra) {
+ if (dynamic_vertex_input) {
// Exclude dynamic state
- return offsetof(FixedPipelineState, dynamic_state);
+ return offsetof(FixedPipelineState, attributes);
}
if (extended_dynamic_state) {
// Exclude dynamic state
- return offsetof(FixedPipelineState, dynamic_state.raw2);
+ return offsetof(FixedPipelineState, vertex_strides);
}
// Default
return offsetof(FixedPipelineState, xfb_state);
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
index ce82a9c65..dab3d7e3f 100644
--- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
+++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
@@ -489,9 +489,11 @@ void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling,
if (bind_pipeline) {
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
}
- cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
- RESCALING_LAYOUT_WORDS_OFFSET, sizeof(rescaling_data),
- rescaling_data.data());
+ if (is_rescaling) {
+ cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS,
+ RESCALING_LAYOUT_WORDS_OFFSET, sizeof(rescaling_data),
+ rescaling_data.data());
+ }
if (update_rescaling) {
const f32 config_down_factor{Settings::values.resolution_info.down_factor};
const f32 scale_down_factor{is_rescaling ? config_down_factor : 1.0f};
@@ -524,9 +526,8 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
FixedPipelineState::DynamicState dynamic{};
if (!key.state.extended_dynamic_state) {
dynamic = key.state.dynamic_state;
- }
- if (!key.state.extended_dynamic_state_2) {
- dynamic.raw2 = key.state.dynamic_state.raw2;
+ } else {
+ dynamic.raw1 = key.state.dynamic_state.raw1;
}
static_vector<VkVertexInputBindingDescription, 32> vertex_bindings;
static_vector<VkVertexInputBindingDivisorDescriptionEXT, 32> vertex_binding_divisors;
@@ -564,7 +565,7 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
instanced ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX;
vertex_bindings.push_back({
.binding = static_cast<u32>(index),
- .stride = dynamic.vertex_strides[index],
+ .stride = key.state.vertex_strides[index],
.inputRate = rate,
});
if (instanced) {
@@ -675,7 +676,7 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
.pNext = nullptr,
.flags = 0,
.depthClampEnable =
- static_cast<VkBool32>(key.state.depth_clamp_disabled == 0 ? VK_TRUE : VK_FALSE),
+ static_cast<VkBool32>(dynamic.depth_clamp_disabled == 0 ? VK_TRUE : VK_FALSE),
.rasterizerDiscardEnable =
static_cast<VkBool32>(dynamic.rasterize_enable == 0 ? VK_TRUE : VK_FALSE),
.polygonMode =
@@ -785,13 +786,13 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
- .logicOpEnable = key.state.logic_op_enable != 0,
+ .logicOpEnable = dynamic.logic_op_enable != 0,
.logicOp = static_cast<VkLogicOp>(dynamic.logic_op.Value()),
.attachmentCount = static_cast<u32>(cb_attachments.size()),
.pAttachments = cb_attachments.data(),
.blendConstants = {},
};
- static_vector<VkDynamicState, 23> dynamic_states{
+ static_vector<VkDynamicState, 28> dynamic_states{
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR,
VK_DYNAMIC_STATE_DEPTH_BIAS, VK_DYNAMIC_STATE_BLEND_CONSTANTS,
VK_DYNAMIC_STATE_DEPTH_BOUNDS, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
@@ -825,6 +826,21 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
if (key.state.extended_dynamic_state_2_extra) {
dynamic_states.push_back(VK_DYNAMIC_STATE_LOGIC_OP_EXT);
}
+ if (key.state.extended_dynamic_state_3_blend) {
+ static constexpr std::array extended3{
+ VK_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT,
+ VK_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT,
+ VK_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT,
+ };
+ dynamic_states.insert(dynamic_states.end(), extended3.begin(), extended3.end());
+ }
+ if (key.state.extended_dynamic_state_3_enables) {
+ static constexpr std::array extended3{
+ VK_DYNAMIC_STATE_DEPTH_CLAMP_ENABLE_EXT,
+ VK_DYNAMIC_STATE_LOGIC_OP_ENABLE_EXT,
+ };
+ dynamic_states.insert(dynamic_states.end(), extended3.begin(), extended3.end());
+ }
}
const VkPipelineDynamicStateCreateInfo dynamic_state_ci{
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
index ee1ad744f..6cd162422 100644
--- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
@@ -356,7 +356,8 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, const Device& device
.has_extended_dynamic_state = device.IsExtExtendedDynamicStateSupported(),
.has_extended_dynamic_state_2 = device.IsExtExtendedDynamicState2Supported(),
.has_extended_dynamic_state_2_extra = device.IsExtExtendedDynamicState2ExtrasSupported(),
- .has_extended_dynamic_state_3 = device.IsExtExtendedDynamicState3Supported(),
+ .has_extended_dynamic_state_3_blend = device.IsExtExtendedDynamicState3BlendingSupported(),
+ .has_extended_dynamic_state_3_enables = device.IsExtExtendedDynamicState3EnablesSupported(),
.has_dynamic_vertex_input = device.IsExtVertexInputDynamicStateSupported(),
};
}
@@ -456,8 +457,10 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading
dynamic_features.has_extended_dynamic_state_2 ||
(key.state.extended_dynamic_state_2_extra != 0) !=
dynamic_features.has_extended_dynamic_state_2_extra ||
- (key.state.extended_dynamic_state_3 != 0) !=
- dynamic_features.has_extended_dynamic_state_3 ||
+ (key.state.extended_dynamic_state_3_blend != 0) !=
+ dynamic_features.has_extended_dynamic_state_3_blend ||
+ (key.state.extended_dynamic_state_3_enables != 0) !=
+ dynamic_features.has_extended_dynamic_state_3_enables ||
(key.state.dynamic_vertex_input != 0) != dynamic_features.has_dynamic_vertex_input) {
return;
}
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index 3cf6b796b..143af93c5 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -698,10 +698,17 @@ void RasterizerVulkan::UpdateDynamicStates() {
UpdateRasterizerDiscardEnable(regs);
UpdateDepthBiasEnable(regs);
}
+ if (device.IsExtExtendedDynamicState3EnablesSupported()) {
+ UpdateLogicOpEnable(regs);
+ UpdateDepthClampEnable(regs);
+ }
}
if (device.IsExtExtendedDynamicState2ExtrasSupported()) {
UpdateLogicOp(regs);
}
+ if (device.IsExtExtendedDynamicState3Supported()) {
+ UpdateBlending(regs);
+ }
}
}
@@ -970,7 +977,30 @@ void RasterizerVulkan::UpdateDepthBiasEnable(Tegra::Engines::Maxwell3D::Regs& re
};
const u32 topology_index = static_cast<u32>(maxwell3d->draw_manager->GetDrawState().topology);
const u32 enable = enabled_lut[POLYGON_OFFSET_ENABLE_LUT[topology_index]];
- scheduler.Record([enable](vk::CommandBuffer cmdbuf) { cmdbuf.SetDepthBiasEnableEXT(enable); });
+ scheduler.Record([enable](vk::CommandBuffer cmdbuf) { cmdbuf.SetDepthBiasEnableEXT(enable != 0); });
+}
+
+void RasterizerVulkan::UpdateLogicOpEnable(Tegra::Engines::Maxwell3D::Regs& regs) {
+ if (!state_tracker.TouchLogicOpEnable()) {
+ return;
+ }
+ scheduler.Record([enable = regs.logic_op.enable](vk::CommandBuffer cmdbuf) {
+ cmdbuf.SetLogicOpEnableEXT(enable != 0);
+ });
+}
+
+void RasterizerVulkan::UpdateDepthClampEnable(Tegra::Engines::Maxwell3D::Regs& regs) {
+ if (!state_tracker.TouchDepthClampEnable()) {
+ return;
+ }
+ bool is_enabled = !(regs.viewport_clip_control.geometry_clip ==
+ Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
+ regs.viewport_clip_control.geometry_clip ==
+ Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
+ regs.viewport_clip_control.geometry_clip ==
+ Maxwell::ViewportClipControl::GeometryClip::FrustumZ);
+ scheduler.Record(
+ [is_enabled](vk::CommandBuffer cmdbuf) { cmdbuf.SetDepthClampEnableEXT(is_enabled); });
}
void RasterizerVulkan::UpdateDepthCompareOp(Tegra::Engines::Maxwell3D::Regs& regs) {
@@ -1041,6 +1071,68 @@ void RasterizerVulkan::UpdateLogicOp(Tegra::Engines::Maxwell3D::Regs& regs) {
scheduler.Record([op](vk::CommandBuffer cmdbuf) { cmdbuf.SetLogicOpEXT(op); });
}
+void RasterizerVulkan::UpdateBlending(Tegra::Engines::Maxwell3D::Regs& regs) {
+ if (!state_tracker.TouchBlending()) {
+ return;
+ }
+
+ if (state_tracker.TouchColorMask()) {
+ std::array<VkColorComponentFlags, Maxwell::NumRenderTargets> setup_masks{};
+ for (size_t index = 0; index < Maxwell::NumRenderTargets; index++) {
+ const auto& mask = regs.color_mask[regs.color_mask_common ? 0 : index];
+ auto& current = setup_masks[index];
+ if (mask.R) {
+ current |= VK_COLOR_COMPONENT_R_BIT;
+ }
+ if (mask.G) {
+ current |= VK_COLOR_COMPONENT_G_BIT;
+ }
+ if (mask.B) {
+ current |= VK_COLOR_COMPONENT_B_BIT;
+ }
+ if (mask.A) {
+ current |= VK_COLOR_COMPONENT_A_BIT;
+ }
+ }
+ scheduler.Record([setup_masks](vk::CommandBuffer cmdbuf) {
+ cmdbuf.SetColorWriteMaskEXT(0, setup_masks);
+ });
+ }
+
+ if (state_tracker.TouchBlendEnable()) {
+ std::array<VkBool32, Maxwell::NumRenderTargets> setup_enables{};
+ std::ranges::transform(
+ regs.blend.enable, setup_enables.begin(),
+ [&](const auto& is_enabled) { return is_enabled != 0 ? VK_TRUE : VK_FALSE; });
+ scheduler.Record([setup_enables](vk::CommandBuffer cmdbuf) {
+ cmdbuf.SetColorBlendEnableEXT(0, setup_enables);
+ });
+ }
+
+ if (state_tracker.TouchBlendEquations()) {
+ std::array<VkColorBlendEquationEXT, Maxwell::NumRenderTargets> setup_blends{};
+ for (size_t index = 0; index < Maxwell::NumRenderTargets; index++) {
+ const auto blend_setup = [&]<typename T>(const T& guest_blend) {
+ auto& host_blend = setup_blends[index];
+ host_blend.srcColorBlendFactor = MaxwellToVK::BlendFactor(guest_blend.color_source);
+ host_blend.dstColorBlendFactor = MaxwellToVK::BlendFactor(guest_blend.color_dest);
+ host_blend.colorBlendOp = MaxwellToVK::BlendEquation(guest_blend.color_op);
+ host_blend.srcAlphaBlendFactor = MaxwellToVK::BlendFactor(guest_blend.alpha_source);
+ host_blend.dstAlphaBlendFactor = MaxwellToVK::BlendFactor(guest_blend.alpha_dest);
+ host_blend.alphaBlendOp = MaxwellToVK::BlendEquation(guest_blend.alpha_op);
+ };
+ if (!regs.blend_per_target_enabled) {
+ blend_setup(regs.blend);
+ continue;
+ }
+ blend_setup(regs.blend_per_target[index]);
+ }
+ scheduler.Record([setup_blends](vk::CommandBuffer cmdbuf) {
+ cmdbuf.SetColorBlendEquationEXT(0, setup_blends);
+ });
+ }
+}
+
void RasterizerVulkan::UpdateStencilTestEnable(Tegra::Engines::Maxwell3D::Regs& regs) {
if (!state_tracker.TouchStencilTestEnable()) {
return;
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h
index 67d35eff7..839de6b26 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.h
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.h
@@ -142,10 +142,13 @@ private:
void UpdatePrimitiveRestartEnable(Tegra::Engines::Maxwell3D::Regs& regs);
void UpdateRasterizerDiscardEnable(Tegra::Engines::Maxwell3D::Regs& regs);
void UpdateDepthBiasEnable(Tegra::Engines::Maxwell3D::Regs& regs);
+ void UpdateLogicOpEnable(Tegra::Engines::Maxwell3D::Regs& regs);
+ void UpdateDepthClampEnable(Tegra::Engines::Maxwell3D::Regs& regs);
void UpdateFrontFace(Tegra::Engines::Maxwell3D::Regs& regs);
void UpdateStencilOp(Tegra::Engines::Maxwell3D::Regs& regs);
void UpdateStencilTestEnable(Tegra::Engines::Maxwell3D::Regs& regs);
void UpdateLogicOp(Tegra::Engines::Maxwell3D::Regs& regs);
+ void UpdateBlending(Tegra::Engines::Maxwell3D::Regs& regs);
void UpdateVertexInput(Tegra::Engines::Maxwell3D::Regs& regs);
diff --git a/src/video_core/renderer_vulkan/vk_state_tracker.cpp b/src/video_core/renderer_vulkan/vk_state_tracker.cpp
index 1f8528e3e..bfea503de 100644
--- a/src/video_core/renderer_vulkan/vk_state_tracker.cpp
+++ b/src/video_core/renderer_vulkan/vk_state_tracker.cpp
@@ -48,7 +48,13 @@ Flags MakeInvalidationFlags() {
PrimitiveRestartEnable,
RasterizerDiscardEnable,
DepthBiasEnable,
+ LogicOpEnable,
+ DepthClampEnable,
LogicOp,
+ Blending,
+ ColorMask,
+ BlendEquations,
+ BlendEnable,
};
Flags flags{};
for (const int flag : INVALIDATION_FLAGS) {
@@ -128,6 +134,8 @@ void SetupDirtyStateEnable(Tables& tables) {
setup(OFF(polygon_offset_point_enable), DepthBiasEnable);
setup(OFF(polygon_offset_line_enable), DepthBiasEnable);
setup(OFF(polygon_offset_fill_enable), DepthBiasEnable);
+ setup(OFF(logic_op.enable), LogicOpEnable);
+ setup(OFF(viewport_clip_control.geometry_clip), DepthClampEnable);
}
void SetupDirtyDepthCompareOp(Tables& tables) {
@@ -157,10 +165,16 @@ void SetupDirtyStencilOp(Tables& tables) {
void SetupDirtyBlending(Tables& tables) {
tables[0][OFF(color_mask_common)] = Blending;
+ tables[1][OFF(color_mask_common)] = ColorMask;
tables[0][OFF(blend_per_target_enabled)] = Blending;
+ tables[1][OFF(blend_per_target_enabled)] = BlendEquations;
FillBlock(tables[0], OFF(color_mask), NUM(color_mask), Blending);
+ FillBlock(tables[1], OFF(color_mask), NUM(color_mask), ColorMask);
FillBlock(tables[0], OFF(blend), NUM(blend), Blending);
+ FillBlock(tables[1], OFF(blend), NUM(blend), BlendEquations);
+ FillBlock(tables[1], OFF(blend.enable), NUM(blend.enable), BlendEnable);
FillBlock(tables[0], OFF(blend_per_target), NUM(blend_per_target), Blending);
+ FillBlock(tables[1], OFF(blend_per_target), NUM(blend_per_target), BlendEquations);
}
void SetupDirtySpecialOps(Tables& tables) {
diff --git a/src/video_core/renderer_vulkan/vk_state_tracker.h b/src/video_core/renderer_vulkan/vk_state_tracker.h
index 6050f5d26..7cdc70c60 100644
--- a/src/video_core/renderer_vulkan/vk_state_tracker.h
+++ b/src/video_core/renderer_vulkan/vk_state_tracker.h
@@ -50,8 +50,13 @@ enum : u8 {
DepthBiasEnable,
StateEnable,
LogicOp,
+ LogicOpEnable,
+ DepthClampEnable,
Blending,
+ BlendEnable,
+ BlendEquations,
+ ColorMask,
ViewportSwizzles,
Last,
@@ -144,6 +149,14 @@ public:
return Exchange(Dirty::DepthBiasEnable, false);
}
+ bool TouchLogicOpEnable() {
+ return Exchange(Dirty::LogicOpEnable, false);
+ }
+
+ bool TouchDepthClampEnable() {
+ return Exchange(Dirty::DepthClampEnable, false);
+ }
+
bool TouchDepthCompareOp() {
return Exchange(Dirty::DepthCompareOp, false);
}
@@ -156,6 +169,22 @@ public:
return Exchange(Dirty::StencilOp, false);
}
+ bool TouchBlending() {
+ return Exchange(Dirty::Blending, false);
+ }
+
+ bool TouchBlendEnable() {
+ return Exchange(Dirty::BlendEnable, false);
+ }
+
+ bool TouchBlendEquations() {
+ return Exchange(Dirty::BlendEquations, false);
+ }
+
+ bool TouchColorMask() {
+ return Exchange(Dirty::ColorMask, false);
+ }
+
bool TouchStencilTestEnable() {
return Exchange(Dirty::StencilTestEnable, false);
}