diff options
| author | 2020-04-18 05:41:56 -0300 | |
|---|---|---|
| committer | 2020-04-18 19:23:35 -0300 | |
| commit | b571c92dfd0e6bc3efeae6087723996165273c06 (patch) | |
| tree | de85f23fce0f4f17ce4dccde8254ad305ef18a3c | |
| parent | fixed_pipeline_state: Pack rasterizer state (diff) | |
| download | yuzu-b571c92dfd0e6bc3efeae6087723996165273c06.tar.gz yuzu-b571c92dfd0e6bc3efeae6087723996165273c06.tar.xz yuzu-b571c92dfd0e6bc3efeae6087723996165273c06.zip | |
fixed_pipeline_state: Pack blending state
Reduce FixedPipelineState's size to 364 bytes.
Diffstat (limited to '')
3 files changed, 227 insertions, 98 deletions
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp index 1a23de07f..2b053ea74 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp | |||
| @@ -95,71 +95,58 @@ void FixedPipelineState::Rasterizer::Fill(const Maxwell& regs) noexcept { | |||
| 95 | std::memcpy(&point_size, ®s.point_size, sizeof(point_size)); // TODO: C++20 std::bit_cast | 95 | std::memcpy(&point_size, ®s.point_size, sizeof(point_size)); // TODO: C++20 std::bit_cast |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | namespace { | 98 | void FixedPipelineState::ColorBlending::Fill(const Maxwell& regs) noexcept { |
| 99 | 99 | for (std::size_t index = 0; index < std::size(attachments); ++index) { | |
| 100 | constexpr FixedPipelineState::BlendingAttachment GetBlendingAttachmentState( | 100 | attachments[index].Fill(regs, index); |
| 101 | const Maxwell& regs, std::size_t render_target) { | ||
| 102 | const auto& mask = regs.color_mask[regs.color_mask_common ? 0 : render_target]; | ||
| 103 | const std::array components = {mask.R != 0, mask.G != 0, mask.B != 0, mask.A != 0}; | ||
| 104 | |||
| 105 | const FixedPipelineState::BlendingAttachment default_blending( | ||
| 106 | false, Maxwell::Blend::Equation::Add, Maxwell::Blend::Factor::One, | ||
| 107 | Maxwell::Blend::Factor::Zero, Maxwell::Blend::Equation::Add, Maxwell::Blend::Factor::One, | ||
| 108 | Maxwell::Blend::Factor::Zero, components); | ||
| 109 | if (render_target >= regs.rt_control.count) { | ||
| 110 | return default_blending; | ||
| 111 | } | 101 | } |
| 102 | } | ||
| 103 | |||
| 104 | void FixedPipelineState::BlendingAttachment::Fill(const Maxwell& regs, std::size_t index) { | ||
| 105 | const auto& mask = regs.color_mask[regs.color_mask_common ? 0 : index]; | ||
| 106 | |||
| 107 | raw = 0; | ||
| 108 | mask_r.Assign(mask.R); | ||
| 109 | mask_g.Assign(mask.G); | ||
| 110 | mask_b.Assign(mask.B); | ||
| 111 | mask_a.Assign(mask.A); | ||
| 112 | |||
| 113 | // TODO: C++20 Use templated lambda to deduplicate code | ||
| 112 | 114 | ||
| 113 | if (!regs.independent_blend_enable) { | 115 | if (!regs.independent_blend_enable) { |
| 114 | const auto& src = regs.blend; | 116 | const auto& src = regs.blend; |
| 115 | if (!src.enable[render_target]) { | 117 | if (!src.enable[index]) { |
| 116 | return default_blending; | 118 | return; |
| 117 | } | 119 | } |
| 118 | return FixedPipelineState::BlendingAttachment( | 120 | equation_rgb.Assign(PackBlendEquation(src.equation_rgb)); |
| 119 | true, src.equation_rgb, src.factor_source_rgb, src.factor_dest_rgb, src.equation_a, | 121 | equation_a.Assign(PackBlendEquation(src.equation_a)); |
| 120 | src.factor_source_a, src.factor_dest_a, components); | 122 | factor_source_rgb.Assign(PackBlendFactor(src.factor_source_rgb)); |
| 123 | factor_dest_rgb.Assign(PackBlendFactor(src.factor_dest_rgb)); | ||
| 124 | factor_source_a.Assign(PackBlendFactor(src.factor_source_a)); | ||
| 125 | factor_dest_a.Assign(PackBlendFactor(src.factor_dest_a)); | ||
| 126 | enable.Assign(1); | ||
| 127 | return; | ||
| 121 | } | 128 | } |
| 122 | 129 | ||
| 123 | if (!regs.blend.enable[render_target]) { | 130 | if (!regs.blend.enable[index]) { |
| 124 | return default_blending; | 131 | return; |
| 125 | } | 132 | } |
| 126 | const auto& src = regs.independent_blend[render_target]; | 133 | const auto& src = regs.independent_blend[index]; |
| 127 | return FixedPipelineState::BlendingAttachment( | 134 | equation_rgb.Assign(PackBlendEquation(src.equation_rgb)); |
| 128 | true, src.equation_rgb, src.factor_source_rgb, src.factor_dest_rgb, src.equation_a, | 135 | equation_a.Assign(PackBlendEquation(src.equation_a)); |
| 129 | src.factor_source_a, src.factor_dest_a, components); | 136 | factor_source_rgb.Assign(PackBlendFactor(src.factor_source_rgb)); |
| 130 | } | 137 | factor_dest_rgb.Assign(PackBlendFactor(src.factor_dest_rgb)); |
| 131 | 138 | factor_source_a.Assign(PackBlendFactor(src.factor_source_a)); | |
| 132 | constexpr FixedPipelineState::ColorBlending GetColorBlendingState(const Maxwell& regs) { | 139 | factor_dest_a.Assign(PackBlendFactor(src.factor_dest_a)); |
| 133 | return FixedPipelineState::ColorBlending( | 140 | enable.Assign(1); |
| 134 | {regs.blend_color.r, regs.blend_color.g, regs.blend_color.b, regs.blend_color.a}, | ||
| 135 | regs.rt_control.count, | ||
| 136 | {GetBlendingAttachmentState(regs, 0), GetBlendingAttachmentState(regs, 1), | ||
| 137 | GetBlendingAttachmentState(regs, 2), GetBlendingAttachmentState(regs, 3), | ||
| 138 | GetBlendingAttachmentState(regs, 4), GetBlendingAttachmentState(regs, 5), | ||
| 139 | GetBlendingAttachmentState(regs, 6), GetBlendingAttachmentState(regs, 7)}); | ||
| 140 | } | 141 | } |
| 141 | 142 | ||
| 142 | } // Anonymous namespace | ||
| 143 | |||
| 144 | std::size_t FixedPipelineState::BlendingAttachment::Hash() const noexcept { | 143 | std::size_t FixedPipelineState::BlendingAttachment::Hash() const noexcept { |
| 145 | return static_cast<std::size_t>(enable) ^ (static_cast<std::size_t>(rgb_equation) << 5) ^ | 144 | return raw; |
| 146 | (static_cast<std::size_t>(src_rgb_func) << 10) ^ | ||
| 147 | (static_cast<std::size_t>(dst_rgb_func) << 15) ^ | ||
| 148 | (static_cast<std::size_t>(a_equation) << 20) ^ | ||
| 149 | (static_cast<std::size_t>(src_a_func) << 25) ^ | ||
| 150 | (static_cast<std::size_t>(dst_a_func) << 30) ^ | ||
| 151 | (static_cast<std::size_t>(components[0]) << 35) ^ | ||
| 152 | (static_cast<std::size_t>(components[1]) << 36) ^ | ||
| 153 | (static_cast<std::size_t>(components[2]) << 37) ^ | ||
| 154 | (static_cast<std::size_t>(components[3]) << 38); | ||
| 155 | } | 145 | } |
| 156 | 146 | ||
| 157 | bool FixedPipelineState::BlendingAttachment::operator==(const BlendingAttachment& rhs) const | 147 | bool FixedPipelineState::BlendingAttachment::operator==(const BlendingAttachment& rhs) const |
| 158 | noexcept { | 148 | noexcept { |
| 159 | return std::tie(enable, rgb_equation, src_rgb_func, dst_rgb_func, a_equation, src_a_func, | 149 | return raw == rhs.raw; |
| 160 | dst_a_func, components) == | ||
| 161 | std::tie(rhs.enable, rhs.rgb_equation, rhs.src_rgb_func, rhs.dst_rgb_func, | ||
| 162 | rhs.a_equation, rhs.src_a_func, rhs.dst_a_func, rhs.components); | ||
| 163 | } | 150 | } |
| 164 | 151 | ||
| 165 | std::size_t FixedPipelineState::VertexInput::Hash() const noexcept { | 152 | std::size_t FixedPipelineState::VertexInput::Hash() const noexcept { |
| @@ -190,16 +177,15 @@ bool FixedPipelineState::DepthStencil::operator==(const DepthStencil& rhs) const | |||
| 190 | } | 177 | } |
| 191 | 178 | ||
| 192 | std::size_t FixedPipelineState::ColorBlending::Hash() const noexcept { | 179 | std::size_t FixedPipelineState::ColorBlending::Hash() const noexcept { |
| 193 | std::size_t hash = attachments_count << 13; | 180 | std::size_t hash = 0; |
| 194 | for (std::size_t rt = 0; rt < static_cast<std::size_t>(attachments_count); ++rt) { | 181 | for (std::size_t rt = 0; rt < std::size(attachments); ++rt) { |
| 195 | boost::hash_combine(hash, attachments[rt].Hash()); | 182 | boost::hash_combine(hash, attachments[rt].Hash()); |
| 196 | } | 183 | } |
| 197 | return hash; | 184 | return hash; |
| 198 | } | 185 | } |
| 199 | 186 | ||
| 200 | bool FixedPipelineState::ColorBlending::operator==(const ColorBlending& rhs) const noexcept { | 187 | bool FixedPipelineState::ColorBlending::operator==(const ColorBlending& rhs) const noexcept { |
| 201 | return std::equal(attachments.begin(), attachments.begin() + attachments_count, | 188 | return attachments == rhs.attachments; |
| 202 | rhs.attachments.begin(), rhs.attachments.begin() + rhs.attachments_count); | ||
| 203 | } | 189 | } |
| 204 | 190 | ||
| 205 | std::size_t FixedPipelineState::Hash() const noexcept { | 191 | std::size_t FixedPipelineState::Hash() const noexcept { |
| @@ -220,7 +206,7 @@ FixedPipelineState GetFixedPipelineState(const Maxwell& regs) { | |||
| 220 | FixedPipelineState fixed_state; | 206 | FixedPipelineState fixed_state; |
| 221 | fixed_state.rasterizer.Fill(regs); | 207 | fixed_state.rasterizer.Fill(regs); |
| 222 | fixed_state.depth_stencil.Fill(regs); | 208 | fixed_state.depth_stencil.Fill(regs); |
| 223 | fixed_state.color_blending = GetColorBlendingState(regs); | 209 | fixed_state.color_blending.Fill(regs); |
| 224 | return fixed_state; | 210 | return fixed_state; |
| 225 | } | 211 | } |
| 226 | 212 | ||
| @@ -312,4 +298,121 @@ Maxwell::LogicOperation FixedPipelineState::UnpackLogicOp(u32 packed) noexcept { | |||
| 312 | return static_cast<Maxwell::LogicOperation>(packed + 0x1500); | 298 | return static_cast<Maxwell::LogicOperation>(packed + 0x1500); |
| 313 | } | 299 | } |
| 314 | 300 | ||
| 301 | u32 FixedPipelineState::PackBlendEquation(Maxwell::Blend::Equation equation) noexcept { | ||
| 302 | switch (equation) { | ||
| 303 | case Maxwell::Blend::Equation::Add: | ||
| 304 | case Maxwell::Blend::Equation::AddGL: | ||
| 305 | return 0; | ||
| 306 | case Maxwell::Blend::Equation::Subtract: | ||
| 307 | case Maxwell::Blend::Equation::SubtractGL: | ||
| 308 | return 1; | ||
| 309 | case Maxwell::Blend::Equation::ReverseSubtract: | ||
| 310 | case Maxwell::Blend::Equation::ReverseSubtractGL: | ||
| 311 | return 2; | ||
| 312 | case Maxwell::Blend::Equation::Min: | ||
| 313 | case Maxwell::Blend::Equation::MinGL: | ||
| 314 | return 3; | ||
| 315 | case Maxwell::Blend::Equation::Max: | ||
| 316 | case Maxwell::Blend::Equation::MaxGL: | ||
| 317 | return 4; | ||
| 318 | } | ||
| 319 | return 0; | ||
| 320 | } | ||
| 321 | |||
| 322 | Maxwell::Blend::Equation FixedPipelineState::UnpackBlendEquation(u32 packed) noexcept { | ||
| 323 | static constexpr std::array LUT = { | ||
| 324 | Maxwell::Blend::Equation::Add, Maxwell::Blend::Equation::Subtract, | ||
| 325 | Maxwell::Blend::Equation::ReverseSubtract, Maxwell::Blend::Equation::Min, | ||
| 326 | Maxwell::Blend::Equation::Max}; | ||
| 327 | return LUT[packed]; | ||
| 328 | } | ||
| 329 | |||
| 330 | u32 FixedPipelineState::PackBlendFactor(Maxwell::Blend::Factor factor) noexcept { | ||
| 331 | switch (factor) { | ||
| 332 | case Maxwell::Blend::Factor::Zero: | ||
| 333 | case Maxwell::Blend::Factor::ZeroGL: | ||
| 334 | return 0; | ||
| 335 | case Maxwell::Blend::Factor::One: | ||
| 336 | case Maxwell::Blend::Factor::OneGL: | ||
| 337 | return 1; | ||
| 338 | case Maxwell::Blend::Factor::SourceColor: | ||
| 339 | case Maxwell::Blend::Factor::SourceColorGL: | ||
| 340 | return 2; | ||
| 341 | case Maxwell::Blend::Factor::OneMinusSourceColor: | ||
| 342 | case Maxwell::Blend::Factor::OneMinusSourceColorGL: | ||
| 343 | return 3; | ||
| 344 | case Maxwell::Blend::Factor::SourceAlpha: | ||
| 345 | case Maxwell::Blend::Factor::SourceAlphaGL: | ||
| 346 | return 4; | ||
| 347 | case Maxwell::Blend::Factor::OneMinusSourceAlpha: | ||
| 348 | case Maxwell::Blend::Factor::OneMinusSourceAlphaGL: | ||
| 349 | return 5; | ||
| 350 | case Maxwell::Blend::Factor::DestAlpha: | ||
| 351 | case Maxwell::Blend::Factor::DestAlphaGL: | ||
| 352 | return 6; | ||
| 353 | case Maxwell::Blend::Factor::OneMinusDestAlpha: | ||
| 354 | case Maxwell::Blend::Factor::OneMinusDestAlphaGL: | ||
| 355 | return 7; | ||
| 356 | case Maxwell::Blend::Factor::DestColor: | ||
| 357 | case Maxwell::Blend::Factor::DestColorGL: | ||
| 358 | return 8; | ||
| 359 | case Maxwell::Blend::Factor::OneMinusDestColor: | ||
| 360 | case Maxwell::Blend::Factor::OneMinusDestColorGL: | ||
| 361 | return 9; | ||
| 362 | case Maxwell::Blend::Factor::SourceAlphaSaturate: | ||
| 363 | case Maxwell::Blend::Factor::SourceAlphaSaturateGL: | ||
| 364 | return 10; | ||
| 365 | case Maxwell::Blend::Factor::Source1Color: | ||
| 366 | case Maxwell::Blend::Factor::Source1ColorGL: | ||
| 367 | return 11; | ||
| 368 | case Maxwell::Blend::Factor::OneMinusSource1Color: | ||
| 369 | case Maxwell::Blend::Factor::OneMinusSource1ColorGL: | ||
| 370 | return 12; | ||
| 371 | case Maxwell::Blend::Factor::Source1Alpha: | ||
| 372 | case Maxwell::Blend::Factor::Source1AlphaGL: | ||
| 373 | return 13; | ||
| 374 | case Maxwell::Blend::Factor::OneMinusSource1Alpha: | ||
| 375 | case Maxwell::Blend::Factor::OneMinusSource1AlphaGL: | ||
| 376 | return 14; | ||
| 377 | case Maxwell::Blend::Factor::ConstantColor: | ||
| 378 | case Maxwell::Blend::Factor::ConstantColorGL: | ||
| 379 | return 15; | ||
| 380 | case Maxwell::Blend::Factor::OneMinusConstantColor: | ||
| 381 | case Maxwell::Blend::Factor::OneMinusConstantColorGL: | ||
| 382 | return 16; | ||
| 383 | case Maxwell::Blend::Factor::ConstantAlpha: | ||
| 384 | case Maxwell::Blend::Factor::ConstantAlphaGL: | ||
| 385 | return 17; | ||
| 386 | case Maxwell::Blend::Factor::OneMinusConstantAlpha: | ||
| 387 | case Maxwell::Blend::Factor::OneMinusConstantAlphaGL: | ||
| 388 | return 18; | ||
| 389 | } | ||
| 390 | return 0; | ||
| 391 | } | ||
| 392 | |||
| 393 | Maxwell::Blend::Factor FixedPipelineState::UnpackBlendFactor(u32 packed) noexcept { | ||
| 394 | static constexpr std::array LUT = { | ||
| 395 | Maxwell::Blend::Factor::Zero, | ||
| 396 | Maxwell::Blend::Factor::One, | ||
| 397 | Maxwell::Blend::Factor::SourceColor, | ||
| 398 | Maxwell::Blend::Factor::OneMinusSourceColor, | ||
| 399 | Maxwell::Blend::Factor::SourceAlpha, | ||
| 400 | Maxwell::Blend::Factor::OneMinusSourceAlpha, | ||
| 401 | Maxwell::Blend::Factor::DestAlpha, | ||
| 402 | Maxwell::Blend::Factor::OneMinusDestAlpha, | ||
| 403 | Maxwell::Blend::Factor::DestColor, | ||
| 404 | Maxwell::Blend::Factor::OneMinusDestColor, | ||
| 405 | Maxwell::Blend::Factor::SourceAlphaSaturate, | ||
| 406 | Maxwell::Blend::Factor::Source1Color, | ||
| 407 | Maxwell::Blend::Factor::OneMinusSource1Color, | ||
| 408 | Maxwell::Blend::Factor::Source1Alpha, | ||
| 409 | Maxwell::Blend::Factor::OneMinusSource1Alpha, | ||
| 410 | Maxwell::Blend::Factor::ConstantColor, | ||
| 411 | Maxwell::Blend::Factor::OneMinusConstantColor, | ||
| 412 | Maxwell::Blend::Factor::ConstantAlpha, | ||
| 413 | Maxwell::Blend::Factor::OneMinusConstantAlpha, | ||
| 414 | }; | ||
| 415 | return LUT[packed]; | ||
| 416 | } | ||
| 417 | |||
| 315 | } // namespace Vulkan | 418 | } // namespace Vulkan |
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.h b/src/video_core/renderer_vulkan/fixed_pipeline_state.h index 75b093e90..9393cb24c 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.h +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.h | |||
| @@ -42,27 +42,29 @@ struct FixedPipelineState { | |||
| 42 | static u32 PackLogicOp(Maxwell::LogicOperation op) noexcept; | 42 | static u32 PackLogicOp(Maxwell::LogicOperation op) noexcept; |
| 43 | static Maxwell::LogicOperation UnpackLogicOp(u32 packed) noexcept; | 43 | static Maxwell::LogicOperation UnpackLogicOp(u32 packed) noexcept; |
| 44 | 44 | ||
| 45 | static u32 PackBlendEquation(Maxwell::Blend::Equation equation) noexcept; | ||
| 46 | static Maxwell::Blend::Equation UnpackBlendEquation(u32 packed) noexcept; | ||
| 47 | |||
| 48 | static u32 PackBlendFactor(Maxwell::Blend::Factor factor) noexcept; | ||
| 49 | static Maxwell::Blend::Factor UnpackBlendFactor(u32 packed) noexcept; | ||
| 50 | |||
| 45 | struct BlendingAttachment { | 51 | struct BlendingAttachment { |
| 46 | constexpr BlendingAttachment(bool enable, Maxwell::Blend::Equation rgb_equation, | 52 | union { |
| 47 | Maxwell::Blend::Factor src_rgb_func, | 53 | u32 raw; |
| 48 | Maxwell::Blend::Factor dst_rgb_func, | 54 | BitField<0, 1, u32> mask_r; |
| 49 | Maxwell::Blend::Equation a_equation, | 55 | BitField<1, 1, u32> mask_g; |
| 50 | Maxwell::Blend::Factor src_a_func, | 56 | BitField<2, 1, u32> mask_b; |
| 51 | Maxwell::Blend::Factor dst_a_func, | 57 | BitField<3, 1, u32> mask_a; |
| 52 | std::array<bool, 4> components) | 58 | BitField<4, 3, u32> equation_rgb; |
| 53 | : enable{enable}, rgb_equation{rgb_equation}, src_rgb_func{src_rgb_func}, | 59 | BitField<7, 3, u32> equation_a; |
| 54 | dst_rgb_func{dst_rgb_func}, a_equation{a_equation}, src_a_func{src_a_func}, | 60 | BitField<10, 5, u32> factor_source_rgb; |
| 55 | dst_a_func{dst_a_func}, components{components} {} | 61 | BitField<15, 5, u32> factor_dest_rgb; |
| 56 | BlendingAttachment() = default; | 62 | BitField<20, 5, u32> factor_source_a; |
| 57 | 63 | BitField<25, 5, u32> factor_dest_a; | |
| 58 | bool enable; | 64 | BitField<30, 1, u32> enable; |
| 59 | Maxwell::Blend::Equation rgb_equation; | 65 | }; |
| 60 | Maxwell::Blend::Factor src_rgb_func; | 66 | |
| 61 | Maxwell::Blend::Factor dst_rgb_func; | 67 | void Fill(const Maxwell& regs, std::size_t index); |
| 62 | Maxwell::Blend::Equation a_equation; | ||
| 63 | Maxwell::Blend::Factor src_a_func; | ||
| 64 | Maxwell::Blend::Factor dst_a_func; | ||
| 65 | std::array<bool, 4> components; | ||
| 66 | 68 | ||
| 67 | std::size_t Hash() const noexcept; | 69 | std::size_t Hash() const noexcept; |
| 68 | 70 | ||
| @@ -71,7 +73,36 @@ struct FixedPipelineState { | |||
| 71 | bool operator!=(const BlendingAttachment& rhs) const noexcept { | 73 | bool operator!=(const BlendingAttachment& rhs) const noexcept { |
| 72 | return !operator==(rhs); | 74 | return !operator==(rhs); |
| 73 | } | 75 | } |
| 76 | |||
| 77 | constexpr std::array<bool, 4> Mask() const noexcept { | ||
| 78 | return {mask_r != 0, mask_g != 0, mask_b != 0, mask_a != 0}; | ||
| 79 | } | ||
| 80 | |||
| 81 | Maxwell::Blend::Equation EquationRGB() const noexcept { | ||
| 82 | return UnpackBlendEquation(equation_rgb.Value()); | ||
| 83 | } | ||
| 84 | |||
| 85 | Maxwell::Blend::Equation EquationAlpha() const noexcept { | ||
| 86 | return UnpackBlendEquation(equation_a.Value()); | ||
| 87 | } | ||
| 88 | |||
| 89 | Maxwell::Blend::Factor SourceRGBFactor() const noexcept { | ||
| 90 | return UnpackBlendFactor(factor_source_rgb.Value()); | ||
| 91 | } | ||
| 92 | |||
| 93 | Maxwell::Blend::Factor DestRGBFactor() const noexcept { | ||
| 94 | return UnpackBlendFactor(factor_dest_rgb.Value()); | ||
| 95 | } | ||
| 96 | |||
| 97 | Maxwell::Blend::Factor SourceAlphaFactor() const noexcept { | ||
| 98 | return UnpackBlendFactor(factor_source_a.Value()); | ||
| 99 | } | ||
| 100 | |||
| 101 | Maxwell::Blend::Factor DestAlphaFactor() const noexcept { | ||
| 102 | return UnpackBlendFactor(factor_dest_a.Value()); | ||
| 103 | } | ||
| 74 | }; | 104 | }; |
| 105 | static_assert(IsHashable<BlendingAttachment>); | ||
| 75 | 106 | ||
| 76 | struct VertexInput { | 107 | struct VertexInput { |
| 77 | union Binding { | 108 | union Binding { |
| @@ -231,15 +262,10 @@ struct FixedPipelineState { | |||
| 231 | static_assert(IsHashable<DepthStencil>); | 262 | static_assert(IsHashable<DepthStencil>); |
| 232 | 263 | ||
| 233 | struct ColorBlending { | 264 | struct ColorBlending { |
| 234 | constexpr ColorBlending( | ||
| 235 | std::array<float, 4> blend_constants, std::size_t attachments_count, | ||
| 236 | std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments) | ||
| 237 | : attachments_count{attachments_count}, attachments{attachments} {} | ||
| 238 | ColorBlending() = default; | ||
| 239 | |||
| 240 | std::size_t attachments_count; | ||
| 241 | std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments; | 265 | std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments; |
| 242 | 266 | ||
| 267 | void Fill(const Maxwell& regs) noexcept; | ||
| 268 | |||
| 243 | std::size_t Hash() const noexcept; | 269 | std::size_t Hash() const noexcept; |
| 244 | 270 | ||
| 245 | bool operator==(const ColorBlending& rhs) const noexcept; | 271 | bool operator==(const ColorBlending& rhs) const noexcept; |
| @@ -248,6 +274,7 @@ struct FixedPipelineState { | |||
| 248 | return !operator==(rhs); | 274 | return !operator==(rhs); |
| 249 | } | 275 | } |
| 250 | }; | 276 | }; |
| 277 | static_assert(IsHashable<ColorBlending>); | ||
| 251 | 278 | ||
| 252 | VertexInput vertex_input; | 279 | VertexInput vertex_input; |
| 253 | Rasterizer rasterizer; | 280 | Rasterizer rasterizer; |
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index e12c26076..343999cf5 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | |||
| @@ -286,29 +286,28 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa | |||
| 286 | depth_stencil_ci.maxDepthBounds = 0.0f; | 286 | depth_stencil_ci.maxDepthBounds = 0.0f; |
| 287 | 287 | ||
| 288 | std::array<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments; | 288 | std::array<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments; |
| 289 | const std::size_t num_attachments = | 289 | const std::size_t num_attachments = renderpass_params.color_attachments.size(); |
| 290 | std::min(cd.attachments_count, renderpass_params.color_attachments.size()); | 290 | for (std::size_t index = 0; index < num_attachments; ++index) { |
| 291 | for (std::size_t i = 0; i < num_attachments; ++i) { | 291 | static constexpr std::array COMPONENT_TABLE = { |
| 292 | static constexpr std::array component_table = { | ||
| 293 | VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_B_BIT, | 292 | VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_B_BIT, |
| 294 | VK_COLOR_COMPONENT_A_BIT}; | 293 | VK_COLOR_COMPONENT_A_BIT}; |
| 295 | const auto& blend = cd.attachments[i]; | 294 | const auto& blend = cd.attachments[index]; |
| 296 | 295 | ||
| 297 | VkColorComponentFlags color_components = 0; | 296 | VkColorComponentFlags color_components = 0; |
| 298 | for (std::size_t j = 0; j < component_table.size(); ++j) { | 297 | for (std::size_t i = 0; i < COMPONENT_TABLE.size(); ++i) { |
| 299 | if (blend.components[j]) { | 298 | if (blend.Mask()[i]) { |
| 300 | color_components |= component_table[j]; | 299 | color_components |= COMPONENT_TABLE[i]; |
| 301 | } | 300 | } |
| 302 | } | 301 | } |
| 303 | 302 | ||
| 304 | VkPipelineColorBlendAttachmentState& attachment = cb_attachments[i]; | 303 | VkPipelineColorBlendAttachmentState& attachment = cb_attachments[index]; |
| 305 | attachment.blendEnable = blend.enable; | 304 | attachment.blendEnable = blend.enable != 0; |
| 306 | attachment.srcColorBlendFactor = MaxwellToVK::BlendFactor(blend.src_rgb_func); | 305 | attachment.srcColorBlendFactor = MaxwellToVK::BlendFactor(blend.SourceRGBFactor()); |
| 307 | attachment.dstColorBlendFactor = MaxwellToVK::BlendFactor(blend.dst_rgb_func); | 306 | attachment.dstColorBlendFactor = MaxwellToVK::BlendFactor(blend.DestRGBFactor()); |
| 308 | attachment.colorBlendOp = MaxwellToVK::BlendEquation(blend.rgb_equation); | 307 | attachment.colorBlendOp = MaxwellToVK::BlendEquation(blend.EquationRGB()); |
| 309 | attachment.srcAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.src_a_func); | 308 | attachment.srcAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.SourceAlphaFactor()); |
| 310 | attachment.dstAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.dst_a_func); | 309 | attachment.dstAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.DestAlphaFactor()); |
| 311 | attachment.alphaBlendOp = MaxwellToVK::BlendEquation(blend.a_equation); | 310 | attachment.alphaBlendOp = MaxwellToVK::BlendEquation(blend.EquationAlpha()); |
| 312 | attachment.colorWriteMask = color_components; | 311 | attachment.colorWriteMask = color_components; |
| 313 | } | 312 | } |
| 314 | 313 | ||