OSDN Git Service

Make Blitter part of Renderer.
[android-x86/external-swiftshader.git] / src / Renderer / Renderer.hpp
index c443219..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
@@ -86,11 +89,10 @@ namespace sw
 
        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()
@@ -107,20 +109,28 @@ namespace sw
                bool building;
                volatile int reference;
                volatile unsigned int data;
+
+               const Type type;
        };
 
        struct DrawData
        {
                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;
 
                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];
                };
@@ -129,6 +139,7 @@ namespace sw
                {
                        word4 cW[8][4];
                        float4 c[FRAGMENT_UNIFORM_VECTORS];
+                       byte* u[MAX_UNIFORM_BUFFER_BINDINGS];
                        int4 i[16];
                        bool b[16];
                };
@@ -210,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[VERTEX_ATTRIBUTES];
+               Resource *vertexStream[MAX_VERTEX_INPUTS];
                Resource *indexBuffer;
                Surface *renderTarget[RENDERTARGETS];
-               Surface *depthStencil;
+               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;
@@ -303,67 +318,77 @@ namespace sw
 
                virtual ~Renderer();
 
-               virtual void clear(void* pixel, Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
-               virtual void blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter);
-               virtual void blit3D(Surface *source, Surface *dest);
-               virtual void draw(DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true);
-
-               virtual void setIndexBuffer(Resource *indexBuffer);
-
-               virtual void setMultiSampleMask(unsigned int mask);
-               virtual void setTransparencyAntialiasing(TransparencyAntialiasing transparencyAntialiasing);
-
-               virtual void setTextureResource(unsigned int sampler, Resource *resource);
-               virtual void setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type);
-
-               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, float maxAnisotropy);
-               virtual void setSwizzleR(SamplerType type, int sampler, SwizzleType swizzleR);
-               virtual void setSwizzleG(SamplerType type, int sampler, SwizzleType swizzleG);
-               virtual void setSwizzleB(SamplerType type, int sampler, SwizzleType swizzleB);
-               virtual void setSwizzleA(SamplerType type, int sampler, SwizzleType swizzleA);
-               
-               virtual void setPointSpriteEnable(bool pointSpriteEnable);
-               virtual void setPointScaleEnable(bool pointScaleEnable);
-               virtual void setLineWidth(float width);
-
-               virtual void setDepthBias(float bias);
-               virtual void setSlopeDepthBias(float slopeBias);
+               void *operator new(size_t size);
+               void operator delete(void * mem);
+
+               void draw(DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true);
+
+               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);
+
+               void setIndexBuffer(Resource *indexBuffer);
+
+               void setMultiSampleMask(unsigned int mask);
+               void setTransparencyAntialiasing(TransparencyAntialiasing transparencyAntialiasing);
+
+               void setTextureResource(unsigned int sampler, Resource *resource);
+               void setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type);
+
+               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();
 
@@ -387,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();
 
@@ -408,6 +432,7 @@ namespace sw
 
                Context *context;
                Clipper *clipper;
+               Blitter *blitter;
                Viewport viewport;
                Rect scissor;
                int clipFlags;
@@ -442,7 +467,7 @@ namespace sw
                unsigned int qHead;
                unsigned int qSize;
 
-               BackoffLock schedulerMutex;
+               MutexLock schedulerMutex;
 
                #if PERF_HUD
                        int64_t vertexTime[16];
@@ -460,6 +485,10 @@ namespace sw
                VertexProcessor::State vertexState;
                SetupProcessor::State setupState;
                PixelProcessor::State pixelState;
+
+               Routine *vertexRoutine;
+               Routine *setupRoutine;
+               Routine *pixelRoutine;
        };
 }