Make the number of vertex inputs configurable.
Change-Id: Ic078acae24dd2b2361a32498b49238b98e0ac0d1
Reviewed-on: https://swiftshader-review.googlesource.com/5386
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/D3D9/Capabilities.hpp b/src/D3D9/Capabilities.hpp
index 02e5d86..768ad1d 100644
--- a/src/D3D9/Capabilities.hpp
+++ b/src/D3D9/Capabilities.hpp
@@ -473,6 +473,7 @@
{
MAX_VERTEX_SHADER_CONST = 256,
MAX_PIXEL_SHADER_CONST = 224,
+ MAX_VERTEX_INPUTS = 16,
MAX_VERTEX_OUTPUTS = 12,
MAX_PIXEL_INPUTS = 10,
};
@@ -480,12 +481,14 @@
// Shader Model 3.0 requirements
META_ASSERT(MAX_VERTEX_SHADER_CONST >= 256);
META_ASSERT(MAX_PIXEL_SHADER_CONST == 224);
+ META_ASSERT(MAX_VERTEX_INPUTS == 16);
META_ASSERT(MAX_VERTEX_OUTPUTS == 12);
META_ASSERT(MAX_PIXEL_INPUTS == 10);
// Back-end minimum requirements
META_ASSERT(sw::VERTEX_UNIFORM_VECTORS >= MAX_VERTEX_SHADER_CONST);
META_ASSERT(sw::FRAGMENT_UNIFORM_VECTORS >= MAX_PIXEL_SHADER_CONST);
+ META_ASSERT(sw::MAX_VERTEX_INPUTS >= MAX_VERTEX_INPUTS);
META_ASSERT(sw::MAX_VERTEX_OUTPUTS >= MAX_VERTEX_OUTPUTS);
META_ASSERT(sw::MAX_FRAGMENT_INPUTS >= MAX_PIXEL_INPUTS);
}
diff --git a/src/D3D9/Direct3DDevice9.cpp b/src/D3D9/Direct3DDevice9.cpp
index 3414a4a..96a0b9a 100644
--- a/src/D3D9/Direct3DDevice9.cpp
+++ b/src/D3D9/Direct3DDevice9.cpp
@@ -93,7 +93,7 @@
vertexShaderConstantsFDirty = 0;
vertexShaderConstantsIDirty = 0;
- for(int i = 0; i < 16; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
dataStream[i] = 0;
streamStride[i] = 0;
@@ -231,7 +231,7 @@
}
}
- for(int i = 0; i < 16; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
if(dataStream[i])
{
@@ -5787,7 +5787,7 @@
if(!vertexDeclaration->isPreTransformed())
{
- for(int i = 0; i < 16; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
if(usage == shader->input[i].usage &&
index == shader->input[i].index)
diff --git a/src/D3D9/Direct3DDevice9.hpp b/src/D3D9/Direct3DDevice9.hpp
index da78c9b..4ca3442 100644
--- a/src/D3D9/Direct3DDevice9.hpp
+++ b/src/D3D9/Direct3DDevice9.hpp
@@ -277,10 +277,10 @@
int vertexShaderConstantB[16];
Direct3DVertexDeclaration9 *vertexDeclaration;
- Direct3DVertexBuffer9 *dataStream[16];
- int streamStride[16];
- int streamOffset[16];
- unsigned int streamSourceFreq[16];
+ Direct3DVertexBuffer9 *dataStream[MAX_VERTEX_INPUTS];
+ int streamStride[MAX_VERTEX_INPUTS];
+ int streamOffset[MAX_VERTEX_INPUTS];
+ unsigned int streamSourceFreq[MAX_VERTEX_INPUTS];
Direct3DIndexBuffer9 *indexData;
Direct3DSwapChain9 *swapChain;
diff --git a/src/D3D9/Direct3DStateBlock9.cpp b/src/D3D9/Direct3DStateBlock9.cpp
index 3971413..48ee0c5 100644
--- a/src/D3D9/Direct3DStateBlock9.cpp
+++ b/src/D3D9/Direct3DStateBlock9.cpp
@@ -33,7 +33,7 @@
indexBuffer = 0;
- for(int stream = 0; stream < 16; stream++)
+ for(int stream = 0; stream < MAX_VERTEX_INPUTS; stream++)
{
streamSource[stream].vertexBuffer = 0;
}
@@ -185,7 +185,7 @@
}
}
- for(int stream = 0; stream < 16; stream++)
+ for(int stream = 0; stream < MAX_VERTEX_INPUTS; stream++)
{
if(streamSourceCaptured[stream])
{
@@ -405,7 +405,7 @@
}
}
- for(int stream = 0; stream < 16; stream++)
+ for(int stream = 0; stream < MAX_VERTEX_INPUTS; stream++)
{
if(streamSourceCaptured[stream])
{
@@ -840,7 +840,7 @@
}
}
- for(int stream = 0; stream < 16; stream++)
+ for(int stream = 0; stream < MAX_VERTEX_INPUTS; stream++)
{
streamSourceCaptured[stream] = false;
streamSourceFrequencyCaptured[stream] = false;
@@ -928,7 +928,7 @@
indexBuffer = 0;
}
- for(int stream = 0; stream < 16; stream++)
+ for(int stream = 0; stream < MAX_VERTEX_INPUTS; stream++)
{
if(streamSource[stream].vertexBuffer)
{
@@ -1223,7 +1223,7 @@
void Direct3DStateBlock9::captureStreamSourceFrequencies()
{
- for(int stream = 0; stream < 16; stream++)
+ for(int stream = 0; stream < MAX_VERTEX_INPUTS; stream++)
{
streamSourceFrequencyCaptured[stream] = true;
device->GetStreamSourceFreq(stream, &streamSourceFrequency[stream]);
@@ -1272,7 +1272,7 @@
void Direct3DStateBlock9::captureVertexStreams()
{
- for(int stream = 0; stream < 16; stream++)
+ for(int stream = 0; stream < MAX_VERTEX_INPUTS; stream++)
{
streamSourceCaptured[stream] = true;
device->GetStreamSource(stream, reinterpret_cast<IDirect3DVertexBuffer9**>(&streamSource[stream].vertexBuffer), &streamSource[stream].offset, &streamSource[stream].stride);
diff --git a/src/D3D9/Direct3DStateBlock9.hpp b/src/D3D9/Direct3DStateBlock9.hpp
index 31fa6e8..ed709b0 100644
--- a/src/D3D9/Direct3DStateBlock9.hpp
+++ b/src/D3D9/Direct3DStateBlock9.hpp
@@ -139,17 +139,17 @@
bool samplerStateCaptured[16 + 4][D3DSAMP_DMAPOFFSET + 1];
unsigned long samplerState[16 + 4][D3DSAMP_DMAPOFFSET + 1];
- bool streamSourceCaptured[16];
+ bool streamSourceCaptured[MAX_VERTEX_INPUTS];
struct StreamSource
{
Direct3DVertexBuffer9 *vertexBuffer;
unsigned int offset;
unsigned int stride;
};
- StreamSource streamSource[16];
+ StreamSource streamSource[MAX_VERTEX_INPUTS];
- bool streamSourceFrequencyCaptured[16];
- unsigned int streamSourceFrequency[16];
+ bool streamSourceFrequencyCaptured[MAX_VERTEX_INPUTS];
+ unsigned int streamSourceFrequency[MAX_VERTEX_INPUTS];
bool textureCaptured[16 + 4];
Direct3DBaseTexture9 *texture[16 + 4];
diff --git a/src/D3D9/Direct3DVertexDeclaration9.cpp b/src/D3D9/Direct3DVertexDeclaration9.cpp
index 1cb5b2b..56718a1 100644
--- a/src/D3D9/Direct3DVertexDeclaration9.cpp
+++ b/src/D3D9/Direct3DVertexDeclaration9.cpp
@@ -51,7 +51,7 @@
{
this->FVF = FVF;
- vertexElement = new D3DVERTEXELEMENT9[16];
+ vertexElement = new D3DVERTEXELEMENT9[MAX_VERTEX_INPUTS];
numElements = 0;
int offset = 0;
diff --git a/src/Main/Config.hpp b/src/Main/Config.hpp
index b0839b5..9b67ac1 100644
--- a/src/Main/Config.hpp
+++ b/src/Main/Config.hpp
@@ -81,12 +81,12 @@
{
OUTLINE_RESOLUTION = 4096, // Maximum vertical resolution of the render target
MIPMAP_LEVELS = 14,
- VERTEX_ATTRIBUTES = 16,
TEXTURE_IMAGE_UNITS = 16,
VERTEX_TEXTURE_IMAGE_UNITS = 16,
TOTAL_IMAGE_UNITS = TEXTURE_IMAGE_UNITS + VERTEX_TEXTURE_IMAGE_UNITS,
FRAGMENT_UNIFORM_VECTORS = 224,
VERTEX_UNIFORM_VECTORS = 256,
+ MAX_VERTEX_INPUTS = 16,
MAX_VERTEX_OUTPUTS = 12,
MAX_FRAGMENT_INPUTS = 10,
MAX_FRAGMENT_UNIFORM_BLOCKS = 12,
diff --git a/src/OpenGL/compiler/OutputASM.cpp b/src/OpenGL/compiler/OutputASM.cpp
index 43ba172..8cf572b 100644
--- a/src/OpenGL/compiler/OutputASM.cpp
+++ b/src/OpenGL/compiler/OutputASM.cpp
@@ -2908,7 +2908,7 @@
const TType &type = attribute->getType();
int registerCount = attribute->totalRegisterCount();
- if(vertexShader && (index + registerCount) <= sw::VertexShader::MAX_INPUT_ATTRIBUTES)
+ if(vertexShader && (index + registerCount) <= sw::MAX_VERTEX_INPUTS)
{
for(int i = 0; i < registerCount; i++)
{
diff --git a/src/OpenGL/libGLES_CM/Context.h b/src/OpenGL/libGLES_CM/Context.h
index 9051e02..1ee5699 100644
--- a/src/OpenGL/libGLES_CM/Context.h
+++ b/src/OpenGL/libGLES_CM/Context.h
@@ -63,7 +63,7 @@
enum
{
- MAX_VERTEX_ATTRIBS = sw::VERTEX_ATTRIBUTES,
+ MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS,
MAX_VARYING_VECTORS = 10,
MAX_TEXTURE_UNITS = 2,
MAX_DRAW_BUFFERS = 1,
diff --git a/src/OpenGL/libGLESv2/Context.h b/src/OpenGL/libGLESv2/Context.h
index 6477734..d6e09ee 100644
--- a/src/OpenGL/libGLESv2/Context.h
+++ b/src/OpenGL/libGLESv2/Context.h
@@ -74,7 +74,7 @@
enum
{
- MAX_VERTEX_ATTRIBS = sw::VERTEX_ATTRIBUTES,
+ MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS,
MAX_UNIFORM_VECTORS = 256, // Device limit
MAX_VERTEX_UNIFORM_VECTORS = sw::VERTEX_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
MAX_VARYING_VECTORS = 10,
diff --git a/src/Renderer/Context.cpp b/src/Renderer/Context.cpp
index bc7f37f..b206dde 100644
--- a/src/Renderer/Context.cpp
+++ b/src/Renderer/Context.cpp
@@ -204,7 +204,7 @@
}
// Set vertex streams to null stream
- for(int i = 0; i < VERTEX_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
input[i].defaults();
}
diff --git a/src/Renderer/Context.hpp b/src/Renderer/Context.hpp
index 6e68ecb..f1e59ba 100644
--- a/src/Renderer/Context.hpp
+++ b/src/Renderer/Context.hpp
@@ -442,7 +442,7 @@
bool colorUsed();
Resource *texture[TOTAL_IMAGE_UNITS];
- Stream input[VERTEX_ATTRIBUTES];
+ Stream input[MAX_VERTEX_INPUTS];
Resource *indexBuffer;
bool preTransformed; // FIXME: Private
diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp
index 712d74a..2cb19e3 100644
--- a/src/Renderer/Renderer.cpp
+++ b/src/Renderer/Renderer.cpp
@@ -335,7 +335,7 @@
draw->setupPrimitives = setupPrimitives;
draw->setupState = setupState;
- for(int i = 0; i < VERTEX_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
draw->vertexStream[i] = context->input[i].resource;
data->input[i] = context->input[i].buffer;
@@ -990,7 +990,7 @@
}
}
- for(int i = 0; i < VERTEX_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
if(draw.vertexStream[i])
{
diff --git a/src/Renderer/Renderer.hpp b/src/Renderer/Renderer.hpp
index 4b3abbe..cf3cbc1 100644
--- a/src/Renderer/Renderer.hpp
+++ b/src/Renderer/Renderer.hpp
@@ -117,8 +117,8 @@
{
const Constants *constants;
- const void *input[VERTEX_ATTRIBUTES];
- unsigned int stride[VERTEX_ATTRIBUTES];
+ const void *input[MAX_VERTEX_INPUTS];
+ unsigned int stride[MAX_VERTEX_INPUTS];
Texture mipmap[TOTAL_IMAGE_UNITS];
const void *indices;
@@ -224,7 +224,7 @@
int (*setupPrimitives)(Renderer *renderer, int batch, int count);
SetupProcessor::State setupState;
- Resource *vertexStream[VERTEX_ATTRIBUTES];
+ Resource *vertexStream[MAX_VERTEX_INPUTS];
Resource *indexBuffer;
Surface *renderTarget[RENDERTARGETS];
Surface *depthBuffer;
diff --git a/src/Renderer/VertexProcessor.cpp b/src/Renderer/VertexProcessor.cpp
index 291e532..90c954f 100644
--- a/src/Renderer/VertexProcessor.cpp
+++ b/src/Renderer/VertexProcessor.cpp
@@ -135,7 +135,7 @@
void VertexProcessor::resetInputStreams(bool preTransformed)
{
- for(int i = 0; i < VERTEX_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
context->input[i].defaults();
}
@@ -912,7 +912,7 @@
state.transformFeedbackQueryEnabled = context->transformFeedbackQueryEnabled;
state.transformFeedbackEnabled = context->transformFeedbackEnabled;
- for(int i = 0; i < VERTEX_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
state.input[i].type = context->input[i].type;
state.input[i].count = context->input[i].count;
diff --git a/src/Renderer/VertexProcessor.hpp b/src/Renderer/VertexProcessor.hpp
index bcbf4fd..9629c47 100644
--- a/src/Renderer/VertexProcessor.hpp
+++ b/src/Renderer/VertexProcessor.hpp
@@ -133,7 +133,7 @@
};
};
- Input input[VERTEX_ATTRIBUTES];
+ Input input[MAX_VERTEX_INPUTS];
Output output[MAX_VERTEX_OUTPUTS];
};
diff --git a/src/Shader/VertexRoutine.cpp b/src/Shader/VertexRoutine.cpp
index 1affb45..dce0dc2 100644
--- a/src/Shader/VertexRoutine.cpp
+++ b/src/Shader/VertexRoutine.cpp
@@ -83,7 +83,7 @@
void VertexRoutine::readInput(UInt &index)
{
- for(int i = 0; i < VERTEX_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
Pointer<Byte> input = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData,input) + sizeof(void*) * i);
UInt stride = *Pointer<UInt>(data + OFFSET(DrawData,stride) + sizeof(unsigned int) * i);
diff --git a/src/Shader/VertexRoutine.hpp b/src/Shader/VertexRoutine.hpp
index d97d8ed..7f29ff5 100644
--- a/src/Shader/VertexRoutine.hpp
+++ b/src/Shader/VertexRoutine.hpp
@@ -48,7 +48,7 @@
Int clipFlags;
- RegisterArray<16> v; // Varying registers
+ RegisterArray<MAX_VERTEX_INPUTS> v; // Input registers
RegisterArray<MAX_VERTEX_OUTPUTS> o; // Output registers
const VertexProcessor::State &state;
diff --git a/src/Shader/VertexShader.cpp b/src/Shader/VertexShader.cpp
index c488630..06dd1b2 100644
--- a/src/Shader/VertexShader.cpp
+++ b/src/Shader/VertexShader.cpp
@@ -28,7 +28,7 @@
pointSizeRegister = Unused;
instanceIdDeclared = false;
- for(int i = 0; i < MAX_INPUT_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
input[i] = Semantic(-1, -1);
}
@@ -60,7 +60,7 @@
pointSizeRegister = Unused;
instanceIdDeclared = false;
- for(int i = 0; i < MAX_INPUT_ATTRIBUTES; i++)
+ for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
input[i] = Semantic(-1, -1);
}
diff --git a/src/Shader/VertexShader.hpp b/src/Shader/VertexShader.hpp
index 2a76cd2..0fdd09c 100644
--- a/src/Shader/VertexShader.hpp
+++ b/src/Shader/VertexShader.hpp
@@ -38,9 +38,7 @@
bool instanceIdDeclared;
- enum {MAX_INPUT_ATTRIBUTES = 16};
- Semantic input[MAX_INPUT_ATTRIBUTES]; // FIXME: Private
-
+ Semantic input[MAX_VERTEX_INPUTS]; // FIXME: Private
Semantic output[MAX_VERTEX_OUTPUTS][4]; // FIXME: Private
private: