Commit dc2966a1 by Nicolas Capens Committed by Nicolas Capens

Eliminate legacy functionality.

Vulkan doesn't require any fixed-function vertex and pixel processing. Bug b/117152542 Change-Id: I4c758c70ff97a785c263c38497e7fb435b81b05d Reviewed-on: https://swiftshader-review.googlesource.com/c/22148Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 1d8c8dba
......@@ -16,7 +16,6 @@
#define sw_Context_hpp
#include "Sampler.hpp"
#include "TextureStage.hpp"
#include "Stream.hpp"
#include "Point.hpp"
#include "Vertex.hpp"
......@@ -60,29 +59,17 @@ namespace sw
DRAW_POINTLIST = 0x00,
DRAW_LINELIST = 0x01,
DRAW_LINESTRIP = 0x02,
DRAW_LINELOOP = 0x03,
DRAW_TRIANGLELIST = 0x04,
DRAW_TRIANGLESTRIP = 0x05,
DRAW_TRIANGLEFAN = 0x06,
DRAW_QUADLIST = 0x07,
DRAW_TRIANGLELIST = 0x03,
DRAW_TRIANGLESTRIP = 0x04,
DRAW_TRIANGLEFAN = 0x05,
DRAW_NONINDEXED = 0x00,
DRAW_INDEXED8 = 0x10,
DRAW_INDEXED16 = 0x20,
DRAW_INDEXED32 = 0x30,
DRAW_INDEXEDPOINTLIST8 = DRAW_POINTLIST | DRAW_INDEXED8,
DRAW_INDEXEDLINELIST8 = DRAW_LINELIST | DRAW_INDEXED8,
DRAW_INDEXEDLINESTRIP8 = DRAW_LINESTRIP | DRAW_INDEXED8,
DRAW_INDEXEDLINELOOP8 = DRAW_LINELOOP | DRAW_INDEXED8,
DRAW_INDEXEDTRIANGLELIST8 = DRAW_TRIANGLELIST | DRAW_INDEXED8,
DRAW_INDEXEDTRIANGLESTRIP8 = DRAW_TRIANGLESTRIP | DRAW_INDEXED8,
DRAW_INDEXEDTRIANGLEFAN8 = DRAW_TRIANGLEFAN | DRAW_INDEXED8,
DRAW_INDEXEDPOINTLIST16 = DRAW_POINTLIST | DRAW_INDEXED16,
DRAW_INDEXEDLINELIST16 = DRAW_LINELIST | DRAW_INDEXED16,
DRAW_INDEXEDLINESTRIP16 = DRAW_LINESTRIP | DRAW_INDEXED16,
DRAW_INDEXEDLINELOOP16 = DRAW_LINELOOP | DRAW_INDEXED16,
DRAW_INDEXEDTRIANGLELIST16 = DRAW_TRIANGLELIST | DRAW_INDEXED16,
DRAW_INDEXEDTRIANGLESTRIP16 = DRAW_TRIANGLESTRIP | DRAW_INDEXED16,
DRAW_INDEXEDTRIANGLEFAN16 = DRAW_TRIANGLEFAN | DRAW_INDEXED16,
......@@ -90,7 +77,6 @@ namespace sw
DRAW_INDEXEDPOINTLIST32 = DRAW_POINTLIST | DRAW_INDEXED32,
DRAW_INDEXEDLINELIST32 = DRAW_LINELIST | DRAW_INDEXED32,
DRAW_INDEXEDLINESTRIP32 = DRAW_LINESTRIP | DRAW_INDEXED32,
DRAW_INDEXEDLINELOOP32 = DRAW_LINELOOP | DRAW_INDEXED32,
DRAW_INDEXEDTRIANGLELIST32 = DRAW_TRIANGLELIST | DRAW_INDEXED32,
DRAW_INDEXEDTRIANGLESTRIP32 = DRAW_TRIANGLESTRIP | DRAW_INDEXED32,
DRAW_INDEXEDTRIANGLEFAN32 = DRAW_TRIANGLEFAN | DRAW_INDEXED32,
......@@ -98,23 +84,6 @@ namespace sw
DRAW_LAST = DRAW_INDEXEDTRIANGLEFAN32
};
enum FillMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
FILL_SOLID,
FILL_WIREFRAME,
FILL_VERTEX,
FILL_LAST = FILL_VERTEX
};
enum ShadingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
SHADING_FLAT,
SHADING_GOURAUD,
SHADING_LAST = SHADING_GOURAUD
};
enum DepthCompareMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
DEPTH_ALWAYS,
......@@ -238,37 +207,6 @@ namespace sw
LOGICALOP_LAST = LOGICALOP_OR_INVERTED
};
enum MaterialSource ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
MATERIAL_MATERIAL,
MATERIAL_COLOR1,
MATERIAL_COLOR2,
MATERIAL_LAST = MATERIAL_COLOR2
};
enum FogMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
FOG_NONE,
FOG_LINEAR,
FOG_EXP,
FOG_EXP2,
FOG_LAST = FOG_EXP2
};
enum TexGen ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
TEXGEN_PASSTHRU,
TEXGEN_NORMAL,
TEXGEN_POSITION,
TEXGEN_REFLECTION,
TEXGEN_SPHEREMAP,
TEXGEN_NONE,
TEXGEN_LAST = TEXGEN_NONE
};
enum TransparencyAntialiasing ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
TRANSPARENCY_NONE,
......@@ -287,34 +225,12 @@ namespace sw
void *operator new(size_t bytes);
void operator delete(void *pointer, size_t bytes);
bool isDrawPoint(bool fillModeAware = false) const;
bool isDrawLine(bool fillModeAware = false) const;
bool isDrawTriangle(bool fillModeAware = false) const;
void init();
const float &exp2Bias(); // NOTE: Needs address for JIT
const Point &getLightPosition(int light);
void setGlobalMipmapBias(float bias);
bool isDrawPoint() const;
bool isDrawLine() const;
bool isDrawTriangle() const;
// Set fixed-function vertex pipeline states
void setLightingEnable(bool lightingEnable);
void setSpecularEnable(bool specularEnable);
void setLightEnable(int light, bool lightEnable);
void setLightPosition(int light, Point worldLightPosition);
void setColorVertexEnable(bool colorVertexEnable);
void setAmbientMaterialSource(MaterialSource ambientMaterialSource);
void setDiffuseMaterialSource(MaterialSource diffuseMaterialSource);
void setSpecularMaterialSource(MaterialSource specularMaterialSource);
void setEmissiveMaterialSource(MaterialSource emissiveMaterialSource);
void setPointSpriteEnable(bool pointSpriteEnable);
void setPointScaleEnable(bool pointScaleEnable);
// Set fixed-function pixel pipeline states, return true when modified
bool setDepthBufferEnable(bool depthBufferEnable);
bool setAlphaBlendEnable(bool alphaBlendEnable);
......@@ -333,10 +249,6 @@ namespace sw
bool setColorLogicOpEnabled(bool colorLogicOpEnabled);
bool setLogicalOperation(LogicalOperation logicalOperation);
// Active fixed-function pixel pipeline states
bool fogActive();
bool pointSizeActive();
FogMode pixelFogActive();
bool depthWriteActive();
bool alphaTestActive();
bool depthBufferActive();
......@@ -344,24 +256,6 @@ namespace sw
bool perspectiveActive();
// Active fixed-function vertex pipeline states
bool vertexLightingActive();
bool texCoordActive(int coordinate, int component);
bool texCoordActive(int coordinate);
bool isProjectionComponent(unsigned int coordinate, int component);
bool vertexSpecularInputActive();
bool vertexSpecularActive();
bool vertexNormalActive();
bool vertexLightActive();
bool vertexLightActive(int i);
MaterialSource vertexDiffuseMaterialSourceActive();
MaterialSource vertexSpecularMaterialSourceActive();
MaterialSource vertexAmbientMaterialSourceActive();
MaterialSource vertexEmissiveMaterialSourceActive();
bool pointSpriteActive();
bool pointScaleActive();
bool alphaBlendActive();
BlendFactor sourceBlendFactor();
BlendFactor destBlendFactor();
......@@ -372,38 +266,11 @@ namespace sw
BlendOperation blendOperationAlpha();
LogicalOperation colorLogicOp();
LogicalOperation indexLogicOp();
bool indexedVertexBlendActive();
int vertexBlendMatrixCountActive();
bool localViewerActive();
bool normalizeNormalsActive();
FogMode vertexFogModeActive();
bool rangeFogActive();
TexGen texGenActive(int stage);
int textureTransformCountActive(int stage);
int texCoordIndexActive(int stage);
// Active context states
bool diffuseUsed(); // Used by pixel processor but not provided by vertex processor
bool diffuseUsed(int component); // Used by pixel processor but not provided by vertex processor
bool diffuseActive();
bool diffuseActive(int component);
bool specularUsed();
bool specularUsed(int component);
bool specularActive();
bool specularActive(int component);
bool colorActive(int color, int component);
bool textureActive();
bool textureActive(int coordinate);
bool textureActive(int coordinate, int component);
unsigned short pixelShaderModel() const;
unsigned short vertexShaderModel() const;
int getMultiSampleCount() const;
int getSuperSampleCount() const;
DrawType drawType;
......@@ -428,8 +295,6 @@ namespace sw
// Pixel processor states
AlphaCompareMode alphaCompareMode;
bool alphaTestEnable;
FillMode fillMode;
ShadingMode shadingMode;
CullMode cullMode;
bool frontFacingCCW;
......@@ -438,7 +303,6 @@ namespace sw
float depthBias;
float slopeDepthBias;
TextureStage textureStage[8];
Sampler sampler[TOTAL_IMAGE_UNITS];
Format renderTargetInternalFormat(int index);
......@@ -450,21 +314,6 @@ namespace sw
Stream input[MAX_VERTEX_INPUTS];
Resource *indexBuffer;
bool preTransformed; // FIXME: Private
float fogStart;
float fogEnd;
void computeIllumination();
bool textureWrapActive;
unsigned char textureWrap[TEXTURE_IMAGE_UNITS];
TexGen texGen[8];
bool localViewer;
bool normalizeNormals;
int textureTransformCount[8];
bool textureTransformProject[8];
Surface *renderTarget[RENDERTARGETS];
unsigned int renderTargetLayer[RENDERTARGETS];
Surface *depthBuffer;
......@@ -472,39 +321,13 @@ namespace sw
Surface *stencilBuffer;
unsigned int stencilBufferLayer;
// Fog
bool fogEnable;
FogMode pixelFogMode;
FogMode vertexFogMode;
bool wBasedFog;
bool rangeFogEnable;
// Vertex blending
bool indexedVertexBlendEnable;
int vertexBlendMatrixCount;
// Shaders
const PixelShader *pixelShader;
const VertexShader *vertexShader;
// Global mipmap bias
float bias;
// Instancing
int instanceID;
// Fixed-function vertex pipeline state
bool lightingEnable;
bool specularEnable;
bool lightEnable[8];
Point worldLightPosition[8];
MaterialSource ambientMaterialSource;
MaterialSource diffuseMaterialSource;
MaterialSource specularMaterialSource;
MaterialSource emissiveMaterialSource;
bool colorVertexEnable;
bool occlusionEnabled;
bool transformFeedbackQueryEnabled;
uint64_t transformFeedbackEnabled;
......@@ -525,8 +348,6 @@ namespace sw
BlendFactor destBlendFactorStateAlpha;
BlendOperation blendOperationStateAlpha;
bool pointSpriteEnable;
bool pointScaleEnable;
float lineWidth;
int colorWriteMask[RENDERTARGETS]; // RGBA
......
......@@ -60,11 +60,7 @@ namespace sw
bool stencilWriteMaskedCCW : 1;
bool depthTestActive : 1;
bool fogActive : 1;
FogMode pixelFogMode : BITS(FOG_LAST);
bool specularAdd : 1;
bool occlusionEnabled : 1;
bool wBasedFog : 1;
bool perspective : 1;
bool depthClamp : 1;
......@@ -88,7 +84,6 @@ namespace sw
LogicalOperation logicalOperation : BITS(LOGICALOP_LAST);
Sampler::State sampler[TEXTURE_IMAGE_UNITS];
TextureStage::State textureStage[8];
struct Interpolant
{
......@@ -127,11 +122,6 @@ namespace sw
return (alphaCompareMode != ALPHA_ALWAYS) || (transparencyAntialiasing != TRANSPARENCY_NONE);
}
bool pixelFogActive() const
{
return pixelFogMode != FOG_NONE;
}
unsigned int hash;
};
......@@ -162,20 +152,8 @@ namespace sw
}
};
struct Fog
{
float4 scale;
float4 offset;
word4 color4[3];
float4 colorF[3];
float4 densityE;
float4 density2E;
};
struct Factor
{
word4 textureFactor4[4];
word4 alphaReference4;
word4 blendConstant4W[4];
......@@ -203,21 +181,6 @@ namespace sw
void setStencilBuffer(Surface *stencilBuffer, unsigned int layer = 0);
void setTexCoordIndex(unsigned int stage, int texCoordIndex);
void setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation);
void setFirstArgument(unsigned int stage, TextureStage::SourceArgument firstArgument);
void setSecondArgument(unsigned int stage, TextureStage::SourceArgument secondArgument);
void setThirdArgument(unsigned int stage, TextureStage::SourceArgument thirdArgument);
void setStageOperationAlpha(unsigned int stage, TextureStage::StageOperation stageOperationAlpha);
void setFirstArgumentAlpha(unsigned int stage, TextureStage::SourceArgument firstArgumentAlpha);
void setSecondArgumentAlpha(unsigned int stage, TextureStage::SourceArgument secondArgumentAlpha);
void setThirdArgumentAlpha(unsigned int stage, TextureStage::SourceArgument thirdArgumentAlpha);
void setFirstModifier(unsigned int stage, TextureStage::ArgumentModifier firstModifier);
void setSecondModifier(unsigned int stage, TextureStage::ArgumentModifier secondModifier);
void setThirdModifier(unsigned int stage, TextureStage::ArgumentModifier thirdModifier);
void setFirstModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier firstModifierAlpha);
void setSecondModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier secondModifierAlpha);
void setThirdModifierAlpha(unsigned int stage, TextureStage::ArgumentModifier thirdModifierAlpha);
void setDestinationArgument(unsigned int stage, TextureStage::DestinationArgument destinationArgument);
void setConstantColor(unsigned int stage, const Color<float> &constantColor);
void setBumpmapMatrix(unsigned int stage, int element, float value);
void setLuminanceScale(unsigned int stage, float value);
......@@ -243,7 +206,6 @@ namespace sw
void setMaxLevel(unsigned int sampler, int maxLevel);
void setMinLod(unsigned int sampler, float minLod);
void setMaxLod(unsigned int sampler, float maxLod);
void setSyncRequired(unsigned int sampler, bool isSincRequired);
void setWriteSRGB(bool sRGB);
void setDepthBufferEnable(bool depthBufferEnable);
......@@ -274,12 +236,8 @@ namespace sw
void setStencilZFailOperationCCW(StencilOperation stencilZFailOperation);
void setStencilWriteMaskCCW(int stencilWriteMask);
void setTextureFactor(const Color<float> &textureFactor);
void setBlendConstant(const Color<float> &blendConstant);
void setFillMode(FillMode fillMode);
void setShadingMode(ShadingMode shadingMode);
void setAlphaBlendEnable(bool alphaBlendEnable);
void setSourceBlendFactor(BlendFactor sourceBlendFactor);
void setDestBlendFactor(BlendFactor destBlendFactor);
......@@ -292,14 +250,6 @@ namespace sw
void setAlphaReference(float alphaReference);
void setGlobalMipmapBias(float bias);
void setFogStart(float start);
void setFogEnd(float end);
void setFogColor(Color<float> fogColor);
void setFogDensity(float fogDensity);
void setPixelFogMode(FogMode fogMode);
void setPerspectiveCorrection(bool perspectiveCorrection);
void setOcclusionEnabled(bool enable);
......@@ -310,7 +260,6 @@ namespace sw
void setRoutineCacheSize(int routineCacheSize);
// Shader constants
word4 cW[8][4];
float4 c[FRAGMENT_UNIFORM_VECTORS];
int4 i[16];
bool b[16];
......@@ -318,7 +267,6 @@ namespace sw
// Other semi-constants
Stencil stencil;
Stencil stencilCCW;
Fog fog;
Factor factor;
private:
......
......@@ -135,29 +135,23 @@ namespace sw
struct PS
{
word4 cW[8][4];
float4 c[FRAGMENT_UNIFORM_VECTORS];
byte* u[MAX_UNIFORM_BUFFER_BINDINGS];
int4 i[16];
bool b[16];
};
union
{
VS vs;
VertexProcessor::FixedFunction ff;
};
VS vs;
PS ps;
int instanceID;
VertexProcessor::PointSprite point;
float pointSizeMin;
float pointSizeMax;
float lineWidth;
PixelProcessor::Stencil stencil[2]; // clockwise, counterclockwise
PixelProcessor::Stencil stencilCCW;
PixelProcessor::Fog fog;
PixelProcessor::Factor factor;
unsigned int occlusion[16]; // Number of pixels passing depth test
......@@ -165,14 +159,10 @@ namespace sw
int64_t cycles[PERF_TIMERS][16];
#endif
TextureStage::Uniforms textureStage[8];
float4 Wx16;
float4 Hx16;
float4 X0x16;
float4 Y0x16;
float4 XXXX;
float4 YYYY;
float4 halfPixelX;
float4 halfPixelY;
float viewportHeight;
......@@ -304,10 +294,7 @@ namespace sw
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 setSyncRequired(SamplerType type, int sampler, bool syncRequired);
void setPointSpriteEnable(bool pointSpriteEnable);
void setPointScaleEnable(bool pointScaleEnable);
void setLineWidth(float width);
void setDepthBias(float bias);
......@@ -366,9 +353,7 @@ namespace sw
void processPrimitiveVertices(int unit, unsigned int start, unsigned int count, unsigned int loop, int thread);
int setupSolidTriangles(int batch, int count);
int setupWireframeTriangle(int batch, int count);
int setupVertexTriangle(int batch, int count);
int setupTriangles(int batch, int count);
int setupLines(int batch, int count);
int setupPoints(int batch, int count);
......
......@@ -401,16 +401,6 @@ namespace sw
return textureType == TEXTURE_3D || textureType == TEXTURE_2D_ARRAY;
}
void Sampler::setSyncRequired(bool isSyncRequired)
{
syncRequired = isSyncRequired;
}
bool Sampler::requiresSync() const
{
return syncRequired;
}
const Texture &Sampler::getTextureData()
{
return texture;
......
......@@ -193,7 +193,6 @@ namespace sw
void setMaxLevel(int maxLevel);
void setMinLod(float minLod);
void setMaxLod(float maxLod);
void setSyncRequired(bool isSincRequired);
static void setFilterQuality(FilterType maximumFilterQuality);
static void setMipmapQuality(MipmapType maximumFilterQuality);
......@@ -203,7 +202,6 @@ namespace sw
bool hasUnsignedTexture() const;
bool hasCubeTexture() const;
bool hasVolumeTexture() const;
bool requiresSync() const;
const Texture &getTextureData();
......@@ -228,7 +226,6 @@ namespace sw
bool sRGB;
bool gather;
bool highPrecisionFiltering;
bool syncRequired;
int border;
SwizzleType swizzleR;
......
......@@ -59,14 +59,14 @@ namespace sw
SetupProcessor::SetupProcessor(Context *context) : context(context)
{
routineCache = 0;
routineCache = nullptr;
setRoutineCacheSize(1024);
}
SetupProcessor::~SetupProcessor()
{
delete routineCache;
routineCache = 0;
routineCache = nullptr;
}
SetupProcessor::State SetupProcessor::update() const
......@@ -75,14 +75,12 @@ namespace sw
bool vPosZW = (context->pixelShader && context->pixelShader->isVPosDeclared() && fullPixelPositionRegister);
state.isDrawPoint = context->isDrawPoint(true);
state.isDrawLine = context->isDrawLine(true);
state.isDrawTriangle = context->isDrawTriangle(false);
state.isDrawSolidTriangle = context->isDrawTriangle(true);
state.interpolateZ = context->depthBufferActive() || context->pixelFogActive() != FOG_NONE || vPosZW;
state.isDrawPoint = context->isDrawPoint();
state.isDrawLine = context->isDrawLine();
state.isDrawTriangle = context->isDrawTriangle();
state.interpolateZ = context->depthBufferActive() || vPosZW;
state.interpolateW = context->perspectiveActive() || vPosZW;
state.perspective = context->perspectiveActive();
state.pointSprite = context->pointSpriteActive();
state.cullMode = context->cullMode;
state.twoSidedStencil = context->stencilActive() && context->twoSidedStencil;
state.slopeDepthBias = context->slopeDepthBias != 0.0f;
......@@ -94,15 +92,8 @@ namespace sw
state.multiSample = context->getMultiSampleCount();
state.rasterizerDiscard = context->rasterizerDiscard;
if(context->vertexShader)
{
state.positionRegister = context->vertexShader->getPositionRegister();
state.pointSizeRegister = context->vertexShader->getPointSizeRegister();
}
else if(context->pointSizeActive())
{
state.pointSizeRegister = Pts;
}
state.positionRegister = context->vertexShader->getPositionRegister();
state.pointSizeRegister = context->vertexShader->getPointSizeRegister();
for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
{
......@@ -114,109 +105,39 @@ namespace sw
}
}
state.fog.attribute = Unused;
state.fog.flat = false;
state.fog.wrap = false;
const bool point = context->isDrawPoint(true);
const bool sprite = context->pointSpriteActive();
const bool flatShading = (context->shadingMode == SHADING_FLAT) || point;
const bool point = context->isDrawPoint();
if(context->vertexShader && context->pixelShader)
for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
{
for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
for(int component = 0; component < 4; component++)
{
for(int component = 0; component < 4; component++)
{
int project = context->isProjectionComponent(interpolant - 2, component) ? 1 : 0;
const Shader::Semantic& semantic = context->pixelShader->getInput(interpolant, component - project);
const Shader::Semantic& semantic = context->pixelShader->getInput(interpolant, component);
if(semantic.active())
if(semantic.active())
{
int input = interpolant;
for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
{
int input = interpolant;
for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
if(semantic == context->vertexShader->getOutput(i, component))
{
if(semantic == context->vertexShader->getOutput(i, component - project))
{
input = i;
break;
}
input = i;
break;
}
bool flat = point;
switch(semantic.usage)
{
case Shader::USAGE_TEXCOORD: flat = point && !sprite; break;
case Shader::USAGE_COLOR: flat = semantic.flat || flatShading; break;
}
state.gradient[interpolant][component].attribute = input;
state.gradient[interpolant][component].flat = flat;
}
}
}
}
else if(context->preTransformed && context->pixelShader)
{
for(int interpolant = 0; interpolant < MAX_FRAGMENT_INPUTS; interpolant++)
{
for(int component = 0; component < 4; component++)
{
const Shader::Semantic& semantic = context->pixelShader->getInput(interpolant, component);
bool flat = point;
switch(semantic.usage)
{
case 0xFF:
break;
case Shader::USAGE_TEXCOORD:
state.gradient[interpolant][component].attribute = T0 + semantic.index;
state.gradient[interpolant][component].flat = semantic.flat || (point && !sprite);
break;
case Shader::USAGE_COLOR:
state.gradient[interpolant][component].attribute = C0 + semantic.index;
state.gradient[interpolant][component].flat = semantic.flat || flatShading;
break;
default:
ASSERT(false);
}
}
}
}
else if(context->pixelShaderModel() < 0x0300)
{
for(int coordinate = 0; coordinate < 8; coordinate++)
{
for(int component = 0; component < 4; component++)
{
if(context->textureActive(coordinate, component))
{
state.texture[coordinate][component].attribute = T0 + coordinate;
state.texture[coordinate][component].flat = point && !sprite;
state.texture[coordinate][component].wrap = (context->textureWrap[coordinate] & (1 << component)) != 0;
case Shader::USAGE_TEXCOORD: flat = false; break;
case Shader::USAGE_COLOR: flat = semantic.flat || point; break;
}
}
}
for(int color = 0; color < 2; color++)
{
for(int component = 0; component < 4; component++)
{
if(context->colorActive(color, component))
{
state.color[color][component].attribute = C0 + color;
state.color[color][component].flat = flatShading;
}
state.gradient[interpolant][component].attribute = input;
state.gradient[interpolant][component].flat = flat;
}
}
}
else ASSERT(false);
if(context->fogActive())
{
state.fog.attribute = Fog;
state.fog.flat = point;
}
state.hash = state.computeHash();
......
......@@ -40,11 +40,9 @@ namespace sw
bool isDrawPoint : 1;
bool isDrawLine : 1;
bool isDrawTriangle : 1;
bool isDrawSolidTriangle : 1;
bool interpolateZ : 1;
bool interpolateW : 1;
bool perspective : 1;
bool pointSprite : 1;
unsigned int positionRegister : BITS(VERTEX_OUTPUT_LAST);
unsigned int pointSizeRegister : BITS(VERTEX_OUTPUT_LAST);
CullMode cullMode : BITS(CULL_LAST);
......@@ -61,17 +59,7 @@ namespace sw
bool wrap : 1;
};
union
{
struct
{
Gradient color[2][4];
Gradient texture[8][4];
Gradient fog;
};
Gradient gradient[MAX_FRAGMENT_INPUTS][4];
};
Gradient gradient[MAX_FRAGMENT_INPUTS][4];
};
struct State : States
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// 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
//
// 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_TextureStage_hpp
#define sw_TextureStage_hpp
#include "System/Types.hpp"
#include "System/Math.hpp"
#include "Device/Color.hpp"
namespace sw
{
class Sampler;
class PixelRoutine;
class Context;
class TextureStage
{
friend class Context; // FIXME
public:
enum StageOperation
{
STAGE_DISABLE,
STAGE_SELECTARG1,
STAGE_SELECTARG2,
STAGE_SELECTARG3,
STAGE_MODULATE,
STAGE_MODULATE2X,
STAGE_MODULATE4X,
STAGE_ADD,
STAGE_ADDSIGNED,
STAGE_ADDSIGNED2X,
STAGE_SUBTRACT,
STAGE_ADDSMOOTH,
STAGE_MULTIPLYADD,
STAGE_LERP,
STAGE_DOT3,
STAGE_BLENDCURRENTALPHA,
STAGE_BLENDDIFFUSEALPHA,
STAGE_BLENDFACTORALPHA,
STAGE_BLENDTEXTUREALPHA,
STAGE_BLENDTEXTUREALPHAPM,
STAGE_PREMODULATE,
STAGE_MODULATEALPHA_ADDCOLOR,
STAGE_MODULATECOLOR_ADDALPHA,
STAGE_MODULATEINVALPHA_ADDCOLOR,
STAGE_MODULATEINVCOLOR_ADDALPHA,
STAGE_BUMPENVMAP,
STAGE_BUMPENVMAPLUMINANCE,
STAGE_LAST = STAGE_BUMPENVMAPLUMINANCE
};
enum SourceArgument
{
SOURCE_TEXTURE,
SOURCE_CONSTANT,
SOURCE_CURRENT,
SOURCE_DIFFUSE,
SOURCE_SPECULAR,
SOURCE_TEMP,
SOURCE_TFACTOR,
SOURCE_LAST = SOURCE_TFACTOR
};
enum DestinationArgument
{
DESTINATION_CURRENT,
DESTINATION_TEMP,
DESTINATION_LAST = DESTINATION_TEMP
};
enum ArgumentModifier
{
MODIFIER_COLOR,
MODIFIER_INVCOLOR,
MODIFIER_ALPHA,
MODIFIER_INVALPHA,
MODIFIER_LAST = MODIFIER_INVALPHA
};
struct State
{
State();
unsigned int stageOperation : BITS(STAGE_LAST);
unsigned int firstArgument : BITS(SOURCE_LAST);
unsigned int secondArgument : BITS(SOURCE_LAST);
unsigned int thirdArgument : BITS(SOURCE_LAST);
unsigned int stageOperationAlpha : BITS(STAGE_LAST);
unsigned int firstArgumentAlpha : BITS(SOURCE_LAST);
unsigned int secondArgumentAlpha : BITS(SOURCE_LAST);
unsigned int thirdArgumentAlpha : BITS(SOURCE_LAST);
unsigned int firstModifier : BITS(MODIFIER_LAST);
unsigned int secondModifier : BITS(MODIFIER_LAST);
unsigned int thirdModifier : BITS(MODIFIER_LAST);
unsigned int firstModifierAlpha : BITS(MODIFIER_LAST);
unsigned int secondModifierAlpha : BITS(MODIFIER_LAST);
unsigned int thirdModifierAlpha : BITS(MODIFIER_LAST);
unsigned int destinationArgument : BITS(DESTINATION_LAST);
unsigned int texCoordIndex : BITS(7);
unsigned int cantUnderflow : 1;
unsigned int usesTexture : 1;
};
struct Uniforms
{
word4 constantColor4[4];
float4 bumpmapMatrix4F[2][2];
word4 bumpmapMatrix4W[2][2];
word4 luminanceScale4;
word4 luminanceOffset4;
};
TextureStage();
~TextureStage();
void init(int stage, const Sampler *sampler, const TextureStage *previousStage);
State textureStageState() const;
void setConstantColor(const Color<float> &constantColor);
void setBumpmapMatrix(int element, float value);
void setLuminanceScale(float value);
void setLuminanceOffset(float value);
void setTexCoordIndex(unsigned int texCoordIndex);
void setStageOperation(StageOperation stageOperation);
void setFirstArgument(SourceArgument firstArgument);
void setSecondArgument(SourceArgument secondArgument);
void setThirdArgument(SourceArgument thirdArgument);
void setStageOperationAlpha(StageOperation stageOperationAlpha);
void setFirstArgumentAlpha(SourceArgument firstArgumentAlpha);
void setSecondArgumentAlpha(SourceArgument secondArgumentAlpha);
void setThirdArgumentAlpha(SourceArgument thirdArgumentAlpha);
void setFirstModifier(ArgumentModifier firstModifier);
void setSecondModifier(ArgumentModifier secondModifier);
void setThirdModifier(ArgumentModifier thirdModifier);
void setFirstModifierAlpha(ArgumentModifier firstModifierAlpha);
void setSecondModifierAlpha(ArgumentModifier secondModifierAlpha);
void setThirdModifierAlpha(ArgumentModifier thirdModifierAlpha);
void setDestinationArgument(DestinationArgument destinationArgument);
Uniforms uniforms; // FIXME: Private
private:
bool usesColor(SourceArgument source) const;
bool usesAlpha(SourceArgument source) const;
bool uses(SourceArgument source) const;
bool usesCurrent() const;
bool usesDiffuse() const;
bool usesSpecular() const;
bool usesTexture() const;
bool isStageDisabled() const;
bool writesCurrent() const;
int stage;
StageOperation stageOperation;
SourceArgument firstArgument;
SourceArgument secondArgument;
SourceArgument thirdArgument;
StageOperation stageOperationAlpha;
SourceArgument firstArgumentAlpha;
SourceArgument secondArgumentAlpha;
SourceArgument thirdArgumentAlpha;
ArgumentModifier firstModifier;
ArgumentModifier secondModifier;
ArgumentModifier thirdModifier;
ArgumentModifier firstModifierAlpha;
ArgumentModifier secondModifierAlpha;
ArgumentModifier thirdModifierAlpha;
DestinationArgument destinationArgument;
int texCoordIndex;
const Sampler *sampler;
const TextureStage *previousStage;
};
}
#endif // sw_TextureStage_hpp
......@@ -55,42 +55,12 @@ namespace sw
unsigned int positionRegister : BITS(MAX_VERTEX_OUTPUTS); // TODO: Eliminate by querying shader.
unsigned int pointSizeRegister : BITS(MAX_VERTEX_OUTPUTS); // TODO: Eliminate by querying shader.
unsigned int vertexBlendMatrixCount : 3;
bool indexedVertexBlendEnable : 1;
bool vertexNormalActive : 1;
bool normalizeNormals : 1;
bool vertexLightingActive : 1;
bool diffuseActive : 1;
bool specularActive : 1;
bool vertexSpecularActive : 1;
unsigned int vertexLightActive : 8;
MaterialSource vertexDiffuseMaterialSourceActive : BITS(MATERIAL_LAST);
MaterialSource vertexSpecularMaterialSourceActive : BITS(MATERIAL_LAST);
MaterialSource vertexAmbientMaterialSourceActive : BITS(MATERIAL_LAST);
MaterialSource vertexEmissiveMaterialSourceActive : BITS(MATERIAL_LAST);
bool fogActive : 1;
FogMode vertexFogMode : BITS(FOG_LAST);
bool rangeFogActive : 1;
bool localViewerActive : 1;
bool pointSizeActive : 1;
bool pointScaleActive : 1;
bool transformFeedbackQueryEnabled : 1;
uint64_t transformFeedbackEnabled : 64;
unsigned char verticesPerPrimitive : 2; // 1 (points), 2 (lines) or 3 (triangles)
bool preTransformed : 1;
bool superSampling : 1;
bool multiSampling : 1;
struct TextureState
{
TexGen texGenActive : BITS(TEXGEN_LAST);
unsigned char textureTransformCountActive : 3;
unsigned char texCoordIndexActive : 3;
};
TextureState textureState[8];
Sampler::State sampler[VERTEX_TEXTURE_IMAGE_UNITS];
struct Input
......@@ -148,39 +118,6 @@ namespace sw
unsigned int hash;
};
struct FixedFunction
{
float4 transformT[12][4];
float4 cameraTransformT[12][4];
float4 normalTransformT[12][4];
float4 textureTransform[8][4];
float4 lightPosition[8];
float4 lightAmbient[8];
float4 lightSpecular[8];
float4 lightDiffuse[8];
float4 attenuationConstant[8];
float4 attenuationLinear[8];
float4 attenuationQuadratic[8];
float lightRange[8];
float4 materialDiffuse;
float4 materialSpecular;
float materialShininess;
float4 globalAmbient;
float4 materialEmission;
float4 materialAmbient;
};
struct PointSprite
{
float4 pointSize;
float pointSizeMin;
float pointSizeMax;
float pointScaleA;
float pointScaleB;
float pointScaleC;
};
typedef void (*RoutinePointer)(Vertex *output, unsigned int *batch, VertexTask *vertexTask, DrawData *draw);
VertexProcessor(Context *context);
......@@ -188,7 +125,7 @@ namespace sw
virtual ~VertexProcessor();
void setInputStream(int index, const Stream &stream);
void resetInputStreams(bool preTransformed);
void resetInputStreams();
void setFloatConstant(unsigned int index, const float value[4]);
void setIntegerConstant(unsigned int index, const int integer[4]);
......@@ -200,54 +137,8 @@ namespace sw
void setTransformFeedbackBuffer(int index, sw::Resource* transformFeedbackBuffer, int offset, unsigned int reg, unsigned int row, unsigned int col, unsigned int stride);
void lockTransformFeedbackBuffers(byte** t, unsigned int* v, unsigned int* r, unsigned int* c, unsigned int* s, sw::Resource* transformFeedbackBuffers[]);
// Transformations
void setModelMatrix(const Matrix &M, int i = 0);
void setViewMatrix(const Matrix &V);
void setBaseMatrix(const Matrix &B);
void setProjectionMatrix(const Matrix &P);
// Lighting
void setLightingEnable(bool lightingEnable);
void setLightEnable(unsigned int light, bool lightEnable);
void setSpecularEnable(bool specularEnable);
void setGlobalAmbient(const Color<float> &globalAmbient);
void setLightPosition(unsigned int light, const Point &lightPosition);
void setLightViewPosition(unsigned int light, const Point &lightPosition);
void setLightDiffuse(unsigned int light, const Color<float> &lightDiffuse);
void setLightSpecular(unsigned int light, const Color<float> &lightSpecular);
void setLightAmbient(unsigned int light, const Color<float> &lightAmbient);
void setLightAttenuation(unsigned int light, float constant, float linear, float quadratic);
void setLightRange(unsigned int light, float lightRange);
void setInstanceID(int instanceID);
void setFogEnable(bool fogEnable);
void setVertexFogMode(FogMode fogMode);
void setRangeFogEnable(bool enable);
void setColorVertexEnable(bool colorVertexEnable);
void setDiffuseMaterialSource(MaterialSource diffuseMaterialSource);
void setSpecularMaterialSource(MaterialSource specularMaterialSource);
void setAmbientMaterialSource(MaterialSource ambientMaterialSource);
void setEmissiveMaterialSource(MaterialSource emissiveMaterialSource);
void setMaterialEmission(const Color<float> &emission);
void setMaterialAmbient(const Color<float> &materialAmbient);
void setMaterialDiffuse(const Color<float> &diffuseColor);
void setMaterialSpecular(const Color<float> &specularColor);
void setMaterialShininess(float specularPower);
void setIndexedVertexBlendEnable(bool indexedVertexBlendEnable);
void setVertexBlendMatrixCount(unsigned int vertexBlendMatrixCount);
void setTextureWrap(unsigned int stage, int mask);
void setTexGen(unsigned int stage, TexGen texGen);
void setLocalViewer(bool localViewer);
void setNormalizeNormals(bool normalizeNormals);
void setTextureMatrix(int stage, const Matrix &T);
void setTextureTransform(int stage, int count, bool project);
void setTextureFilter(unsigned int sampler, FilterType textureFilter);
void setMipmapFilter(unsigned int sampler, MipmapType mipmapFilter);
void setGatherEnable(unsigned int sampler, bool enable);
......@@ -268,26 +159,17 @@ namespace sw
void setMaxLevel(unsigned int sampler, int maxLevel);
void setMinLod(unsigned int sampler, float minLod);
void setMaxLod(unsigned int sampler, float maxLod);
void setSyncRequired(unsigned int sampler, bool isSincRequired);
void setPointSize(float pointSize);
void setPointSizeMin(float pointSizeMin);
void setPointSizeMax(float pointSizeMax);
void setPointScaleA(float pointScaleA);
void setPointScaleB(float pointScaleB);
void setPointScaleC(float pointScaleC);
void setTransformFeedbackQueryEnabled(bool enable);
void enableTransformFeedback(uint64_t enable);
protected:
const Matrix &getModelTransform(int i);
const Matrix &getViewTransform();
const State update(DrawType drawType);
Routine *routine(const State &state);
bool isFixedFunction();
void setRoutineCacheSize(int cacheSize);
// Shader constants
......@@ -295,8 +177,8 @@ namespace sw
int4 i[16];
bool b[16];
PointSprite point;
FixedFunction ff;
float pointSizeMin;
float pointSizeMax;
private:
struct UniformBufferInfo
......@@ -321,31 +203,9 @@ namespace sw
};
TransformFeedbackInfo transformFeedbackInfo[MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS];
void updateTransform();
void setTransform(const Matrix &M, int i);
void setCameraTransform(const Matrix &M, int i);
void setNormalTransform(const Matrix &M, int i);
Context *const context;
RoutineCache<State> *routineCache;
protected:
Matrix M[12]; // Model/Geometry/World matrix
Matrix V; // View/Camera/Eye matrix
Matrix B; // Base matrix
Matrix P; // Projection matrix
Matrix PB; // P * B
Matrix PBV; // P * B * V
Matrix PBVM[12]; // P * B * V * M
// Update hierarchy
bool updateMatrix;
bool updateModelMatrix[12];
bool updateViewMatrix;
bool updateBaseMatrix;
bool updateProjectionMatrix;
bool updateLighting;
};
}
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// 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
//
// 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_PixelPipeline_hpp
#define sw_PixelPipeline_hpp
#include "PixelRoutine.hpp"
namespace sw
{
class PixelPipeline : public PixelRoutine
{
public:
PixelPipeline(const PixelProcessor::State &state, const PixelShader *shader) :
PixelRoutine(state, shader), current(rs[0]), diffuse(vs[0]), specular(vs[1]), perturbate(false), luminance(false), previousScaling(false) {}
virtual ~PixelPipeline() {}
protected:
virtual void setBuiltins(Int &x, Int &y, Float4(&z)[4], Float4 &w);
virtual void applyShader(Int cMask[4]);
virtual Bool alphaTest(Int cMask[4]);
virtual void rasterOperation(Float4 &fog, Pointer<Byte> cBuffer[4], Int &x, Int sMask[4], Int zMask[4], Int cMask[4]);
private:
Vector4s &current;
Vector4s &diffuse;
Vector4s &specular;
Vector4s rs[6];
Vector4s vs[2];
Vector4s ts[6];
// bem(l) offsets and luminance
Float4 du;
Float4 dv;
Short4 L;
// texm3x3 temporaries
Float4 u_; // FIXME
Float4 v_; // FIXME
Float4 w_; // FIXME
Float4 U; // FIXME
Float4 V; // FIXME
Float4 W; // FIXME
void fixedFunction();
void blendTexture(Vector4s &temp, Vector4s &texture, int stage);
void fogBlend(Vector4s &current, Float4 &fog);
void specularPixel(Vector4s &current, Vector4s &specular);
Vector4s sampleTexture(int coordinates, int sampler, bool project = false);
Vector4s sampleTexture(int sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project = false);
Short4 convertFixed12(RValue<Float4> cf);
void convertFixed12(Vector4s &cs, Vector4f &cf);
Float4 convertSigned12(Short4 &cs);
void convertSigned12(Vector4f &cf, Vector4s &cs);
void writeDestination(Vector4s &d, const Dst &dst);
Vector4s fetchRegister(const Src &src);
// Instructions
void MOV(Vector4s &dst, Vector4s &src0);
void ADD(Vector4s &dst, Vector4s &src0, Vector4s &src1);
void SUB(Vector4s &dst, Vector4s &src0, Vector4s &src1);
void MAD(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
void MUL(Vector4s &dst, Vector4s &src0, Vector4s &src1);
void DP3(Vector4s &dst, Vector4s &src0, Vector4s &src1);
void DP4(Vector4s &dst, Vector4s &src0, Vector4s &src1);
void LRP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
void TEXCOORD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate);
void TEXCRD(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int coordinate, bool project);
void TEXDP3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src);
void TEXDP3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0);
void TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s);
void TEXKILL(Int cMask[4], Vector4s &dst);
void TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, bool project);
void TEXLD(Vector4s &dst, Vector4s &src, int stage, bool project);
void TEXBEM(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage);
void TEXBEML(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage);
void TEXREG2AR(Vector4s &dst, Vector4s &src0, int stage);
void TEXREG2GB(Vector4s &dst, Vector4s &src0, int stage);
void TEXREG2RGB(Vector4s &dst, Vector4s &src0, int stage);
void TEXM3X2DEPTH(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src, bool signedScaling);
void TEXM3X2PAD(Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling);
void TEXM3X2TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool signedScaling);
void TEXM3X3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, bool signedScaling);
void TEXM3X3PAD(Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, int component, bool signedScaling);
void TEXM3X3SPEC(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, Vector4s &src1);
void TEXM3X3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool singedScaling);
void TEXM3X3VSPEC(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0);
void TEXDEPTH();
void CND(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
void CMP(Vector4s &dst, Vector4s &src0, Vector4s &src1, Vector4s &src2);
void BEM(Vector4s &dst, Vector4s &src0, Vector4s &src1, int stage);
bool perturbate;
bool luminance;
bool previousScaling;
};
}
#endif
......@@ -627,11 +627,6 @@ namespace sw
c[index].z = linearToSRGB(c[index].z);
}
if(index == 0)
{
fogBlend(c[index], fog);
}
switch(state.targetFormat[index])
{
case FORMAT_R5G6B5:
......
......@@ -583,79 +583,6 @@ namespace sw
cMask[3] &= aMask3;
}
void PixelRoutine::fogBlend(Vector4f &c0, Float4 &fog)
{
if(!state.fogActive)
{
return;
}
if(state.pixelFogMode != FOG_NONE)
{
pixelFog(fog);
fog = Min(fog, Float4(1.0f));
fog = Max(fog, Float4(0.0f));
}
c0.x -= *Pointer<Float4>(data + OFFSET(DrawData,fog.colorF[0]));
c0.y -= *Pointer<Float4>(data + OFFSET(DrawData,fog.colorF[1]));
c0.z -= *Pointer<Float4>(data + OFFSET(DrawData,fog.colorF[2]));
c0.x *= fog;
c0.y *= fog;
c0.z *= fog;
c0.x += *Pointer<Float4>(data + OFFSET(DrawData,fog.colorF[0]));
c0.y += *Pointer<Float4>(data + OFFSET(DrawData,fog.colorF[1]));
c0.z += *Pointer<Float4>(data + OFFSET(DrawData,fog.colorF[2]));
}
void PixelRoutine::pixelFog(Float4 &visibility)
{
Float4 &zw = visibility;
if(state.pixelFogMode != FOG_NONE)
{
if(state.wBasedFog)
{
zw = rhw;
}
else
{
if(complementaryDepthBuffer)
{
zw = Float4(1.0f) - z[0];
}
else
{
zw = z[0];
}
}
}
switch(state.pixelFogMode)
{
case FOG_NONE:
break;
case FOG_LINEAR:
zw *= *Pointer<Float4>(data + OFFSET(DrawData,fog.scale));
zw += *Pointer<Float4>(data + OFFSET(DrawData,fog.offset));
break;
case FOG_EXP:
zw *= *Pointer<Float4>(data + OFFSET(DrawData,fog.densityE));
zw = exponential2(zw, true);
break;
case FOG_EXP2:
zw *= zw;
zw *= *Pointer<Float4>(data + OFFSET(DrawData,fog.density2E));
zw = exponential2(zw, true);
break;
default:
ASSERT(false);
}
}
void PixelRoutine::writeDepth(Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask)
{
if(!state.depthWriteEnable)
......
......@@ -51,8 +51,6 @@ namespace sw
void alphaTest(Int &aMask, Short4 &alpha);
void alphaToCoverage(Int cMask[4], Float4 &alpha);
void fogBlend(Vector4f &c0, Float4 &fog);
void pixelFog(Float4 &visibility);
// Raster operations
void alphaBlend(int index, Pointer<Byte> &cBuffer, Vector4s &current, Int &x);
......
......@@ -47,10 +47,8 @@ namespace sw
Pointer<Byte> constants = *Pointer<Pointer<Byte> >(data + OFFSET(DrawData,constants));
const bool point = state.isDrawPoint;
const bool sprite = state.pointSprite;
const bool line = state.isDrawLine;
const bool triangle = state.isDrawSolidTriangle || sprite;
const bool solidTriangle = state.isDrawSolidTriangle;
const bool triangle = state.isDrawTriangle;
const int V0 = OFFSET(Triangle,v0);
const int V1 = (triangle || line) ? OFFSET(Triangle,v1) : OFFSET(Triangle,v0);
......@@ -76,7 +74,7 @@ namespace sw
Int d = 1; // Winding direction
// Culling
if(solidTriangle)
if(triangle)
{
Float x0 = Float(X[0]);
Float x1 = Float(X[1]);
......@@ -141,7 +139,7 @@ namespace sw
Int n = *Pointer<Int>(polygon + OFFSET(Polygon,n));
Int m = *Pointer<Int>(polygon + OFFSET(Polygon,i));
If(m != 0 || Bool(!solidTriangle)) // Clipped triangle; reproject
If(m != 0 || Bool(!triangle)) // Clipped triangle; reproject
{
Pointer<Byte> V = polygon + OFFSET(Polygon,P) + m * sizeof(void*) * 16;
......@@ -279,7 +277,7 @@ namespace sw
*Pointer<Int>(primitive + OFFSET(Primitive,yMax)) = yMax;
// Sort by minimum y
if(solidTriangle && logPrecision >= WHQL)
if(triangle)
{
Float y0 = *Pointer<Float>(v0 + pos * 16 + 4);
Float y1 = *Pointer<Float>(v1 + pos * 16 + 4);
......@@ -292,7 +290,7 @@ namespace sw
}
// Sort by maximum w
if(solidTriangle)
if(triangle)
{
Float w0 = *Pointer<Float>(v0 + pos * 16 + 12);
Float w1 = *Pointer<Float>(v1 + pos * 16 + 12);
......@@ -463,16 +461,11 @@ namespace sw
if(attribute != Unused)
{
setupGradient(primitive, tri, w012, M, v0, v1, v2, OFFSET(Vertex,v[attribute][component]), OFFSET(Primitive,V[interpolant][component]), flat, sprite, state.perspective, wrap, component);
setupGradient(primitive, tri, w012, M, v0, v1, v2, OFFSET(Vertex,v[attribute][component]), OFFSET(Primitive,V[interpolant][component]), flat, point, state.perspective, wrap, component);
}
}
}
if(state.fog.attribute == Fog)
{
setupGradient(primitive, tri, w012, M, v0, v1, v2, OFFSET(Vertex,f), OFFSET(Primitive,f), state.fog.flat, false, state.perspective, false, 0);
}
Return(true);
}
......@@ -521,7 +514,7 @@ namespace sw
m = Max(m, *Pointer<Float>(v2 + attribute));
m -= 0.5f;
// FIXME: Vectorize
// TODO: Vectorize
If(Float(i.x) < m) i.x = i.x + 1.0f;
If(Float(i.y) < m) i.y = i.y + 1.0f;
If(Float(i.z) < m) i.z = i.z + 1.0f;
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// 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
//
// 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_VertexPipeline_hpp
#define sw_VertexPipeline_hpp
#include "VertexRoutine.hpp"
#include "Device/Context.hpp"
#include "Device/VertexProcessor.hpp"
namespace sw
{
class VertexPipeline : public VertexRoutine
{
public:
VertexPipeline(const VertexProcessor::State &state);
virtual ~VertexPipeline();
private:
void pipeline(UInt &index) override;
void processTextureCoordinate(int stage, Vector4f &normal, Vector4f &position);
void processPointSize();
Vector4f transformBlend(const Register &src, const Pointer<Byte> &matrix, bool homogenous);
Vector4f transform(const Register &src, const Pointer<Byte> &matrix, bool homogenous);
Vector4f transform(const Register &src, const Pointer<Byte> &matrix, UInt index[4], bool homogenous);
Vector4f normalize(Vector4f &src);
Float4 power(Float4 &src0, Float4 &src1);
};
};
#endif // sw_VertexPipeline_hpp
......@@ -59,21 +59,9 @@ namespace sw
{
}
void VertexProgram::pipeline(UInt &index)
{
if(!state.preTransformed)
{
program(index);
}
else
{
passThrough();
}
}
void VertexProgram::program(UInt &index)
{
// shader->print("VertexShader-%0.8X.txt", state.shaderID);
// shader->print("VertexShader-%0.8X.txt", state.shaderID);
unsigned short shaderModel = shader->getShaderModel();
......@@ -418,7 +406,7 @@ namespace sw
if(dst.w) pDst.w = o[C0 + dst.index].w;
break;
case Shader::PARAMETER_TEXCRDOUT:
// case Shader::PARAMETER_OUTPUT:
// case Shader::PARAMETER_OUTPUT:
if(shaderModel < 0x0300)
{
if(dst.x) pDst.x = o[T0 + dst.index].x;
......@@ -564,7 +552,7 @@ namespace sw
if(dst.w) o[C0 + dst.index].w = d.w;
break;
case Shader::PARAMETER_TEXCRDOUT:
// case Shader::PARAMETER_OUTPUT:
// case Shader::PARAMETER_OUTPUT:
if(shaderModel < 0x0300)
{
if(dst.x) o[T0 + dst.index].x = d.x;
......@@ -613,74 +601,6 @@ namespace sw
}
}
void VertexProgram::passThrough()
{
if(shader)
{
for(int i = 0; i < MAX_VERTEX_OUTPUTS; i++)
{
unsigned char usage = shader->getOutput(i, 0).usage;
switch(usage)
{
case 0xFF:
continue;
case Shader::USAGE_PSIZE:
o[i].y = v[i].x;
break;
case Shader::USAGE_TEXCOORD:
o[i].x = v[i].x;
o[i].y = v[i].y;
o[i].z = v[i].z;
o[i].w = v[i].w;
break;
case Shader::USAGE_POSITION:
o[i].x = v[i].x;
o[i].y = v[i].y;
o[i].z = v[i].z;
o[i].w = v[i].w;
break;
case Shader::USAGE_COLOR:
o[i].x = v[i].x;
o[i].y = v[i].y;
o[i].z = v[i].z;
o[i].w = v[i].w;
break;
case Shader::USAGE_FOG:
o[i].x = v[i].x;
break;
default:
ASSERT(false);
}
}
}
else
{
o[Pos].x = v[PositionT].x;
o[Pos].y = v[PositionT].y;
o[Pos].z = v[PositionT].z;
o[Pos].w = v[PositionT].w;
for(int i = 0; i < 2; i++)
{
o[C0 + i].x = v[Color0 + i].x;
o[C0 + i].y = v[Color0 + i].y;
o[C0 + i].z = v[Color0 + i].z;
o[C0 + i].w = v[Color0 + i].w;
}
for(int i = 0; i < 8; i++)
{
o[T0 + i].x = v[TexCoord0 + i].x;
o[T0 + i].y = v[TexCoord0 + i].y;
o[T0 + i].z = v[TexCoord0 + i].z;
o[T0 + i].w = v[TexCoord0 + i].w;
}
o[Pts].y = v[PointSize].x;
}
}
Vector4f VertexProgram::fetchRegister(const Src &src, unsigned int offset)
{
Vector4f reg;
......
......@@ -63,9 +63,7 @@ namespace sw
typedef Shader::Control Control;
typedef Shader::Usage Usage;
void pipeline(UInt &index) override;
void program(UInt &index);
void passThrough();
void program(UInt &index) override;
Vector4f fetchRegister(const Src &src, unsigned int offset = 0);
Vector4f readConstant(const Src &src, unsigned int offset = 0);
......
......@@ -62,7 +62,7 @@ namespace sw
*Pointer<UInt>(tagCache + tagIndex) = indexQ;
readInput(indexQ);
pipeline(indexQ);
program(indexQ);
postTransform();
computeClipFlags();
......@@ -130,11 +130,6 @@ namespace sw
Int4 finiteXYZ = finiteX & finiteY & finiteZ;
clipFlags |= *Pointer<Int>(constants + OFFSET(Constants,fini) + SignMask(finiteXYZ) * 4);
if(state.preTransformed)
{
clipFlags &= 0xFBFBFBFB; // Don't clip against far clip plane
}
}
Vector4f VertexRoutine::readStream(Pointer<Byte> &buffer, UInt &stride, const Stream &stream, const UInt &index)
......@@ -612,33 +607,11 @@ namespace sw
{
int pos = state.positionRegister;
// Backtransform
if(state.preTransformed)
{
Float4 rhw = Float4(1.0f) / o[pos].w;
Float4 W = *Pointer<Float4>(data + OFFSET(DrawData,Wx16)) * Float4(1.0f / 16.0f);
Float4 H = *Pointer<Float4>(data + OFFSET(DrawData,Hx16)) * Float4(1.0f / 16.0f);
Float4 L = *Pointer<Float4>(data + OFFSET(DrawData,X0x16)) * Float4(1.0f / 16.0f);
Float4 T = *Pointer<Float4>(data + OFFSET(DrawData,Y0x16)) * Float4(1.0f / 16.0f);
o[pos].x = (o[pos].x - L) / W * rhw;
o[pos].y = (o[pos].y - T) / H * rhw;
o[pos].z = o[pos].z * rhw;
o[pos].w = rhw;
}
if(!halfIntegerCoordinates && !state.preTransformed)
if(!halfIntegerCoordinates)
{
o[pos].x = o[pos].x + *Pointer<Float4>(data + OFFSET(DrawData,halfPixelX)) * o[pos].w;
o[pos].y = o[pos].y + *Pointer<Float4>(data + OFFSET(DrawData,halfPixelY)) * o[pos].w;
}
if(state.superSampling)
{
o[pos].x = o[pos].x + *Pointer<Float4>(data + OFFSET(DrawData,XXXX)) * o[pos].w;
o[pos].y = o[pos].y + *Pointer<Float4>(data + OFFSET(DrawData,YYYY)) * o[pos].w;
}
}
void VertexRoutine::writeCache(Pointer<Byte> &cacheLine)
......
......@@ -54,7 +54,7 @@ namespace sw
const VertexProcessor::State &state;
private:
virtual void pipeline(UInt &index) = 0;
virtual void program(UInt &index) = 0;
typedef VertexProcessor::State::Input Stream;
......
......@@ -455,8 +455,6 @@ namespace sw
float fogStart;
float fogEnd;
void computeIllumination();
bool textureWrapActive;
unsigned char textureWrap[TEXTURE_IMAGE_UNITS];
TexGen texGen[8];
......
......@@ -15,7 +15,7 @@
#define MAJOR_VERSION 5
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 0
#define BUILD_REVISION 1
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -127,11 +127,9 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClCompile Include="..\Device\SetupProcessor.cpp" />
<ClCompile Include="..\Device\Surface.cpp" />
<ClCompile Include="..\Device\SwiftConfig.cpp" />
<ClCompile Include="..\Device\TextureStage.cpp" />
<ClCompile Include="..\Device\Vector.cpp" />
<ClCompile Include="..\Device\VertexProcessor.cpp" />
<ClCompile Include="..\Pipeline\Constants.cpp" />
<ClCompile Include="..\Pipeline\PixelPipeline.cpp" />
<ClCompile Include="..\Pipeline\PixelProgram.cpp" />
<ClCompile Include="..\Pipeline\PixelRoutine.cpp" />
<ClCompile Include="..\Pipeline\PixelShader.cpp" />
......@@ -139,7 +137,6 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClCompile Include="..\Pipeline\SetupRoutine.cpp" />
<ClCompile Include="..\Pipeline\Shader.cpp" />
<ClCompile Include="..\Pipeline\ShaderCore.cpp" />
<ClCompile Include="..\Pipeline\VertexPipeline.cpp" />
<ClCompile Include="..\Pipeline\VertexProgram.cpp" />
<ClCompile Include="..\Pipeline\VertexRoutine.cpp" />
<ClCompile Include="..\Pipeline\VertexShader.cpp" />
......@@ -224,13 +221,11 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClInclude Include="..\Device\Stream.hpp" />
<ClInclude Include="..\Device\Surface.hpp" />
<ClInclude Include="..\Device\SwiftConfig.hpp" />
<ClInclude Include="..\Device\TextureStage.hpp" />
<ClInclude Include="..\Device\Triangle.hpp" />
<ClInclude Include="..\Device\Vector.hpp" />
<ClInclude Include="..\Device\Vertex.hpp" />
<ClInclude Include="..\Device\VertexProcessor.hpp" />
<ClInclude Include="..\Pipeline\Constants.hpp" />
<ClInclude Include="..\Pipeline\PixelPipeline.hpp" />
<ClInclude Include="..\Pipeline\PixelProgram.hpp" />
<ClInclude Include="..\Pipeline\PixelRoutine.hpp" />
<ClInclude Include="..\Pipeline\PixelShader.hpp" />
......
......@@ -51,9 +51,6 @@
<ClCompile Include="..\Device\Vector.cpp">
<Filter>Source Files\Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\TextureStage.cpp">
<Filter>Source Files\Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\SwiftConfig.cpp">
<Filter>Source Files\Device</Filter>
</ClCompile>
......@@ -111,9 +108,6 @@
<ClCompile Include="..\Pipeline\VertexProgram.cpp">
<Filter>Source Files\Pipeline</Filter>
</ClCompile>
<ClCompile Include="..\Pipeline\VertexPipeline.cpp">
<Filter>Source Files\Pipeline</Filter>
</ClCompile>
<ClCompile Include="..\Pipeline\ShaderCore.cpp">
<Filter>Source Files\Pipeline</Filter>
</ClCompile>
......@@ -135,9 +129,6 @@
<ClCompile Include="..\Pipeline\PixelProgram.cpp">
<Filter>Source Files\Pipeline</Filter>
</ClCompile>
<ClCompile Include="..\Pipeline\PixelPipeline.cpp">
<Filter>Source Files\Pipeline</Filter>
</ClCompile>
<ClCompile Include="..\Pipeline\Constants.cpp">
<Filter>Source Files\Pipeline</Filter>
</ClCompile>
......@@ -302,9 +293,6 @@
<ClInclude Include="..\Device\Triangle.hpp">
<Filter>Header Files\Device</Filter>
</ClInclude>
<ClInclude Include="..\Device\TextureStage.hpp">
<Filter>Header Files\Device</Filter>
</ClInclude>
<ClInclude Include="..\Device\SwiftConfig.hpp">
<Filter>Header Files\Device</Filter>
</ClInclude>
......@@ -431,9 +419,6 @@
<ClInclude Include="..\Pipeline\PixelProgram.hpp">
<Filter>Header Files\Pipeline</Filter>
</ClInclude>
<ClInclude Include="..\Pipeline\PixelPipeline.hpp">
<Filter>Header Files\Pipeline</Filter>
</ClInclude>
<ClInclude Include="..\Pipeline\Constants.hpp">
<Filter>Header Files\Pipeline</Filter>
</ClInclude>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment