Commit de903449 by Nicolas Capens Committed by Nicolas Capens

Create SamplerCore on demand.

Previously we dynamically allocated an array of SamplerCores. This isn't necessary and we can just create one as a temporary object where used. This has the added advantage that we could have Reactor variables as class members and keep them short-lived. Change-Id: Ifb2e6edbf275aa793bd7880bd35384e16000007d Reviewed-on: https://swiftshader-review.googlesource.com/13548Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent f878d50b
......@@ -1238,7 +1238,7 @@ namespace sw
if(!project)
{
sampler[stage]->sampleTexture(texture, c, u, v, w, q, dsx, dsy);
SamplerCore(constants, state.sampler[stage]).sampleTexture(texture, c, u, v, w, q, dsx, dsy);
}
else
{
......@@ -1248,7 +1248,7 @@ namespace sw
Float4 v_q = v * rq;
Float4 w_q = w * rq;
sampler[stage]->sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy);
SamplerCore(constants, state.sampler[stage]).sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy);
}
#if PERF_PROFILE
......
......@@ -716,7 +716,7 @@ namespace sw
#endif
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + samplerIndex * sizeof(Texture);
sampler[samplerIndex]->sampleTexture(texture, c, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
SamplerCore(constants, state.sampler[samplerIndex]).sampleTexture(texture, c, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
#if PERF_PROFILE
cycles[PERF_TEX] += Ticks() - texTime;
......@@ -1169,7 +1169,7 @@ namespace sw
void PixelProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1)
{
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + src1.index * sizeof(Texture);
sampler[src1.index]->textureSize(texture, dst, lod);
SamplerCore::textureSize(texture, dst, lod);
}
void PixelProgram::TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask)
......
......@@ -45,10 +45,6 @@ namespace sw
PixelRoutine::~PixelRoutine()
{
for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
{
delete sampler[i];
}
}
void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y)
......@@ -57,11 +53,6 @@ namespace sw
Long pipeTime = Ticks();
#endif
for(int i = 0; i < TEXTURE_IMAGE_UNITS; i++)
{
sampler[i] = new SamplerCore(constants, state.sampler[i]);
}
const bool earlyDepthTest = !state.depthOverride && !state.alphaTestActive();
Int zMask[4]; // Depth mask
......
......@@ -65,8 +65,6 @@ namespace sw
UShort4 convertFixed16(Float4 &cf, bool saturate = true);
void linearToSRGB12_16(Vector4s &c);
SamplerCore *sampler[TEXTURE_IMAGE_UNITS];
private:
Float4 interpolateCentroid(Float4 &x, Float4 &y, Float4 &rhw, Pointer<Byte> planeEquation, bool flat, bool perspective);
void stencilTest(Pointer<Byte> &sBuffer, int q, Int &x, Int &sMask, Int &cMask);
......
......@@ -47,11 +47,11 @@ namespace sw
class SamplerCore
{
public:
SamplerCore(Pointer<Byte> &r, const Sampler::State &state);
SamplerCore(Pointer<Byte> &constants, const Sampler::State &state);
void sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy);
void sampleTexture(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
void textureSize(Pointer<Byte> &mipmap, Vector4f &size, Float4 &lod);
static void textureSize(Pointer<Byte> &mipmap, Vector4f &size, Float4 &lod);
private:
void sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function, bool fixed12);
......
......@@ -58,19 +58,10 @@ namespace sw
VertexProgram::~VertexProgram()
{
for(int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++)
{
delete sampler[i];
}
}
void VertexProgram::pipeline(UInt& index)
{
for(int i = 0; i < VERTEX_TEXTURE_IMAGE_UNITS; i++)
{
sampler[i] = new SamplerCore(constants, state.sampler[i]);
}
if(!state.preTransformed)
{
program(index);
......@@ -1610,7 +1601,7 @@ namespace sw
void VertexProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1)
{
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[16]) + src1.index * sizeof(Texture);
sampler[src1.index]->textureSize(texture, dst, lod);
SamplerCore::textureSize(texture, dst, lod);
}
void VertexProgram::sampleTexture(Vector4f &c, const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
......@@ -1620,7 +1611,7 @@ namespace sw
if(s.type == Shader::PARAMETER_SAMPLER && s.rel.type == Shader::PARAMETER_VOID)
{
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + s.index * sizeof(Texture);
sampler[s.index]->sampleTexture(texture, tmp, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
SamplerCore(constants, state.sampler[s.index]).sampleTexture(texture, tmp, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
}
else
{
......@@ -1633,7 +1624,7 @@ namespace sw
If(index == i)
{
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + i * sizeof(Texture);
sampler[i]->sampleTexture(texture, tmp, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
SamplerCore(constants, state.sampler[i]).sampleTexture(texture, tmp, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
// FIXME: When the sampler states are the same, we could use one sampler and just index the texture
}
}
......
......@@ -119,8 +119,6 @@ namespace sw
void sampleTexture(Vector4f &c, const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
SamplerCore *sampler[VERTEX_TEXTURE_IMAGE_UNITS];
int ifDepth;
int loopRepDepth;
int breakDepth;
......
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