IDs: Move inline impls below class.
Addresses comments on:
https://swiftshader-review.googlesource.com/c/SwiftShader/+/38891/1/src/Vulkan/Debug/ID.hpp#34
Bug: b/145351270
Change-Id: If1aabf0b2d2ac7e992bfd59a19eeeba57cb7f84e
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39248
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvID.hpp b/src/Pipeline/SpirvID.hpp
index 35b910a..67ca59d 100644
--- a/src/Pipeline/SpirvID.hpp
+++ b/src/Pipeline/SpirvID.hpp
@@ -29,29 +29,56 @@
class SpirvID
{
public:
- SpirvID()
- : id(0)
- {}
- SpirvID(uint32_t id)
- : id(id)
- {}
- bool operator==(const SpirvID<T> &rhs) const { return id == rhs.id; }
- bool operator!=(const SpirvID<T> &rhs) const { return id != rhs.id; }
- bool operator<(const SpirvID<T> &rhs) const { return id < rhs.id; }
+ SpirvID() = default;
+ inline SpirvID(uint32_t id);
+ inline bool operator==(const SpirvID<T> &rhs) const;
+ inline bool operator!=(const SpirvID<T> &rhs) const;
+ inline bool operator<(const SpirvID<T> &rhs) const;
// value returns the numerical value of the identifier.
- uint32_t value() const { return id; }
+ inline uint32_t value() const;
private:
- uint32_t id;
+ uint32_t id = 0;
};
+template<typename T>
+SpirvID<T>::SpirvID(uint32_t id)
+ : id(id)
+{}
+
+template<typename T>
+bool SpirvID<T>::operator==(const SpirvID<T> &rhs) const
+{
+ return id == rhs.id;
+}
+
+template<typename T>
+bool SpirvID<T>::operator!=(const SpirvID<T> &rhs) const
+{
+ return id != rhs.id;
+}
+
+template<typename T>
+bool SpirvID<T>::operator<(const SpirvID<T> &rhs) const
+{
+ return id < rhs.id;
+}
+
+template<typename T>
+uint32_t SpirvID<T>::value() const
+{
+ return id;
+}
+
// HandleMap<T> is an unordered map of SpirvID<T> to T.
template<typename T>
using HandleMap = std::unordered_map<SpirvID<T>, T>;
+
} // namespace sw
namespace std {
+
// std::hash implementation for sw::SpirvID<T>
template<typename T>
struct hash<sw::SpirvID<T> >
diff --git a/src/Vulkan/Debug/ID.hpp b/src/Vulkan/Debug/ID.hpp
index b818b98..59ba55e 100644
--- a/src/Vulkan/Debug/ID.hpp
+++ b/src/Vulkan/Debug/ID.hpp
@@ -29,25 +29,63 @@
class ID
{
public:
- inline ID()
- : id(0)
- {}
- inline ID(int id)
- : id(id)
- {}
- inline bool operator==(const ID<T> &rhs) const { return id == rhs.id; }
- inline bool operator!=(const ID<T> &rhs) const { return id != rhs.id; }
- inline bool operator<(const ID<T> &rhs) const { return id < rhs.id; }
- inline ID operator++() { return ID(++id); }
- inline ID operator++(int) { return ID(id++); }
+ ID() = default;
+
+ inline ID(int id);
+ inline bool operator==(const ID<T> &rhs) const;
+ inline bool operator!=(const ID<T> &rhs) const;
+ inline bool operator<(const ID<T> &rhs) const;
+ inline ID operator++();
+ inline ID operator++(int);
// value returns the numerical value of the identifier.
- inline int value() const { return id; }
+ inline int value() const;
private:
- int id;
+ int id = 0;
};
+template<typename T>
+ID<T>::ID(int id)
+ : id(id)
+{}
+
+template<typename T>
+bool ID<T>::operator==(const ID<T> &rhs) const
+{
+ return id == rhs.id;
+}
+
+template<typename T>
+bool ID<T>::operator!=(const ID<T> &rhs) const
+{
+ return id != rhs.id;
+}
+
+template<typename T>
+bool ID<T>::operator<(const ID<T> &rhs) const
+{
+ return id < rhs.id;
+}
+
+template<typename T>
+ID<T> ID<T>::operator++()
+{
+ return ID(++id);
+}
+
+template<typename T>
+ID<T> ID<T>::operator++(int)
+{
+ return ID(id++);
+}
+
+template<typename T>
+int ID<T>::value() const
+{
+ return id;
+}
+
} // namespace dbg
} // namespace vk