diff options
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/renderer_vulkan/fixed_pipeline_state.cpp | 60 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/fixed_pipeline_state.h | 54 |
2 files changed, 9 insertions, 105 deletions
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp index 2b053ea74..be1c31978 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp | |||
| @@ -140,66 +140,13 @@ void FixedPipelineState::BlendingAttachment::Fill(const Maxwell& regs, std::size | |||
| 140 | enable.Assign(1); | 140 | enable.Assign(1); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | std::size_t FixedPipelineState::BlendingAttachment::Hash() const noexcept { | ||
| 144 | return raw; | ||
| 145 | } | ||
| 146 | |||
| 147 | bool FixedPipelineState::BlendingAttachment::operator==(const BlendingAttachment& rhs) const | ||
| 148 | noexcept { | ||
| 149 | return raw == rhs.raw; | ||
| 150 | } | ||
| 151 | |||
| 152 | std::size_t FixedPipelineState::VertexInput::Hash() const noexcept { | ||
| 153 | // TODO(Rodrigo): Replace this | ||
| 154 | return Common::CityHash64(reinterpret_cast<const char*>(this), sizeof *this); | ||
| 155 | } | ||
| 156 | |||
| 157 | bool FixedPipelineState::VertexInput::operator==(const VertexInput& rhs) const noexcept { | ||
| 158 | return std::memcmp(this, &rhs, sizeof *this) == 0; | ||
| 159 | } | ||
| 160 | |||
| 161 | std::size_t FixedPipelineState::Rasterizer::Hash() const noexcept { | ||
| 162 | u64 hash = static_cast<u64>(raw) << 32; | ||
| 163 | std::memcpy(&hash, &point_size, sizeof(u32)); | ||
| 164 | return static_cast<std::size_t>(hash); | ||
| 165 | } | ||
| 166 | |||
| 167 | bool FixedPipelineState::Rasterizer::operator==(const Rasterizer& rhs) const noexcept { | ||
| 168 | return raw == rhs.raw && point_size == rhs.point_size; | ||
| 169 | } | ||
| 170 | |||
| 171 | std::size_t FixedPipelineState::DepthStencil::Hash() const noexcept { | ||
| 172 | return raw; | ||
| 173 | } | ||
| 174 | |||
| 175 | bool FixedPipelineState::DepthStencil::operator==(const DepthStencil& rhs) const noexcept { | ||
| 176 | return raw == rhs.raw; | ||
| 177 | } | ||
| 178 | |||
| 179 | std::size_t FixedPipelineState::ColorBlending::Hash() const noexcept { | ||
| 180 | std::size_t hash = 0; | ||
| 181 | for (std::size_t rt = 0; rt < std::size(attachments); ++rt) { | ||
| 182 | boost::hash_combine(hash, attachments[rt].Hash()); | ||
| 183 | } | ||
| 184 | return hash; | ||
| 185 | } | ||
| 186 | |||
| 187 | bool FixedPipelineState::ColorBlending::operator==(const ColorBlending& rhs) const noexcept { | ||
| 188 | return attachments == rhs.attachments; | ||
| 189 | } | ||
| 190 | |||
| 191 | std::size_t FixedPipelineState::Hash() const noexcept { | 143 | std::size_t FixedPipelineState::Hash() const noexcept { |
| 192 | std::size_t hash = 0; | 144 | const u64 hash = Common::CityHash64(reinterpret_cast<const char*>(this), sizeof *this); |
| 193 | boost::hash_combine(hash, vertex_input.Hash()); | 145 | return static_cast<std::size_t>(hash); |
| 194 | boost::hash_combine(hash, rasterizer.Hash()); | ||
| 195 | boost::hash_combine(hash, depth_stencil.Hash()); | ||
| 196 | boost::hash_combine(hash, color_blending.Hash()); | ||
| 197 | return hash; | ||
| 198 | } | 146 | } |
| 199 | 147 | ||
| 200 | bool FixedPipelineState::operator==(const FixedPipelineState& rhs) const noexcept { | 148 | bool FixedPipelineState::operator==(const FixedPipelineState& rhs) const noexcept { |
| 201 | return std::tie(vertex_input, rasterizer, depth_stencil, color_blending) == | 149 | return std::memcmp(this, &rhs, sizeof *this) == 0; |
| 202 | std::tie(rhs.vertex_input, rhs.rasterizer, rhs.depth_stencil, rhs.color_blending); | ||
| 203 | } | 150 | } |
| 204 | 151 | ||
| 205 | FixedPipelineState GetFixedPipelineState(const Maxwell& regs) { | 152 | FixedPipelineState GetFixedPipelineState(const Maxwell& regs) { |
| @@ -207,6 +154,7 @@ FixedPipelineState GetFixedPipelineState(const Maxwell& regs) { | |||
| 207 | fixed_state.rasterizer.Fill(regs); | 154 | fixed_state.rasterizer.Fill(regs); |
| 208 | fixed_state.depth_stencil.Fill(regs); | 155 | fixed_state.depth_stencil.Fill(regs); |
| 209 | fixed_state.color_blending.Fill(regs); | 156 | fixed_state.color_blending.Fill(regs); |
| 157 | fixed_state.padding = {}; | ||
| 210 | return fixed_state; | 158 | return fixed_state; |
| 211 | } | 159 | } |
| 212 | 160 | ||
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.h b/src/video_core/renderer_vulkan/fixed_pipeline_state.h index 9393cb24c..9fe6bdbf9 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.h +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.h | |||
| @@ -17,13 +17,7 @@ namespace Vulkan { | |||
| 17 | 17 | ||
| 18 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; | 18 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; |
| 19 | 19 | ||
| 20 | // TODO(Rodrigo): Optimize this structure. | 20 | struct alignas(32) FixedPipelineState { |
| 21 | |||
| 22 | template <class T> | ||
| 23 | inline constexpr bool IsHashable = std::has_unique_object_representations_v<T>&& | ||
| 24 | std::is_trivially_copyable_v<T>&& std::is_trivially_constructible_v<T>; | ||
| 25 | |||
| 26 | struct FixedPipelineState { | ||
| 27 | static u32 PackComparisonOp(Maxwell::ComparisonOp op) noexcept; | 21 | static u32 PackComparisonOp(Maxwell::ComparisonOp op) noexcept; |
| 28 | static Maxwell::ComparisonOp UnpackComparisonOp(u32 packed) noexcept; | 22 | static Maxwell::ComparisonOp UnpackComparisonOp(u32 packed) noexcept; |
| 29 | 23 | ||
| @@ -102,7 +96,6 @@ struct FixedPipelineState { | |||
| 102 | return UnpackBlendFactor(factor_dest_a.Value()); | 96 | return UnpackBlendFactor(factor_dest_a.Value()); |
| 103 | } | 97 | } |
| 104 | }; | 98 | }; |
| 105 | static_assert(IsHashable<BlendingAttachment>); | ||
| 106 | 99 | ||
| 107 | struct VertexInput { | 100 | struct VertexInput { |
| 108 | union Binding { | 101 | union Binding { |
| @@ -151,16 +144,7 @@ struct FixedPipelineState { | |||
| 151 | attribute.type.Assign(static_cast<u32>(type)); | 144 | attribute.type.Assign(static_cast<u32>(type)); |
| 152 | attribute.size.Assign(static_cast<u32>(size)); | 145 | attribute.size.Assign(static_cast<u32>(size)); |
| 153 | } | 146 | } |
| 154 | |||
| 155 | std::size_t Hash() const noexcept; | ||
| 156 | |||
| 157 | bool operator==(const VertexInput& rhs) const noexcept; | ||
| 158 | |||
| 159 | bool operator!=(const VertexInput& rhs) const noexcept { | ||
| 160 | return !operator==(rhs); | ||
| 161 | } | ||
| 162 | }; | 147 | }; |
| 163 | static_assert(IsHashable<VertexInput>); | ||
| 164 | 148 | ||
| 165 | struct Rasterizer { | 149 | struct Rasterizer { |
| 166 | union { | 150 | union { |
| @@ -187,14 +171,6 @@ struct FixedPipelineState { | |||
| 187 | 171 | ||
| 188 | void Fill(const Maxwell& regs) noexcept; | 172 | void Fill(const Maxwell& regs) noexcept; |
| 189 | 173 | ||
| 190 | std::size_t Hash() const noexcept; | ||
| 191 | |||
| 192 | bool operator==(const Rasterizer& rhs) const noexcept; | ||
| 193 | |||
| 194 | bool operator!=(const Rasterizer& rhs) const noexcept { | ||
| 195 | return !operator==(rhs); | ||
| 196 | } | ||
| 197 | |||
| 198 | constexpr Maxwell::PrimitiveTopology Topology() const noexcept { | 174 | constexpr Maxwell::PrimitiveTopology Topology() const noexcept { |
| 199 | return static_cast<Maxwell::PrimitiveTopology>(topology.Value()); | 175 | return static_cast<Maxwell::PrimitiveTopology>(topology.Value()); |
| 200 | } | 176 | } |
| @@ -207,7 +183,6 @@ struct FixedPipelineState { | |||
| 207 | return UnpackFrontFace(front_face.Value()); | 183 | return UnpackFrontFace(front_face.Value()); |
| 208 | } | 184 | } |
| 209 | }; | 185 | }; |
| 210 | static_assert(IsHashable<Rasterizer>); | ||
| 211 | 186 | ||
| 212 | struct DepthStencil { | 187 | struct DepthStencil { |
| 213 | template <std::size_t Position> | 188 | template <std::size_t Position> |
| @@ -247,39 +222,22 @@ struct FixedPipelineState { | |||
| 247 | 222 | ||
| 248 | void Fill(const Maxwell& regs) noexcept; | 223 | void Fill(const Maxwell& regs) noexcept; |
| 249 | 224 | ||
| 250 | std::size_t Hash() const noexcept; | ||
| 251 | |||
| 252 | bool operator==(const DepthStencil& rhs) const noexcept; | ||
| 253 | |||
| 254 | bool operator!=(const DepthStencil& rhs) const noexcept { | ||
| 255 | return !operator==(rhs); | ||
| 256 | } | ||
| 257 | |||
| 258 | Maxwell::ComparisonOp DepthTestFunc() const noexcept { | 225 | Maxwell::ComparisonOp DepthTestFunc() const noexcept { |
| 259 | return UnpackComparisonOp(depth_test_func); | 226 | return UnpackComparisonOp(depth_test_func); |
| 260 | } | 227 | } |
| 261 | }; | 228 | }; |
| 262 | static_assert(IsHashable<DepthStencil>); | ||
| 263 | 229 | ||
| 264 | struct ColorBlending { | 230 | struct ColorBlending { |
| 265 | std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments; | 231 | std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments; |
| 266 | 232 | ||
| 267 | void Fill(const Maxwell& regs) noexcept; | 233 | void Fill(const Maxwell& regs) noexcept; |
| 268 | |||
| 269 | std::size_t Hash() const noexcept; | ||
| 270 | |||
| 271 | bool operator==(const ColorBlending& rhs) const noexcept; | ||
| 272 | |||
| 273 | bool operator!=(const ColorBlending& rhs) const noexcept { | ||
| 274 | return !operator==(rhs); | ||
| 275 | } | ||
| 276 | }; | 234 | }; |
| 277 | static_assert(IsHashable<ColorBlending>); | ||
| 278 | 235 | ||
| 279 | VertexInput vertex_input; | 236 | VertexInput vertex_input; |
| 280 | Rasterizer rasterizer; | 237 | Rasterizer rasterizer; |
| 281 | DepthStencil depth_stencil; | 238 | DepthStencil depth_stencil; |
| 282 | ColorBlending color_blending; | 239 | ColorBlending color_blending; |
| 240 | std::array<u8, 20> padding; | ||
| 283 | 241 | ||
| 284 | std::size_t Hash() const noexcept; | 242 | std::size_t Hash() const noexcept; |
| 285 | 243 | ||
| @@ -289,12 +247,10 @@ struct FixedPipelineState { | |||
| 289 | return !operator==(rhs); | 247 | return !operator==(rhs); |
| 290 | } | 248 | } |
| 291 | }; | 249 | }; |
| 292 | static_assert(std::is_trivially_copyable_v<FixedPipelineState::BlendingAttachment>); | 250 | static_assert(std::has_unique_object_representations_v<FixedPipelineState>); |
| 293 | static_assert(std::is_trivially_copyable_v<FixedPipelineState::VertexInput>); | ||
| 294 | static_assert(std::is_trivially_copyable_v<FixedPipelineState::Rasterizer>); | ||
| 295 | static_assert(std::is_trivially_copyable_v<FixedPipelineState::DepthStencil>); | ||
| 296 | static_assert(std::is_trivially_copyable_v<FixedPipelineState::ColorBlending>); | ||
| 297 | static_assert(std::is_trivially_copyable_v<FixedPipelineState>); | 251 | static_assert(std::is_trivially_copyable_v<FixedPipelineState>); |
| 252 | static_assert(std::is_trivially_constructible_v<FixedPipelineState>); | ||
| 253 | static_assert(sizeof(FixedPipelineState) % 32 == 0, "Size is not aligned"); | ||
| 298 | 254 | ||
| 299 | FixedPipelineState GetFixedPipelineState(const Maxwell& regs); | 255 | FixedPipelineState GetFixedPipelineState(const Maxwell& regs); |
| 300 | 256 | ||