OSDN Git Service

Make Blitter part of Renderer.
[android-x86/external-swiftshader.git] / src / Renderer / Renderer.hpp
index 3756a47..c59dd31 100644 (file)
@@ -1,13 +1,16 @@
-// SwiftShader Software Renderer
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
 //
-// Copyright(c) 2005-2012 TransGaming Inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
 //
-// All rights reserved. No part of this software may be copied, distributed, transmitted,
-// transcribed, stored in a retrieval system, translated into any human or computer
-// language by any means, or disclosed to third parties without the explicit written
-// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
-// or implied, including but not limited to any patent rights, are granted to you.
+//    http://www.apache.org/licenses/LICENSE-2.0
 //
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
 
 #ifndef sw_Renderer_hpp
 #define sw_Renderer_hpp
@@ -32,6 +35,7 @@ namespace sw
        struct Task;
        class Resource;
        class Renderer;
+       struct Constants;
 
        extern int batchSize;
        extern int threadCount;
@@ -53,13 +57,42 @@ namespace sw
        extern TranscendentalPrecision rsqPrecision;
        extern bool perspectiveCorrection;
 
+       struct Conventions
+       {
+               bool halfIntegerCoordinates;
+               bool symmetricNormalizedDepth;
+               bool booleanFaceRegister;
+               bool fullPixelPositionRegister;
+               bool leadingVertexFirst;
+               bool secondaryColor;
+       };
+
+       static const Conventions OpenGL =
+       {
+               true,    // halfIntegerCoordinates
+               true,    // symmetricNormalizedDepth
+               true,    // booleanFaceRegister
+               true,    // fullPixelPositionRegister
+               false,   // leadingVertexFirst
+               false    // secondaryColor
+       };
+
+       static const Conventions Direct3D =
+       {
+               false,   // halfIntegerCoordinates
+               false,   // symmetricNormalizedDepth
+               false,   // booleanFaceRegister
+               false,   // fullPixelPositionRegister
+               true,    // leadingVertexFirst
+               true,    // secondardyColor
+       };
+
        struct Query
        {
-               Query()
+               enum Type { FRAGMENTS_PASSED, TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN };
+
+               Query(Type type) : building(false), reference(0), data(0), type(type)
                {
-                       building = false;
-                       reference = 0;
-                       data = 0;
                }
 
                void begin()
@@ -76,20 +109,28 @@ namespace sw
                bool building;
                volatile int reference;
                volatile unsigned int data;
+
+               const Type type;
        };
 
        struct DrawData
        {
-               const void *constants;
+               const Constants *constants;
 
-               const void *input[16];
-               unsigned int stride[16];
-               Texture mipmap[16 + 4];
+               const void *input[MAX_VERTEX_INPUTS];
+               unsigned int stride[MAX_VERTEX_INPUTS];
+               Texture mipmap[TOTAL_IMAGE_UNITS];
                const void *indices;
 
                struct VS
                {
-                       float4 c[256 + 1];   // One extra for indices out of range, c[256] = {0, 0, 0, 0}
+                       float4 c[VERTEX_UNIFORM_VECTORS + 1];   // One extra for indices out of range, c[VERTEX_UNIFORM_VECTORS] = {0, 0, 0, 0}
+                       byte* u[MAX_UNIFORM_BUFFER_BINDINGS];
+                       byte* t[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS];
+                       unsigned int reg[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Offset used when reading from registers, in components
+                       unsigned int row[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Number of rows to read
+                       unsigned int col[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Number of columns to read
+                       unsigned int str[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Number of components between each varying in output buffer
                        int4 i[16];
                        bool b[16];
                };
@@ -97,7 +138,8 @@ namespace sw
                struct PS
                {
                        word4 cW[8][4];
-                       float4 c[224];
+                       float4 c[FRAGMENT_UNIFORM_VECTORS];
+                       byte* u[MAX_UNIFORM_BUFFER_BINDINGS];
                        int4 i[16];
                        bool b[16];
                };
@@ -110,7 +152,10 @@ namespace sw
 
                PS ps;
 
+               int instanceID;
+
                VertexProcessor::PointSprite point;
+               float lineWidth;
 
                PixelProcessor::Stencil stencil[2];   // clockwise, counterclockwise
                PixelProcessor::Stencil stencilCCW;
@@ -138,9 +183,9 @@ namespace sw
                float depthNear;
                Plane clipPlane[6];
 
-               unsigned int *colorBuffer[4];
-               int colorPitchB[4];
-               int colorSliceB[4];
+               unsigned int *colorBuffer[RENDERTARGETS];
+               int colorPitchB[RENDERTARGETS];
+               int colorSliceB[RENDERTARGETS];
                float *depthBuffer;
                int depthPitchB;
                int depthSliceB;
@@ -165,7 +210,7 @@ namespace sw
 
                ~DrawCall();
 
-               Context::DrawType drawType;
+               DrawType drawType;
                int batchSize;
 
                Routine *vertexRoutine;
@@ -176,14 +221,18 @@ namespace sw
                SetupProcessor::RoutinePointer setupPointer;
                PixelProcessor::RoutinePointer pixelPointer;
 
-               int (*setupPrimitives)(Renderer *renderer, int batch, int count);
+               int (Renderer::*setupPrimitives)(int batch, int count);
                SetupProcessor::State setupState;
 
-               Resource *vertexStream[16];
+               Resource *vertexStream[MAX_VERTEX_INPUTS];
                Resource *indexBuffer;
-               Surface *renderTarget[4];
-               Surface *depthStencil;
-               Resource *texture[16 + 4];
+               Surface *renderTarget[RENDERTARGETS];
+               Surface *depthBuffer;
+               Surface *stencilBuffer;
+               Resource *texture[TOTAL_IMAGE_UNITS];
+               Resource* pUniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
+               Resource* vUniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
+               Resource* transformFeedbackBuffers[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS];
 
                int vsDirtyConstF;
                int vsDirtyConstI;
@@ -265,64 +314,81 @@ namespace sw
                };
 
        public:
-               Renderer(Context *context, bool halfIntegerCoordinates, bool symmetricNormalizedDepth, bool booleanFaceRegister, bool fullPixelPositionRegister, bool exactColorRounding);
+               Renderer(Context *context, Conventions conventions, bool exactColorRounding);
 
                virtual ~Renderer();
 
-               virtual void blit(Surface *source, const Rect &sRect, Surface *dest, const Rect &dRect, bool filter);
-               virtual void draw(Context::DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true);
+               void *operator new(size_t size);
+               void operator delete(void * mem);
+
+               void draw(DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true);
 
-               virtual void setIndexBuffer(Resource *indexBuffer);
+               void clear(void* pixel, Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
+               void blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil = false);
+               void blit3D(Surface *source, Surface *dest);
 
-               virtual void setMultiSampleMask(unsigned int mask);
-               virtual void setTransparencyAntialiasing(Context::TransparencyAntialiasing transparencyAntialiasing);
+               void setIndexBuffer(Resource *indexBuffer);
 
-               virtual void setTextureResource(unsigned int sampler, Resource *resource);
-               virtual void setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type);
+               void setMultiSampleMask(unsigned int mask);
+               void setTransparencyAntialiasing(TransparencyAntialiasing transparencyAntialiasing);
 
-               virtual void setTextureFilter(SamplerType type, int sampler, FilterType textureFilter);
-               virtual void setMipmapFilter(SamplerType type, int sampler, MipmapType mipmapFilter);
-               virtual void setGatherEnable(SamplerType type, int sampler, bool enable);
-               virtual void setAddressingModeU(SamplerType type, int sampler, AddressingMode addressingMode);
-               virtual void setAddressingModeV(SamplerType type, int sampler, AddressingMode addressingMode);
-               virtual void setAddressingModeW(SamplerType type, int sampler, AddressingMode addressingMode);
-               virtual void setReadSRGB(SamplerType type, int sampler, bool sRGB);
-               virtual void setMipmapLOD(SamplerType type, int sampler, float bias);
-               virtual void setBorderColor(SamplerType type, int sampler, const Color<float> &borderColor);
-               virtual void setMaxAnisotropy(SamplerType type, int sampler, unsigned int maxAnisotropy);
-               
-               virtual void setPointSpriteEnable(bool pointSpriteEnable);
-               virtual void setPointScaleEnable(bool pointScaleEnable);
+               void setTextureResource(unsigned int sampler, Resource *resource);
+               void setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type);
 
-               virtual void setDepthBias(float bias);
-               virtual void setSlopeDepthBias(float slopeBias);
+               void setTextureFilter(SamplerType type, int sampler, FilterType textureFilter);
+               void setMipmapFilter(SamplerType type, int sampler, MipmapType mipmapFilter);
+               void setGatherEnable(SamplerType type, int sampler, bool enable);
+               void setAddressingModeU(SamplerType type, int sampler, AddressingMode addressingMode);
+               void setAddressingModeV(SamplerType type, int sampler, AddressingMode addressingMode);
+               void setAddressingModeW(SamplerType type, int sampler, AddressingMode addressingMode);
+               void setReadSRGB(SamplerType type, int sampler, bool sRGB);
+               void setMipmapLOD(SamplerType type, int sampler, float bias);
+               void setBorderColor(SamplerType type, int sampler, const Color<float> &borderColor);
+               void setMaxAnisotropy(SamplerType type, int sampler, float maxAnisotropy);
+               void setSwizzleR(SamplerType type, int sampler, SwizzleType swizzleR);
+               void setSwizzleG(SamplerType type, int sampler, SwizzleType swizzleG);
+               void setSwizzleB(SamplerType type, int sampler, SwizzleType swizzleB);
+               void setSwizzleA(SamplerType type, int sampler, SwizzleType swizzleA);
+               void setBaseLevel(SamplerType type, int sampler, int baseLevel);
+               void setMaxLevel(SamplerType type, int sampler, int maxLevel);
+               void setMinLod(SamplerType type, int sampler, float minLod);
+               void setMaxLod(SamplerType type, int sampler, float maxLod);
+
+               void setPointSpriteEnable(bool pointSpriteEnable);
+               void setPointScaleEnable(bool pointScaleEnable);
+               void setLineWidth(float width);
+
+               void setDepthBias(float bias);
+               void setSlopeDepthBias(float slopeBias);
+
+               void setRasterizerDiscard(bool rasterizerDiscard);
 
                // Programmable pipelines
-               virtual void setPixelShader(const PixelShader *shader);
-               virtual void setVertexShader(const VertexShader *shader);
+               void setPixelShader(const PixelShader *shader);
+               void setVertexShader(const VertexShader *shader);
 
-               virtual void setPixelShaderConstantF(int index, const float value[4], int count = 1);
-               virtual void setPixelShaderConstantI(int index, const int value[4], int count = 1);
-               virtual void setPixelShaderConstantB(int index, const int *boolean, int count = 1);
+               void setPixelShaderConstantF(int index, const float value[4], int count = 1);
+               void setPixelShaderConstantI(int index, const int value[4], int count = 1);
+               void setPixelShaderConstantB(int index, const int *boolean, int count = 1);
 
-               virtual void setVertexShaderConstantF(int index, const float value[4], int count = 1);
-               virtual void setVertexShaderConstantI(int index, const int value[4], int count = 1);
-               virtual void setVertexShaderConstantB(int index, const int *boolean, int count = 1);
+               void setVertexShaderConstantF(int index, const float value[4], int count = 1);
+               void setVertexShaderConstantI(int index, const int value[4], int count = 1);
+               void setVertexShaderConstantB(int index, const int *boolean, int count = 1);
 
                // Viewport & Clipper
-               virtual void setViewport(const Viewport &viewport);
-               virtual void setScissor(const Rect &scissor);
-               virtual void setClipFlags(int flags);
-               virtual void setClipPlane(unsigned int index, const float plane[4]);
+               void setViewport(const Viewport &viewport);
+               void setScissor(const Rect &scissor);
+               void setClipFlags(int flags);
+               void setClipPlane(unsigned int index, const float plane[4]);
 
                // Partial transform
-               virtual void setModelMatrix(const Matrix &M, int i = 0);
-               virtual void setViewMatrix(const Matrix &V);
-               virtual void setBaseMatrix(const Matrix &B);
-               virtual void setProjectionMatrix(const Matrix &P);
+               void setModelMatrix(const Matrix &M, int i = 0);
+               void setViewMatrix(const Matrix &V);
+               void setBaseMatrix(const Matrix &B);
+               void setProjectionMatrix(const Matrix &P);
 
-               virtual void addQuery(Query *query);
-               virtual void removeQuery(Query *query);
+               void addQuery(Query *query);
+               void removeQuery(Query *query);
 
                void synchronize();
 
@@ -346,19 +412,18 @@ namespace sw
 
                void processPrimitiveVertices(int unit, unsigned int start, unsigned int count, unsigned int loop, int thread);
 
-               static int setupSolidTriangles(Renderer *renderer, int batch, int count);
-               static int setupWireframeTriangle(Renderer *renderer, int batch, int count);
-               static int setupVertexTriangle(Renderer *renderer, int batch, int count);
-               static int setupLines(Renderer *renderer, int batch, int count);
-               static int setupPoints(Renderer *renderer, int batch, int count);
+               int setupSolidTriangles(int batch, int count);
+               int setupWireframeTriangle(int batch, int count);
+               int setupVertexTriangle(int batch, int count);
+               int setupLines(int batch, int count);
+               int setupPoints(int batch, int count);
 
-               static bool setupLine(Renderer *renderer, Primitive &primitive, Triangle &triangle, const DrawCall &draw);
-               static bool setupPoint(Renderer *renderer, Primitive &primitive, Triangle &triangle, const DrawCall &draw);
+               bool setupLine(Primitive &primitive, Triangle &triangle, const DrawCall &draw);
+               bool setupPoint(Primitive &primitive, Triangle &triangle, const DrawCall &draw);
 
                bool isReadWriteTexture(int sampler);
                void updateClipper();
                void updateConfiguration(bool initialUpdate = false);
-               static unsigned int computeClipFlags(const float4 &v, const DrawData &data);
                void initializeThreads();
                void terminateThreads();
 
@@ -367,6 +432,7 @@ namespace sw
 
                Context *context;
                Clipper *clipper;
+               Blitter *blitter;
                Viewport viewport;
                Rect scissor;
                int clipFlags;
@@ -375,8 +441,8 @@ namespace sw
                Primitive *primitiveBatch[16];
 
                // User-defined clipping planes
-               Plane userPlane[6];
-               Plane clipPlane[6];   // Tranformed to clip space
+               Plane userPlane[MAX_CLIP_PLANES];
+               Plane clipPlane[MAX_CLIP_PLANES];   // Tranformed to clip space
                bool updateClipPlanes;
 
                volatile bool exitThreads;
@@ -401,7 +467,7 @@ namespace sw
                unsigned int qHead;
                unsigned int qSize;
 
-               BackoffLock mutex;
+               MutexLock schedulerMutex;
 
                #if PERF_HUD
                        int64_t vertexTime[16];
@@ -419,13 +485,10 @@ namespace sw
                VertexProcessor::State vertexState;
                SetupProcessor::State setupState;
                PixelProcessor::State pixelState;
-               int (*setupPrimitives)(Renderer *renderer, int batch, int count);
 
                Routine *vertexRoutine;
                Routine *setupRoutine;
                Routine *pixelRoutine;
-
-               Blitter blitter;
        };
 }