From b9e3f5eb36318f269257ab60f446b72a63aecc3c Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 24 Dec 2019 17:11:08 -0300 Subject: [PATCH] fixed_pipeline_state: Define symetric operator!= and mark as noexcept Marks as noexcept Hash, operator== and operator!= for consistency. --- .../renderer_vulkan/fixed_pipeline_state.cpp | 41 +++++---- .../renderer_vulkan/fixed_pipeline_state.h | 91 +++++++++++++++---- 2 files changed, 92 insertions(+), 40 deletions(-) diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp index f75c348fe1..5a490f6efb 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp @@ -125,39 +125,39 @@ constexpr FixedPipelineState::Rasterizer GetRasterizerState(const Maxwell& regs) } // Anonymous namespace -std::size_t FixedPipelineState::VertexBinding::Hash() const { +std::size_t FixedPipelineState::VertexBinding::Hash() const noexcept { return (index << stride) ^ divisor; } -bool FixedPipelineState::VertexBinding::operator==(const VertexBinding& rhs) const { +bool FixedPipelineState::VertexBinding::operator==(const VertexBinding& rhs) const noexcept { return std::tie(index, stride, divisor) == std::tie(rhs.index, rhs.stride, rhs.divisor); } -std::size_t FixedPipelineState::VertexAttribute::Hash() const { +std::size_t FixedPipelineState::VertexAttribute::Hash() const noexcept { return static_cast(index) ^ (static_cast(buffer) << 13) ^ (static_cast(type) << 22) ^ (static_cast(size) << 31) ^ (static_cast(offset) << 36); } -bool FixedPipelineState::VertexAttribute::operator==(const VertexAttribute& rhs) const { +bool FixedPipelineState::VertexAttribute::operator==(const VertexAttribute& rhs) const noexcept { return std::tie(index, buffer, type, size, offset) == std::tie(rhs.index, rhs.buffer, rhs.type, rhs.size, rhs.offset); } -std::size_t FixedPipelineState::StencilFace::Hash() const { +std::size_t FixedPipelineState::StencilFace::Hash() const noexcept { return static_cast(action_stencil_fail) ^ (static_cast(action_depth_fail) << 4) ^ (static_cast(action_depth_fail) << 20) ^ (static_cast(action_depth_pass) << 36); } -bool FixedPipelineState::StencilFace::operator==(const StencilFace& rhs) const { +bool FixedPipelineState::StencilFace::operator==(const StencilFace& rhs) const noexcept { return std::tie(action_stencil_fail, action_depth_fail, action_depth_pass, test_func) == std::tie(rhs.action_stencil_fail, rhs.action_depth_fail, rhs.action_depth_pass, rhs.test_func); } -std::size_t FixedPipelineState::BlendingAttachment::Hash() const { +std::size_t FixedPipelineState::BlendingAttachment::Hash() const noexcept { return static_cast(enable) ^ (static_cast(rgb_equation) << 5) ^ (static_cast(src_rgb_func) << 10) ^ (static_cast(dst_rgb_func) << 15) ^ @@ -170,14 +170,15 @@ std::size_t FixedPipelineState::BlendingAttachment::Hash() const { (static_cast(components[3]) << 38); } -bool FixedPipelineState::BlendingAttachment::operator==(const BlendingAttachment& rhs) const { +bool FixedPipelineState::BlendingAttachment::operator==(const BlendingAttachment& rhs) const + noexcept { return std::tie(enable, rgb_equation, src_rgb_func, dst_rgb_func, a_equation, src_a_func, dst_a_func, components) == std::tie(rhs.enable, rhs.rgb_equation, rhs.src_rgb_func, rhs.dst_rgb_func, rhs.a_equation, rhs.src_a_func, rhs.dst_a_func, rhs.components); } -std::size_t FixedPipelineState::VertexInput::Hash() const { +std::size_t FixedPipelineState::VertexInput::Hash() const noexcept { std::size_t hash = num_bindings ^ (num_attributes << 32); for (std::size_t i = 0; i < num_bindings; ++i) { boost::hash_combine(hash, bindings[i].Hash()); @@ -188,37 +189,37 @@ std::size_t FixedPipelineState::VertexInput::Hash() const { return hash; } -bool FixedPipelineState::VertexInput::operator==(const VertexInput& rhs) const { +bool FixedPipelineState::VertexInput::operator==(const VertexInput& rhs) const noexcept { return std::equal(bindings.begin(), bindings.begin() + num_bindings, rhs.bindings.begin(), rhs.bindings.begin() + rhs.num_bindings) && std::equal(attributes.begin(), attributes.begin() + num_attributes, rhs.attributes.begin(), rhs.attributes.begin() + rhs.num_attributes); } -std::size_t FixedPipelineState::InputAssembly::Hash() const { +std::size_t FixedPipelineState::InputAssembly::Hash() const noexcept { std::size_t point_size_int = 0; std::memcpy(&point_size_int, &point_size, sizeof(point_size)); return (static_cast(topology) << 24) ^ (point_size_int << 32) ^ static_cast(primitive_restart_enable); } -bool FixedPipelineState::InputAssembly::operator==(const InputAssembly& rhs) const { +bool FixedPipelineState::InputAssembly::operator==(const InputAssembly& rhs) const noexcept { return std::tie(topology, primitive_restart_enable, point_size) == std::tie(rhs.topology, rhs.primitive_restart_enable, rhs.point_size); } -std::size_t FixedPipelineState::Tessellation::Hash() const { +std::size_t FixedPipelineState::Tessellation::Hash() const noexcept { return static_cast(patch_control_points) ^ (static_cast(primitive) << 6) ^ (static_cast(spacing) << 8) ^ (static_cast(clockwise) << 10); } -bool FixedPipelineState::Tessellation::operator==(const Tessellation& rhs) const { +bool FixedPipelineState::Tessellation::operator==(const Tessellation& rhs) const noexcept { return std::tie(patch_control_points, primitive, spacing, clockwise) == std::tie(rhs.patch_control_points, rhs.primitive, rhs.spacing, rhs.clockwise); } -std::size_t FixedPipelineState::Rasterizer::Hash() const { +std::size_t FixedPipelineState::Rasterizer::Hash() const noexcept { return static_cast(cull_enable) ^ (static_cast(depth_bias_enable) << 1) ^ (static_cast(ndc_minus_one_to_one) << 2) ^ @@ -226,13 +227,13 @@ std::size_t FixedPipelineState::Rasterizer::Hash() const { (static_cast(front_face) << 48); } -bool FixedPipelineState::Rasterizer::operator==(const Rasterizer& rhs) const { +bool FixedPipelineState::Rasterizer::operator==(const Rasterizer& rhs) const noexcept { return std::tie(cull_enable, depth_bias_enable, ndc_minus_one_to_one, cull_face, front_face) == std::tie(rhs.cull_enable, rhs.depth_bias_enable, rhs.ndc_minus_one_to_one, rhs.cull_face, rhs.front_face); } -std::size_t FixedPipelineState::DepthStencil::Hash() const { +std::size_t FixedPipelineState::DepthStencil::Hash() const noexcept { std::size_t hash = static_cast(depth_test_enable) ^ (static_cast(depth_write_enable) << 1) ^ (static_cast(depth_bounds_enable) << 2) ^ @@ -243,7 +244,7 @@ std::size_t FixedPipelineState::DepthStencil::Hash() const { return hash; } -bool FixedPipelineState::DepthStencil::operator==(const DepthStencil& rhs) const { +bool FixedPipelineState::DepthStencil::operator==(const DepthStencil& rhs) const noexcept { return std::tie(depth_test_enable, depth_write_enable, depth_bounds_enable, depth_test_function, stencil_enable, front_stencil, back_stencil) == std::tie(rhs.depth_test_enable, rhs.depth_write_enable, rhs.depth_bounds_enable, @@ -251,7 +252,7 @@ bool FixedPipelineState::DepthStencil::operator==(const DepthStencil& rhs) const rhs.back_stencil); } -std::size_t FixedPipelineState::ColorBlending::Hash() const { +std::size_t FixedPipelineState::ColorBlending::Hash() const noexcept { std::size_t hash = attachments_count << 13; for (std::size_t rt = 0; rt < static_cast(attachments_count); ++rt) { boost::hash_combine(hash, attachments[rt].Hash()); @@ -259,7 +260,7 @@ std::size_t FixedPipelineState::ColorBlending::Hash() const { return hash; } -bool FixedPipelineState::ColorBlending::operator==(const ColorBlending& rhs) const { +bool FixedPipelineState::ColorBlending::operator==(const ColorBlending& rhs) const noexcept { return std::equal(attachments.begin(), attachments.begin() + attachments_count, rhs.attachments.begin(), rhs.attachments.begin() + rhs.attachments_count); } diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.h b/src/video_core/renderer_vulkan/fixed_pipeline_state.h index 01f82be68d..04152c0d4e 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.h +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.h @@ -30,8 +30,13 @@ struct FixedPipelineState { u32 stride; u32 divisor; - std::size_t Hash() const; - bool operator==(const VertexBinding& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const VertexBinding& rhs) const noexcept; + + bool operator!=(const VertexBinding& rhs) const noexcept { + return !operator==(rhs); + } }; struct VertexAttribute { @@ -46,8 +51,13 @@ struct FixedPipelineState { Maxwell::VertexAttribute::Size size; u32 offset; - std::size_t Hash() const; - bool operator==(const VertexAttribute& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const VertexAttribute& rhs) const noexcept; + + bool operator!=(const VertexAttribute& rhs) const noexcept { + return !operator==(rhs); + } }; struct StencilFace { @@ -63,8 +73,13 @@ struct FixedPipelineState { Maxwell::StencilOp action_depth_pass; Maxwell::ComparisonOp test_func; - std::size_t Hash() const; - bool operator==(const StencilFace& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const StencilFace& rhs) const noexcept; + + bool operator!=(const StencilFace& rhs) const noexcept { + return !operator==(rhs); + } }; struct BlendingAttachment { @@ -89,8 +104,13 @@ struct FixedPipelineState { Maxwell::Blend::Factor dst_a_func; std::array components; - std::size_t Hash() const; - bool operator==(const BlendingAttachment& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const BlendingAttachment& rhs) const noexcept; + + bool operator!=(const BlendingAttachment& rhs) const noexcept { + return !operator==(rhs); + } }; struct VertexInput { @@ -99,8 +119,13 @@ struct FixedPipelineState { std::array bindings; std::array attributes; - std::size_t Hash() const; - bool operator==(const VertexInput& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const VertexInput& rhs) const noexcept; + + bool operator!=(const VertexInput& rhs) const noexcept { + return !operator==(rhs); + } }; struct InputAssembly { @@ -114,8 +139,13 @@ struct FixedPipelineState { bool primitive_restart_enable; float point_size; - std::size_t Hash() const; - bool operator==(const InputAssembly& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const InputAssembly& rhs) const noexcept; + + bool operator!=(const InputAssembly& rhs) const noexcept { + return !operator==(rhs); + } }; struct Tessellation { @@ -130,8 +160,13 @@ struct FixedPipelineState { Maxwell::TessellationSpacing spacing; bool clockwise; - std::size_t Hash() const; - bool operator==(const Tessellation& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const Tessellation& rhs) const noexcept; + + bool operator!=(const Tessellation& rhs) const noexcept { + return !operator==(rhs); + } }; struct Rasterizer { @@ -148,8 +183,13 @@ struct FixedPipelineState { Maxwell::Cull::CullFace cull_face; Maxwell::Cull::FrontFace front_face; - std::size_t Hash() const; - bool operator==(const Rasterizer& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const Rasterizer& rhs) const noexcept; + + bool operator!=(const Rasterizer& rhs) const noexcept { + return !operator==(rhs); + } }; struct DepthStencil { @@ -171,8 +211,13 @@ struct FixedPipelineState { StencilFace front_stencil; StencilFace back_stencil; - std::size_t Hash() const; - bool operator==(const DepthStencil& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const DepthStencil& rhs) const noexcept; + + bool operator!=(const DepthStencil& rhs) const noexcept { + return !operator==(rhs); + } }; struct ColorBlending { @@ -185,11 +230,17 @@ struct FixedPipelineState { std::size_t attachments_count; std::array attachments; - std::size_t Hash() const; - bool operator==(const ColorBlending& rhs) const; + std::size_t Hash() const noexcept; + + bool operator==(const ColorBlending& rhs) const noexcept; + + bool operator!=(const ColorBlending& rhs) const noexcept { + return !operator==(rhs); + } }; std::size_t Hash() const noexcept; + bool operator==(const FixedPipelineState& rhs) const noexcept; bool operator!=(const FixedPipelineState& rhs) const noexcept {