Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef sw_Renderer_hpp |
| 16 | #define sw_Renderer_hpp |
| 17 | |
| 18 | #include "VertexProcessor.hpp" |
| 19 | #include "PixelProcessor.hpp" |
| 20 | #include "SetupProcessor.hpp" |
| 21 | #include "Plane.hpp" |
| 22 | #include "Blitter.hpp" |
| 23 | #include "Common/MutexLock.hpp" |
| 24 | #include "Common/Thread.hpp" |
| 25 | #include "Main/Config.hpp" |
| 26 | |
| 27 | #include <list> |
| 28 | |
| 29 | namespace sw |
| 30 | { |
| 31 | class Clipper; |
Peter Collingbourne | 9dfb70f | 2018-05-30 12:53:07 -0700 | [diff] [blame] | 32 | struct DrawCall; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 33 | class PixelShader; |
| 34 | class VertexShader; |
| 35 | class SwiftConfig; |
| 36 | struct Task; |
| 37 | class Resource; |
Greg Hartman | 069f950 | 2015-07-07 10:00:48 -0700 | [diff] [blame] | 38 | struct Constants; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 39 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 40 | enum TranscendentalPrecision |
| 41 | { |
| 42 | APPROXIMATE, |
| 43 | PARTIAL, // 2^-10 |
| 44 | ACCURATE, |
| 45 | WHQL, // 2^-21 |
| 46 | IEEE // 2^-23 |
| 47 | }; |
| 48 | |
| 49 | extern TranscendentalPrecision logPrecision; |
| 50 | extern TranscendentalPrecision expPrecision; |
| 51 | extern TranscendentalPrecision rcpPrecision; |
| 52 | extern TranscendentalPrecision rsqPrecision; |
| 53 | extern bool perspectiveCorrection; |
| 54 | |
Nicolas Capens | 3aa46cb | 2015-06-03 16:33:02 -0400 | [diff] [blame] | 55 | struct Conventions |
| 56 | { |
| 57 | bool halfIntegerCoordinates; |
| 58 | bool symmetricNormalizedDepth; |
| 59 | bool booleanFaceRegister; |
| 60 | bool fullPixelPositionRegister; |
| 61 | bool leadingVertexFirst; |
Nicolas Capens | 44ffb65 | 2015-08-04 16:11:24 -0400 | [diff] [blame] | 62 | bool secondaryColor; |
Alexis Hetu | 56f256e | 2017-07-21 11:41:13 -0400 | [diff] [blame] | 63 | bool colorsDefaultToZero; |
Nicolas Capens | 3aa46cb | 2015-06-03 16:33:02 -0400 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static const Conventions OpenGL = |
| 67 | { |
Nicolas Capens | 44ffb65 | 2015-08-04 16:11:24 -0400 | [diff] [blame] | 68 | true, // halfIntegerCoordinates |
| 69 | true, // symmetricNormalizedDepth |
| 70 | true, // booleanFaceRegister |
| 71 | true, // fullPixelPositionRegister |
| 72 | false, // leadingVertexFirst |
Alexis Hetu | 56f256e | 2017-07-21 11:41:13 -0400 | [diff] [blame] | 73 | false, // secondaryColor |
| 74 | true, // colorsDefaultToZero |
Nicolas Capens | 3aa46cb | 2015-06-03 16:33:02 -0400 | [diff] [blame] | 75 | }; |
| 76 | |
Nicolas Capens | 6683943 | 2015-07-17 11:45:49 -0400 | [diff] [blame] | 77 | static const Conventions Direct3D = |
| 78 | { |
| 79 | false, // halfIntegerCoordinates |
| 80 | false, // symmetricNormalizedDepth |
| 81 | false, // booleanFaceRegister |
| 82 | false, // fullPixelPositionRegister |
Nicolas Capens | 44ffb65 | 2015-08-04 16:11:24 -0400 | [diff] [blame] | 83 | true, // leadingVertexFirst |
| 84 | true, // secondardyColor |
Alexis Hetu | 56f256e | 2017-07-21 11:41:13 -0400 | [diff] [blame] | 85 | false, // colorsDefaultToZero |
Nicolas Capens | 6683943 | 2015-07-17 11:45:49 -0400 | [diff] [blame] | 86 | }; |
| 87 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 88 | struct Query |
| 89 | { |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 90 | enum Type { FRAGMENTS_PASSED, TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN }; |
| 91 | |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 92 | Query(Type type); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 93 | |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 94 | void addRef(); |
| 95 | void release(); |
| 96 | |
| 97 | inline void begin() |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 98 | { |
| 99 | building = true; |
| 100 | data = 0; |
| 101 | } |
| 102 | |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 103 | inline void end() |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 104 | { |
| 105 | building = false; |
| 106 | } |
| 107 | |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 108 | inline bool isReady() const |
| 109 | { |
| 110 | return (reference == 1); |
| 111 | } |
| 112 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 113 | bool building; |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 114 | AtomicInt data; |
Alexis Hetu | 16116cb | 2016-03-02 15:59:51 -0500 | [diff] [blame] | 115 | |
| 116 | const Type type; |
Alexis Hetu | 3fc6893 | 2018-11-14 10:54:53 -0500 | [diff] [blame] | 117 | private: |
| 118 | ~Query() {} // Only delete a query within the release() function |
| 119 | |
| 120 | AtomicInt reference; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | struct DrawData |
| 124 | { |
Nicolas Capens | 824e7b3 | 2015-07-03 14:33:14 -0400 | [diff] [blame] | 125 | const Constants *constants; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 126 | |
Nicolas Capens | f0aef1a | 2016-05-18 14:44:21 -0400 | [diff] [blame] | 127 | const void *input[MAX_VERTEX_INPUTS]; |
| 128 | unsigned int stride[MAX_VERTEX_INPUTS]; |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 129 | Texture mipmap[TOTAL_IMAGE_UNITS]; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 130 | const void *indices; |
| 131 | |
| 132 | struct VS |
| 133 | { |
Alexis Hetu | 028f41b | 2016-01-13 14:40:47 -0500 | [diff] [blame] | 134 | float4 c[VERTEX_UNIFORM_VECTORS + 1]; // One extra for indices out of range, c[VERTEX_UNIFORM_VECTORS] = {0, 0, 0, 0} |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 135 | byte* u[MAX_UNIFORM_BUFFER_BINDINGS]; |
Alexis Hetu | c6a57cb | 2016-04-07 10:48:31 -0400 | [diff] [blame] | 136 | byte* t[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; |
| 137 | unsigned int reg[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Offset used when reading from registers, in components |
| 138 | unsigned int row[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Number of rows to read |
| 139 | unsigned int col[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Number of columns to read |
| 140 | unsigned int str[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; // Number of components between each varying in output buffer |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 141 | int4 i[16]; |
| 142 | bool b[16]; |
| 143 | }; |
| 144 | |
| 145 | struct PS |
| 146 | { |
| 147 | word4 cW[8][4]; |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 148 | float4 c[FRAGMENT_UNIFORM_VECTORS]; |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 149 | byte* u[MAX_UNIFORM_BUFFER_BINDINGS]; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 150 | int4 i[16]; |
| 151 | bool b[16]; |
| 152 | }; |
| 153 | |
| 154 | union |
| 155 | { |
| 156 | VS vs; |
| 157 | VertexProcessor::FixedFunction ff; |
| 158 | }; |
| 159 | |
| 160 | PS ps; |
| 161 | |
Alexis Hetu | 6743bbf | 2015-04-21 17:06:14 -0400 | [diff] [blame] | 162 | int instanceID; |
| 163 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 164 | VertexProcessor::PointSprite point; |
Nicolas Capens | 235781d | 2015-01-27 01:46:53 -0500 | [diff] [blame] | 165 | float lineWidth; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 166 | |
| 167 | PixelProcessor::Stencil stencil[2]; // clockwise, counterclockwise |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 168 | PixelProcessor::Fog fog; |
| 169 | PixelProcessor::Factor factor; |
| 170 | unsigned int occlusion[16]; // Number of pixels passing depth test |
| 171 | |
| 172 | #if PERF_PROFILE |
| 173 | int64_t cycles[PERF_TIMERS][16]; |
| 174 | #endif |
| 175 | |
| 176 | TextureStage::Uniforms textureStage[8]; |
| 177 | |
| 178 | float4 Wx16; |
| 179 | float4 Hx16; |
| 180 | float4 X0x16; |
| 181 | float4 Y0x16; |
| 182 | float4 XXXX; |
| 183 | float4 YYYY; |
| 184 | float4 halfPixelX; |
| 185 | float4 halfPixelY; |
| 186 | float viewportHeight; |
| 187 | float slopeDepthBias; |
| 188 | float depthRange; |
| 189 | float depthNear; |
| 190 | Plane clipPlane[6]; |
| 191 | |
Alexis Hetu | 1edcd8b | 2015-11-05 11:12:41 -0500 | [diff] [blame] | 192 | unsigned int *colorBuffer[RENDERTARGETS]; |
| 193 | int colorPitchB[RENDERTARGETS]; |
| 194 | int colorSliceB[RENDERTARGETS]; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 195 | float *depthBuffer; |
| 196 | int depthPitchB; |
| 197 | int depthSliceB; |
| 198 | unsigned char *stencilBuffer; |
| 199 | int stencilPitchB; |
| 200 | int stencilSliceB; |
| 201 | |
| 202 | int scissorX0; |
| 203 | int scissorX1; |
| 204 | int scissorY0; |
| 205 | int scissorY1; |
| 206 | |
| 207 | float4 a2c0; |
| 208 | float4 a2c1; |
| 209 | float4 a2c2; |
| 210 | float4 a2c3; |
| 211 | }; |
| 212 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 213 | struct Viewport |
| 214 | { |
| 215 | float x0; |
| 216 | float y0; |
| 217 | float width; |
| 218 | float height; |
| 219 | float minZ; |
| 220 | float maxZ; |
| 221 | }; |
| 222 | |
| 223 | class Renderer : public VertexProcessor, public PixelProcessor, public SetupProcessor |
| 224 | { |
| 225 | struct Task |
| 226 | { |
| 227 | enum Type |
| 228 | { |
| 229 | PRIMITIVES, |
| 230 | PIXELS, |
| 231 | |
| 232 | RESUME, |
| 233 | SUSPEND |
| 234 | }; |
| 235 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 236 | AtomicInt type; |
| 237 | AtomicInt primitiveUnit; |
| 238 | AtomicInt pixelCluster; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | struct PrimitiveProgress |
| 242 | { |
| 243 | void init() |
| 244 | { |
| 245 | drawCall = 0; |
| 246 | firstPrimitive = 0; |
| 247 | primitiveCount = 0; |
| 248 | visible = 0; |
| 249 | references = 0; |
| 250 | } |
| 251 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 252 | AtomicInt drawCall; |
| 253 | AtomicInt firstPrimitive; |
| 254 | AtomicInt primitiveCount; |
| 255 | AtomicInt visible; |
| 256 | AtomicInt references; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | struct PixelProgress |
| 260 | { |
| 261 | void init() |
| 262 | { |
| 263 | drawCall = 0; |
| 264 | processedPrimitives = 0; |
| 265 | executing = false; |
| 266 | } |
| 267 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 268 | AtomicInt drawCall; |
| 269 | AtomicInt processedPrimitives; |
| 270 | AtomicInt executing; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | public: |
Nicolas Capens | 3aa46cb | 2015-06-03 16:33:02 -0400 | [diff] [blame] | 274 | Renderer(Context *context, Conventions conventions, bool exactColorRounding); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 275 | |
| 276 | virtual ~Renderer(); |
| 277 | |
Alexis Hetu | 81519cf | 2016-09-08 13:59:50 -0400 | [diff] [blame] | 278 | void *operator new(size_t size); |
| 279 | void operator delete(void * mem); |
| 280 | |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 281 | void draw(DrawType drawType, unsigned int indexOffset, unsigned int count, bool update = true); |
| 282 | |
Nicolas Capens | 426cb5e | 2017-07-20 14:14:09 -0400 | [diff] [blame] | 283 | void clear(void *value, Format format, Surface *dest, const Rect &rect, unsigned int rgbaMask); |
Nicolas Capens | 1ab837c | 2017-12-16 02:28:02 -0500 | [diff] [blame] | 284 | void blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil = false, bool sRGBconversion = true); |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 285 | void blit3D(Surface *source, Surface *dest); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 286 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 287 | void setIndexBuffer(Resource *indexBuffer); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 288 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 289 | void setMultiSampleMask(unsigned int mask); |
| 290 | void setTransparencyAntialiasing(TransparencyAntialiasing transparencyAntialiasing); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 291 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 292 | void setTextureResource(unsigned int sampler, Resource *resource); |
| 293 | void setTextureLevel(unsigned int sampler, unsigned int face, unsigned int level, Surface *surface, TextureType type); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 294 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 295 | void setTextureFilter(SamplerType type, int sampler, FilterType textureFilter); |
| 296 | void setMipmapFilter(SamplerType type, int sampler, MipmapType mipmapFilter); |
| 297 | void setGatherEnable(SamplerType type, int sampler, bool enable); |
| 298 | void setAddressingModeU(SamplerType type, int sampler, AddressingMode addressingMode); |
| 299 | void setAddressingModeV(SamplerType type, int sampler, AddressingMode addressingMode); |
| 300 | void setAddressingModeW(SamplerType type, int sampler, AddressingMode addressingMode); |
| 301 | void setReadSRGB(SamplerType type, int sampler, bool sRGB); |
| 302 | void setMipmapLOD(SamplerType type, int sampler, float bias); |
| 303 | void setBorderColor(SamplerType type, int sampler, const Color<float> &borderColor); |
| 304 | void setMaxAnisotropy(SamplerType type, int sampler, float maxAnisotropy); |
Alexis Hetu | 010a464 | 2017-07-18 14:33:04 -0400 | [diff] [blame] | 305 | void setHighPrecisionFiltering(SamplerType type, int sampler, bool highPrecisionFiltering); |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 306 | void setSwizzleR(SamplerType type, int sampler, SwizzleType swizzleR); |
| 307 | void setSwizzleG(SamplerType type, int sampler, SwizzleType swizzleG); |
| 308 | void setSwizzleB(SamplerType type, int sampler, SwizzleType swizzleB); |
| 309 | void setSwizzleA(SamplerType type, int sampler, SwizzleType swizzleA); |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 310 | void setCompareFunc(SamplerType type, int sampler, CompareFunc compare); |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 311 | void setBaseLevel(SamplerType type, int sampler, int baseLevel); |
| 312 | void setMaxLevel(SamplerType type, int sampler, int maxLevel); |
| 313 | void setMinLod(SamplerType type, int sampler, float minLod); |
| 314 | void setMaxLod(SamplerType type, int sampler, float maxLod); |
Alexis Hetu | 88482c3 | 2018-06-05 17:05:17 -0400 | [diff] [blame] | 315 | void setSyncRequired(SamplerType type, int sampler, bool syncRequired); |
Nicolas Capens | 53bf0a1 | 2016-05-26 11:19:02 -0400 | [diff] [blame] | 316 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 317 | void setPointSpriteEnable(bool pointSpriteEnable); |
| 318 | void setPointScaleEnable(bool pointScaleEnable); |
| 319 | void setLineWidth(float width); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 320 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 321 | void setDepthBias(float bias); |
| 322 | void setSlopeDepthBias(float slopeBias); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 323 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 324 | void setRasterizerDiscard(bool rasterizerDiscard); |
Alexis Hetu | b0f247f | 2016-02-22 11:42:39 -0500 | [diff] [blame] | 325 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 326 | // Programmable pipelines |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 327 | void setPixelShader(const PixelShader *shader); |
| 328 | void setVertexShader(const VertexShader *shader); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 329 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 330 | void setPixelShaderConstantF(unsigned int index, const float value[4], unsigned int count = 1); |
| 331 | void setPixelShaderConstantI(unsigned int index, const int value[4], unsigned int count = 1); |
| 332 | void setPixelShaderConstantB(unsigned int index, const int *boolean, unsigned int count = 1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 333 | |
Alexis Hetu | b59a58e | 2016-06-02 11:50:47 -0400 | [diff] [blame] | 334 | void setVertexShaderConstantF(unsigned int index, const float value[4], unsigned int count = 1); |
| 335 | void setVertexShaderConstantI(unsigned int index, const int value[4], unsigned int count = 1); |
| 336 | void setVertexShaderConstantB(unsigned int index, const int *boolean, unsigned int count = 1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 337 | |
| 338 | // Viewport & Clipper |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 339 | void setViewport(const Viewport &viewport); |
| 340 | void setScissor(const Rect &scissor); |
| 341 | void setClipFlags(int flags); |
| 342 | void setClipPlane(unsigned int index, const float plane[4]); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 343 | |
| 344 | // Partial transform |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 345 | void setModelMatrix(const Matrix &M, int i = 0); |
| 346 | void setViewMatrix(const Matrix &V); |
| 347 | void setBaseMatrix(const Matrix &B); |
| 348 | void setProjectionMatrix(const Matrix &P); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 349 | |
Alexis Hetu | c634fb6 | 2016-06-02 10:53:13 -0400 | [diff] [blame] | 350 | void addQuery(Query *query); |
| 351 | void removeQuery(Query *query); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 352 | |
| 353 | void synchronize(); |
| 354 | |
| 355 | #if PERF_HUD |
| 356 | // Performance timers |
| 357 | int getThreadCount(); |
| 358 | int64_t getVertexTime(int thread); |
| 359 | int64_t getSetupTime(int thread); |
| 360 | int64_t getPixelTime(int thread); |
| 361 | void resetTimers(); |
| 362 | #endif |
| 363 | |
Alexis Hetu | aa8239a | 2017-09-22 17:02:24 -0400 | [diff] [blame] | 364 | static int getClusterCount() { return clusterCount; } |
| 365 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 366 | private: |
| 367 | static void threadFunction(void *parameters); |
| 368 | void threadLoop(int threadIndex); |
| 369 | void taskLoop(int threadIndex); |
| 370 | void findAvailableTasks(); |
| 371 | void scheduleTask(int threadIndex); |
| 372 | void executeTask(int threadIndex); |
| 373 | void finishRendering(Task &pixelTask); |
| 374 | |
| 375 | void processPrimitiveVertices(int unit, unsigned int start, unsigned int count, unsigned int loop, int thread); |
| 376 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 377 | int setupSolidTriangles(int batch, int count); |
| 378 | int setupWireframeTriangle(int batch, int count); |
| 379 | int setupVertexTriangle(int batch, int count); |
| 380 | int setupLines(int batch, int count); |
| 381 | int setupPoints(int batch, int count); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 382 | |
Nicolas Capens | 734392e | 2016-05-26 11:07:40 -0400 | [diff] [blame] | 383 | bool setupLine(Primitive &primitive, Triangle &triangle, const DrawCall &draw); |
| 384 | bool setupPoint(Primitive &primitive, Triangle &triangle, const DrawCall &draw); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 385 | |
| 386 | bool isReadWriteTexture(int sampler); |
| 387 | void updateClipper(); |
| 388 | void updateConfiguration(bool initialUpdate = false); |
Nicolas Capens | 7381c99 | 2014-05-06 23:48:15 -0400 | [diff] [blame] | 389 | void initializeThreads(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 390 | void terminateThreads(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 391 | |
| 392 | void loadConstants(const VertexShader *vertexShader); |
| 393 | void loadConstants(const PixelShader *pixelShader); |
| 394 | |
| 395 | Context *context; |
| 396 | Clipper *clipper; |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 397 | Blitter *blitter; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 398 | Viewport viewport; |
| 399 | Rect scissor; |
| 400 | int clipFlags; |
| 401 | |
| 402 | Triangle *triangleBatch[16]; |
| 403 | Primitive *primitiveBatch[16]; |
| 404 | |
| 405 | // User-defined clipping planes |
Nicolas Capens | d226414 | 2015-07-02 17:06:53 -0400 | [diff] [blame] | 406 | Plane userPlane[MAX_CLIP_PLANES]; |
| 407 | Plane clipPlane[MAX_CLIP_PLANES]; // Tranformed to clip space |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 408 | bool updateClipPlanes; |
| 409 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 410 | AtomicInt exitThreads; |
| 411 | AtomicInt threadsAwake; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 412 | Thread *worker[16]; |
| 413 | Event *resume[16]; // Events for resuming threads |
| 414 | Event *suspend[16]; // Events for suspending threads |
| 415 | Event *resumeApp; // Event for resuming the application thread |
| 416 | |
| 417 | PrimitiveProgress primitiveProgress[16]; |
| 418 | PixelProgress pixelProgress[16]; |
| 419 | Task task[16]; // Current tasks for threads |
| 420 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 421 | enum { |
| 422 | DRAW_COUNT = 16, // Number of draw calls buffered (must be power of 2) |
| 423 | DRAW_COUNT_BITS = DRAW_COUNT - 1, |
| 424 | }; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 425 | DrawCall *drawCall[DRAW_COUNT]; |
| 426 | DrawCall *drawList[DRAW_COUNT]; |
| 427 | |
Alexis Hetu | 6b164c3 | 2017-09-20 11:24:52 -0400 | [diff] [blame] | 428 | AtomicInt currentDraw; |
| 429 | AtomicInt nextDraw; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 430 | |
Alexis Hetu | bc6ce4f | 2017-09-27 13:15:59 -0400 | [diff] [blame] | 431 | enum { |
| 432 | TASK_COUNT = 32, // Size of the task queue (must be power of 2) |
| 433 | TASK_COUNT_BITS = TASK_COUNT - 1, |
| 434 | }; |
| 435 | Task taskQueue[TASK_COUNT]; |
Alexis Hetu | aa8239a | 2017-09-22 17:02:24 -0400 | [diff] [blame] | 436 | AtomicInt qHead; |
| 437 | AtomicInt qSize; |
| 438 | |
| 439 | static AtomicInt unitCount; |
| 440 | static AtomicInt clusterCount; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 441 | |
Jorge E. Moreira | f8faed6 | 2016-12-02 17:03:54 -0800 | [diff] [blame] | 442 | MutexLock schedulerMutex; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 443 | |
| 444 | #if PERF_HUD |
| 445 | int64_t vertexTime[16]; |
| 446 | int64_t setupTime[16]; |
| 447 | int64_t pixelTime[16]; |
| 448 | #endif |
| 449 | |
| 450 | VertexTask *vertexTask[16]; |
| 451 | |
| 452 | SwiftConfig *swiftConfig; |
| 453 | |
| 454 | std::list<Query*> queries; |
| 455 | Resource *sync; |
| 456 | |
| 457 | VertexProcessor::State vertexState; |
| 458 | SetupProcessor::State setupState; |
| 459 | PixelProcessor::State pixelState; |
Nicolas Capens | 183949c | 2016-06-23 16:23:13 -0400 | [diff] [blame] | 460 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 461 | std::shared_ptr<Routine> vertexRoutine; |
| 462 | std::shared_ptr<Routine> setupRoutine; |
| 463 | std::shared_ptr<Routine> pixelRoutine; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 464 | }; |
Peter Collingbourne | 9dfb70f | 2018-05-30 12:53:07 -0700 | [diff] [blame] | 465 | |
| 466 | struct DrawCall |
| 467 | { |
| 468 | DrawCall(); |
| 469 | |
| 470 | ~DrawCall(); |
| 471 | |
| 472 | AtomicInt drawType; |
| 473 | AtomicInt batchSize; |
| 474 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 475 | std::shared_ptr<Routine> vertexRoutine; |
| 476 | std::shared_ptr<Routine> setupRoutine; |
| 477 | std::shared_ptr<Routine> pixelRoutine; |
Peter Collingbourne | 9dfb70f | 2018-05-30 12:53:07 -0700 | [diff] [blame] | 478 | |
| 479 | VertexProcessor::RoutinePointer vertexPointer; |
| 480 | SetupProcessor::RoutinePointer setupPointer; |
| 481 | PixelProcessor::RoutinePointer pixelPointer; |
| 482 | |
| 483 | int (Renderer::*setupPrimitives)(int batch, int count); |
| 484 | SetupProcessor::State setupState; |
| 485 | |
| 486 | Resource *vertexStream[MAX_VERTEX_INPUTS]; |
| 487 | Resource *indexBuffer; |
| 488 | Surface *renderTarget[RENDERTARGETS]; |
| 489 | Surface *depthBuffer; |
| 490 | Surface *stencilBuffer; |
| 491 | Resource *texture[TOTAL_IMAGE_UNITS]; |
| 492 | Resource* pUniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS]; |
| 493 | Resource* vUniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS]; |
| 494 | Resource* transformFeedbackBuffers[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]; |
| 495 | |
| 496 | unsigned int vsDirtyConstF; |
| 497 | unsigned int vsDirtyConstI; |
| 498 | unsigned int vsDirtyConstB; |
| 499 | |
| 500 | unsigned int psDirtyConstF; |
| 501 | unsigned int psDirtyConstI; |
| 502 | unsigned int psDirtyConstB; |
| 503 | |
| 504 | std::list<Query*> *queries; |
| 505 | |
| 506 | AtomicInt clipFlags; |
| 507 | |
| 508 | AtomicInt primitive; // Current primitive to enter pipeline |
| 509 | AtomicInt count; // Number of primitives to render |
| 510 | AtomicInt references; // Remaining references to this draw call, 0 when done drawing, -1 when resources unlocked and slot is free |
| 511 | |
| 512 | DrawData *data; |
| 513 | }; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | #endif // sw_Renderer_hpp |