Commit 8bcd1744 by Nicolas Capens Committed by Nicolas Capens

Fix alignment of projected vertex coordinates

Also reorder fields to reduce space wasted on alignment padding, and shuffle writing them to the vertex cache in the same order for consistency. Bug: b/27351835 Change-Id: I06ca0c836aabd9d095893762d973c098f694ee30 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/32788 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent a4308130
......@@ -66,7 +66,7 @@ namespace sw
MAX_TEXTURE_LOD = MIPMAP_LEVELS - 2, // Trilinear accesses lod+1
RENDERTARGETS = 8,
NUM_TEMPORARY_REGISTERS = 4096,
MAX_INTERFACE_COMPONENTS = 32 * 4,
MAX_INTERFACE_COMPONENTS = 32 * 4, // Must be multiple of 4 for 16-byte alignment.
};
}
......
......@@ -888,7 +888,7 @@ namespace sw
if((v0.clipFlags & v1.clipFlags & v2.clipFlags) == Clipper::CLIP_FINITE)
{
Polygon polygon(&v0.builtins.position, &v1.builtins.position, &v2.builtins.position);
Polygon polygon(&v0.position, &v1.position, &v2.position);
int clipFlagsOr = v0.clipFlags | v1.clipFlags | v2.clipFlags;
......@@ -972,8 +972,8 @@ namespace sw
Vertex &v0 = triangle.v0;
Vertex &v1 = triangle.v1;
const float4 &P0 = v0.builtins.position;
const float4 &P1 = v1.builtins.position;
const float4 &P0 = v0.position;
const float4 &P1 = v1.position;
if(P0.w <= 0 && P1.w <= 0)
{
......@@ -1162,17 +1162,17 @@ namespace sw
Vertex &v = triangle.v0;
float pSize = v.builtins.pointSize;
float pSize = v.pointSize;
pSize = clamp(pSize, 1.0f, static_cast<float>(vk::MAX_POINT_SIZE));
float4 P[4];
int C[4];
P[0] = v.builtins.position;
P[1] = v.builtins.position;
P[2] = v.builtins.position;
P[3] = v.builtins.position;
P[0] = v.position;
P[1] = v.position;
P[2] = v.position;
P[3] = v.position;
const float X = pSize * P[0].w * data.halfPixelX[0];
const float Y = pSize * P[0].w * data.halfPixelY[0];
......
......@@ -23,14 +23,12 @@ namespace sw
{
ALIGN(16, struct Vertex
{
float v[MAX_INTERFACE_COMPONENTS];
float4 position;
float pointSize;
struct
{
float4 position;
float pointSize;
} builtins;
struct
int clipFlags;
alignas(16) struct
{
int x;
int y;
......@@ -38,8 +36,7 @@ namespace sw
float w;
} projected;
int clipFlags;
int padding[2];
alignas(16) float v[MAX_INTERFACE_COMPONENTS];
});
static_assert((sizeof(Vertex) & 0x0000000F) == 0, "Vertex size not a multiple of 16 bytes (alignment requirement)");
......
......@@ -86,9 +86,9 @@ namespace sw
Return(0);
}
Int w0w1w2 = *Pointer<Int>(v0 + OFFSET(Vertex, builtins.position.w)) ^
*Pointer<Int>(v1 + OFFSET(Vertex, builtins.position.w)) ^
*Pointer<Int>(v2 + OFFSET(Vertex, builtins.position.w));
Int w0w1w2 = *Pointer<Int>(v0 + OFFSET(Vertex, position.w)) ^
*Pointer<Int>(v1 + OFFSET(Vertex, position.w)) ^
*Pointer<Int>(v2 + OFFSET(Vertex, position.w));
A = IfThenElse(w0w1w2 < 0, -A, A);
......@@ -268,9 +268,9 @@ namespace sw
// Sort by minimum y
if(triangle)
{
Float y0 = *Pointer<Float>(v0 + OFFSET(Vertex, builtins.position.y));
Float y1 = *Pointer<Float>(v1 + OFFSET(Vertex, builtins.position.y));
Float y2 = *Pointer<Float>(v2 + OFFSET(Vertex, builtins.position.y));
Float y0 = *Pointer<Float>(v0 + OFFSET(Vertex, position.y));
Float y1 = *Pointer<Float>(v1 + OFFSET(Vertex, position.y));
Float y2 = *Pointer<Float>(v2 + OFFSET(Vertex, position.y));
Float yMin = Min(Min(y0, y1), y2);
......@@ -281,9 +281,9 @@ namespace sw
// Sort by maximum w
if(triangle)
{
Float w0 = *Pointer<Float>(v0 + OFFSET(Vertex, builtins.position.w));
Float w1 = *Pointer<Float>(v1 + OFFSET(Vertex, builtins.position.w));
Float w2 = *Pointer<Float>(v2 + OFFSET(Vertex, builtins.position.w));
Float w0 = *Pointer<Float>(v0 + OFFSET(Vertex, position.w));
Float w1 = *Pointer<Float>(v1 + OFFSET(Vertex, position.w));
Float w2 = *Pointer<Float>(v2 + OFFSET(Vertex, position.w));
Float wMax = Max(Max(w0, w1), w2);
......@@ -292,13 +292,13 @@ namespace sw
}
*Pointer<Float>(primitive + OFFSET(Primitive, pointCoordX)) =
*Pointer<Float>(v0 + OFFSET(Vertex, builtins.position.x));
*Pointer<Float>(v0 + OFFSET(Vertex, position.x));
*Pointer<Float>(primitive + OFFSET(Primitive, pointCoordY)) =
*Pointer<Float>(v0 + OFFSET(Vertex, builtins.position.y));
*Pointer<Float>(v0 + OFFSET(Vertex, position.y));
Float w0 = *Pointer<Float>(v0 + OFFSET(Vertex, builtins.position.w));
Float w1 = *Pointer<Float>(v1 + OFFSET(Vertex, builtins.position.w));
Float w2 = *Pointer<Float>(v2 + OFFSET(Vertex, builtins.position.w));
Float w0 = *Pointer<Float>(v0 + OFFSET(Vertex, position.w));
Float w1 = *Pointer<Float>(v1 + OFFSET(Vertex, position.w));
Float w2 = *Pointer<Float>(v2 + OFFSET(Vertex, position.w));
Float4 w012;
......
......@@ -15,10 +15,10 @@
#ifndef sw_VertexRoutine_hpp
#define sw_VertexRoutine_hpp
#include "Device/Color.hpp"
#include "Device/VertexProcessor.hpp"
#include "ShaderCore.hpp"
#include "SpirvShader.hpp"
#include "Device/Color.hpp"
#include "Device/VertexProcessor.hpp"
namespace vk
{
......@@ -27,7 +27,7 @@ namespace vk
namespace sw
{
class VertexRoutinePrototype : public Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)>
class VertexRoutinePrototype : public Function<Void(Pointer<Byte>, Pointer<UInt>, Pointer<Byte>, Pointer<Byte>)>
{
public:
VertexRoutinePrototype() : vertex(Arg<0>()), batch(Arg<1>()), task(Arg<2>()), data(Arg<3>()) {}
......@@ -35,7 +35,7 @@ namespace sw
protected:
Pointer<Byte> vertex;
Pointer<Byte> batch;
Pointer<UInt> batch;
Pointer<Byte> task;
Pointer<Byte> data;
};
......@@ -70,7 +70,7 @@ namespace sw
void readInput(UInt &index);
void computeClipFlags();
void writeCache(Pointer<Byte> &cacheLine);
void writeVertex(const Pointer<Byte> &vertex, Pointer<Byte> &cacheLine);
void writeVertex(const Pointer<Byte> &vertex, Pointer<Byte> &cacheEntry);
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment