Add support for quad primitives. Bug 18962347 Change-Id: Id13ef61a8aaacd88afb0b3e634ae971d44e39cd7 Reviewed-on: https://swiftshader-review.googlesource.com/1860 Reviewed-by: Nicolas Capens <capn@google.com> Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Renderer/Context.cpp b/src/Renderer/Context.cpp index dedd574..9e21de8 100644 --- a/src/Renderer/Context.cpp +++ b/src/Renderer/Context.cpp
@@ -94,6 +94,8 @@ case DRAW_INDEXEDTRIANGLESTRIP32: case DRAW_INDEXEDTRIANGLEFAN32: return fillModeAware ? fillMode == FILL_VERTEX : false; + case DRAW_QUADLIST: + return false; default: ASSERT(false); } @@ -136,6 +138,8 @@ case DRAW_INDEXEDTRIANGLESTRIP32: case DRAW_INDEXEDTRIANGLEFAN32: return fillModeAware ? fillMode == FILL_WIREFRAME : false; + case DRAW_QUADLIST: + return false; default: ASSERT(false); } @@ -178,6 +182,9 @@ case DRAW_INDEXEDTRIANGLESTRIP32: case DRAW_INDEXEDTRIANGLEFAN32: return fillModeAware ? fillMode == FILL_SOLID : true; + case DRAW_QUADLIST: + // Quads are broken up into triangles + return fillModeAware ? fillMode == FILL_SOLID : true; default: ASSERT(false); }
diff --git a/src/Renderer/Context.hpp b/src/Renderer/Context.hpp index 848794a..208b8f3 100644 --- a/src/Renderer/Context.hpp +++ b/src/Renderer/Context.hpp
@@ -58,6 +58,7 @@ DRAW_TRIANGLELIST, DRAW_TRIANGLESTRIP, DRAW_TRIANGLEFAN, + DRAW_QUADLIST, DRAW_INDEXEDPOINTLIST8, DRAW_INDEXEDLINELIST8,
diff --git a/src/Renderer/QuadRasterizer.cpp b/src/Renderer/QuadRasterizer.cpp index f189bd3..543c0ce 100644 --- a/src/Renderer/QuadRasterizer.cpp +++ b/src/Renderer/QuadRasterizer.cpp
@@ -122,36 +122,28 @@ Do { - Int x0; - Int x1; - Int x2; - - x0 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span))); - x2 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span))); - x0 = Min(x0, x2); + Int x0a = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span))); + Int x0b = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span))); + Int x0 = Min(x0a, x0b); for(unsigned int q = 1; q < state.multiSample; q++) { - Int x0q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span))); - Int x2q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span))); - x0q = Min(x0q, x2q); - - x0 = Min(x0q, x0); + x0a = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span))); + x0b = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span))); + x0 = Min(x0, Min(x0a, x0b)); } x0 &= 0xFFFFFFFE; - x1 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span))); - x2 = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span))); - x1 = Max(x1, x2); + Int x1a = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span))); + Int x1b = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span))); + Int x1 = Max(x1a, x1b); for(unsigned int q = 1; q < state.multiSample; q++) { - Int x1q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span))); - Int x2q = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span))); - x1q = Max(x1q, x2q); - - x1 = Max(x1q, x1); + x1a = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span))); + x1b = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->right) + (y + 1) * sizeof(Primitive::Span))); + x1 = Max(x1, Max(x1a, x1b)); } Float4 yyyy = Float4(Float(y)) + *Pointer<Float4>(r.primitive + OFFSET(Primitive,yQuad), 16);
diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp index df794ab..7560900 100644 --- a/src/Renderer/Renderer.cpp +++ b/src/Renderer/Renderer.cpp
@@ -942,7 +942,7 @@ pixelProgress[cluster].executing = false; } - void Renderer::processPrimitiveVertices(int unit, unsigned int start, unsigned int count, unsigned int loop, int thread) + void Renderer::processPrimitiveVertices(int unit, unsigned int start, unsigned int triangleCount, unsigned int loop, int thread) { Triangle *triangle = triangleBatch[unit]; DrawCall *draw = drawList[primitiveProgress[unit].drawCall % DRAW_COUNT]; @@ -966,7 +966,7 @@ { unsigned int index = start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index; batch[i][1] = index; @@ -980,7 +980,7 @@ { unsigned int index = 2 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index + 0; batch[i][1] = index + 1; @@ -994,7 +994,7 @@ { unsigned int index = start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index + 0; batch[i][1] = index + 1; @@ -1008,7 +1008,7 @@ { unsigned int index = start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = (index + 0) % loop; batch[i][1] = (index + 1) % loop; @@ -1022,7 +1022,7 @@ { unsigned int index = 3 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index + 0; batch[i][1] = index + 1; @@ -1036,7 +1036,7 @@ { unsigned int index = start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index + 0; batch[i][1] = index + (index & 1) + 1; @@ -1050,7 +1050,7 @@ { unsigned int index = start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index + 1; batch[i][1] = index + 2; @@ -1064,7 +1064,7 @@ { const unsigned char *index = (const unsigned char*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = *index; batch[i][1] = *index; @@ -1078,7 +1078,7 @@ { const unsigned short *index = (const unsigned short*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = *index; batch[i][1] = *index; @@ -1092,7 +1092,7 @@ { const unsigned int *index = (const unsigned int*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = *index; batch[i][1] = *index; @@ -1106,7 +1106,7 @@ { const unsigned char *index = (const unsigned char*)indices + 2 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1120,7 +1120,7 @@ { const unsigned short *index = (const unsigned short*)indices + 2 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1134,7 +1134,7 @@ { const unsigned int *index = (const unsigned int*)indices + 2 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1148,7 +1148,7 @@ { const unsigned char *index = (const unsigned char*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1162,7 +1162,7 @@ { const unsigned short *index = (const unsigned short*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1176,7 +1176,7 @@ { const unsigned int *index = (const unsigned int*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1190,7 +1190,7 @@ { const unsigned char *index = (const unsigned char*)indices; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[(start + i + 0) % loop]; batch[i][1] = index[(start + i + 1) % loop]; @@ -1202,7 +1202,7 @@ { const unsigned short *index = (const unsigned short*)indices; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[(start + i + 0) % loop]; batch[i][1] = index[(start + i + 1) % loop]; @@ -1214,7 +1214,7 @@ { const unsigned int *index = (const unsigned int*)indices; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[(start + i + 0) % loop]; batch[i][1] = index[(start + i + 1) % loop]; @@ -1226,7 +1226,7 @@ { const unsigned char *index = (const unsigned char*)indices + 3 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1240,7 +1240,7 @@ { const unsigned short *index = (const unsigned short*)indices + 3 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1254,7 +1254,7 @@ { const unsigned int *index = (const unsigned int*)indices + 3 * start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[1]; @@ -1268,7 +1268,7 @@ { const unsigned char *index = (const unsigned char*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[((start + i) & 1) + 1]; @@ -1282,7 +1282,7 @@ { const unsigned short *index = (const unsigned short*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[((start + i) & 1) + 1]; @@ -1296,7 +1296,7 @@ { const unsigned int *index = (const unsigned int*)indices + start; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[0]; batch[i][1] = index[((start + i) & 1) + 1]; @@ -1310,7 +1310,7 @@ { const unsigned char *index = (const unsigned char*)indices; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[start + i + 1]; batch[i][1] = index[start + i + 2]; @@ -1322,7 +1322,7 @@ { const unsigned short *index = (const unsigned short*)indices; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[start + i + 1]; batch[i][1] = index[start + i + 2]; @@ -1334,7 +1334,7 @@ { const unsigned int *index = (const unsigned int*)indices; - for(unsigned int i = 0; i < count; i++) + for(unsigned int i = 0; i < triangleCount; i++) { batch[i][0] = index[start + i + 1]; batch[i][1] = index[start + i + 2]; @@ -1342,11 +1342,29 @@ } } break; + case DRAW_QUADLIST: + { + unsigned int index = 4 * start / 2; + + for(unsigned int i = 0; i < triangleCount; i += 2) + { + batch[i+0][0] = index + 0; + batch[i+0][1] = index + 1; + batch[i+0][2] = index + 2; + + batch[i+1][0] = index + 0; + batch[i+1][1] = index + 2; + batch[i+1][2] = index + 3; + + index += 4; + } + } + break; default: ASSERT(false); } - task->count = count * 3; + task->vertexCount = triangleCount * 3; vertexRoutine(&triangle->v0, (unsigned int*)&batch, task, data); }
diff --git a/src/Renderer/VertexProcessor.hpp b/src/Renderer/VertexProcessor.hpp index 81aa451..4f665af 100644 --- a/src/Renderer/VertexProcessor.hpp +++ b/src/Renderer/VertexProcessor.hpp
@@ -32,7 +32,7 @@ struct VertexTask { - unsigned int count; + unsigned int vertexCount; VertexCache vertexCache; };