Typedef int4/float4 from a vec4<T> template
This prepares for simplifying assigning the same scalar to all elements.
Bug: b/146224130
Change-Id: I8499c671f98090ae38fd12bab59f30ef360eff69
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39508
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Device/Clipper.hpp b/src/Device/Clipper.hpp
index 4992a57..524a373 100644
--- a/src/Device/Clipper.hpp
+++ b/src/Device/Clipper.hpp
@@ -15,11 +15,12 @@
#ifndef sw_Clipper_hpp
#define sw_Clipper_hpp
+#include "System/Types.hpp"
+
namespace sw {
struct DrawCall;
struct Polygon;
-struct float4;
struct Clipper
{
diff --git a/src/Device/Matrix.hpp b/src/Device/Matrix.hpp
index e4f5ecc..2dd4e3c 100644
--- a/src/Device/Matrix.hpp
+++ b/src/Device/Matrix.hpp
@@ -15,11 +15,12 @@
#ifndef Matrix_hpp
#define Matrix_hpp
+#include "System/Types.hpp"
+
namespace sw {
struct Vector;
struct Point;
-struct float4;
struct Matrix
{
diff --git a/src/System/Types.hpp b/src/System/Types.hpp
index 385d693..5cc67d3 100644
--- a/src/System/Types.hpp
+++ b/src/System/Types.hpp
@@ -71,61 +71,37 @@
typedef ALIGN(8, float) float2[2];
-struct alignas(16) int4
+template<typename T>
+struct alignas(sizeof(T) * 4) vec4
{
- int x;
- int y;
- int z;
- int w;
+ T x;
+ T y;
+ T z;
+ T w;
- int &operator[](int i)
+ T &operator[](int i)
{
return (&x)[i];
}
- const int &operator[](int i) const
+ const T &operator[](int i) const
{
return (&x)[i];
}
- bool operator!=(const int4 &rhs)
+ bool operator!=(const vec4 &rhs)
{
return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w;
}
- bool operator==(const int4 &rhs)
+ bool operator==(const vec4 &rhs)
{
return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
}
};
-struct alignas(16) float4
-{
- float x;
- float y;
- float z;
- float w;
-
- float &operator[](int i)
- {
- return (&x)[i];
- }
-
- const float &operator[](int i) const
- {
- return (&x)[i];
- }
-
- bool operator!=(const float4 &rhs)
- {
- return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w;
- }
-
- bool operator==(const float4 &rhs)
- {
- return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
- }
-};
+using int4 = vec4<int>;
+using float4 = vec4<float>;
inline constexpr float4 vector(float x, float y, float z, float w)
{
diff --git a/src/Vulkan/VkFormat.h b/src/Vulkan/VkFormat.h
index 486bf50..1e20340 100644
--- a/src/Vulkan/VkFormat.h
+++ b/src/Vulkan/VkFormat.h
@@ -15,9 +15,9 @@
#ifndef VK_FORMAT_UTILS_HPP_
#define VK_FORMAT_UTILS_HPP_
-#include <Vulkan/VulkanPlatform.h>
+#include "System/Types.hpp"
-namespace sw { struct float4; }
+#include <Vulkan/VulkanPlatform.h>
namespace vk {