Commit 89a218b4 by Nicolas Capens Committed by Nicolas Capens

Refactor sampling functions to use a return value.

Change-Id: Ib62f310abecbc4cdaf6e9300791600f25af0eaf3 Reviewed-on: https://swiftshader-review.googlesource.com/13550Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent de903449
...@@ -49,7 +49,7 @@ namespace sw ...@@ -49,7 +49,7 @@ namespace sw
if(state.textureStage[stage].usesTexture) if(state.textureStage[stage].usesTexture)
{ {
sampleTexture(texture, stage, stage); texture = sampleTexture(stage, stage);
} }
blendTexture(temp, texture, stage); blendTexture(temp, texture, stage);
...@@ -1207,7 +1207,7 @@ namespace sw ...@@ -1207,7 +1207,7 @@ namespace sw
current.z = AddSat(current.z, specular.z); current.z = AddSat(current.z, specular.z);
} }
void PixelPipeline::sampleTexture(Vector4s &c, int coordinates, int stage, bool project) Vector4s PixelPipeline::sampleTexture(int coordinates, int stage, bool project)
{ {
Float4 x = v[2 + coordinates].x; Float4 x = v[2 + coordinates].x;
Float4 y = v[2 + coordinates].y; Float4 y = v[2 + coordinates].y;
...@@ -1222,11 +1222,13 @@ namespace sw ...@@ -1222,11 +1222,13 @@ namespace sw
perturbate = false; perturbate = false;
} }
sampleTexture(c, stage, x, y, z, w, project); return sampleTexture(stage, x, y, z, w, project);
} }
void PixelPipeline::sampleTexture(Vector4s &c, int stage, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project) Vector4s PixelPipeline::sampleTexture(int stage, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project)
{ {
Vector4s c;
#if PERF_PROFILE #if PERF_PROFILE
Long texTime = Ticks(); Long texTime = Ticks();
#endif #endif
...@@ -1238,7 +1240,7 @@ namespace sw ...@@ -1238,7 +1240,7 @@ namespace sw
if(!project) if(!project)
{ {
SamplerCore(constants, state.sampler[stage]).sampleTexture(texture, c, u, v, w, q, dsx, dsy); c = SamplerCore(constants, state.sampler[stage]).sampleTexture(texture, u, v, w, q, dsx, dsy);
} }
else else
{ {
...@@ -1248,12 +1250,14 @@ namespace sw ...@@ -1248,12 +1250,14 @@ namespace sw
Float4 v_q = v * rq; Float4 v_q = v * rq;
Float4 w_q = w * rq; Float4 w_q = w * rq;
SamplerCore(constants, state.sampler[stage]).sampleTexture(texture, c, u_q, v_q, w_q, q, dsx, dsy); c = SamplerCore(constants, state.sampler[stage]).sampleTexture(texture, u_q, v_q, w_q, q, dsx, dsy);
} }
#if PERF_PROFILE #if PERF_PROFILE
cycles[PERF_TEX] += Ticks() - texTime; cycles[PERF_TEX] += Ticks() - texTime;
#endif #endif
return c;
} }
Short4 PixelPipeline::convertFixed12(RValue<Float4> cf) Short4 PixelPipeline::convertFixed12(RValue<Float4> cf)
...@@ -1470,22 +1474,18 @@ namespace sw ...@@ -1470,22 +1474,18 @@ namespace sw
{ {
// FIXME: Long fixed-point multiply fixup // FIXME: Long fixed-point multiply fixup
{ dst.x = MulHigh(src0.x, src1.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, src2.x); } { dst.x = MulHigh(src0.x, src1.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, src2.x); }
{ { dst.y = MulHigh(src0.y, src1.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, src2.y); }
dst.y = MulHigh(src0.y, src1.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, src2.y); { dst.z = MulHigh(src0.z, src1.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, src2.z); }
} { dst.w = MulHigh(src0.w, src1.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, src2.w); }
{dst.z = MulHigh(src0.z, src1.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, src2.z); }
{dst.w = MulHigh(src0.w, src1.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, src2.w); }
} }
void PixelPipeline::MUL(Vector4s &dst, Vector4s &src0, Vector4s &src1) void PixelPipeline::MUL(Vector4s &dst, Vector4s &src0, Vector4s &src1)
{ {
// FIXME: Long fixed-point multiply fixup // FIXME: Long fixed-point multiply fixup
{ dst.x = MulHigh(src0.x, src1.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); } { dst.x = MulHigh(src0.x, src1.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); dst.x = AddSat(dst.x, dst.x); }
{ { dst.y = MulHigh(src0.y, src1.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); }
dst.y = MulHigh(src0.y, src1.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); dst.y = AddSat(dst.y, dst.y); { dst.z = MulHigh(src0.z, src1.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); }
} { dst.w = MulHigh(src0.w, src1.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); }
{dst.z = MulHigh(src0.z, src1.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); dst.z = AddSat(dst.z, dst.z); }
{dst.w = MulHigh(src0.w, src1.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); dst.w = AddSat(dst.w, dst.w); }
} }
void PixelPipeline::DP3(Vector4s &dst, Vector4s &src0, Vector4s &src1) void PixelPipeline::DP3(Vector4s &dst, Vector4s &src0, Vector4s &src1)
...@@ -1647,7 +1647,7 @@ namespace sw ...@@ -1647,7 +1647,7 @@ namespace sw
v_ = Float4(0.0f); v_ = Float4(0.0f);
w_ = Float4(0.0f); w_ = Float4(0.0f);
sampleTexture(dst, stage, u_, v_, w_, w_); dst = sampleTexture(stage, u_, v_, w_, w_);
} }
void PixelPipeline::TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s) void PixelPipeline::TEXKILL(Int cMask[4], Float4 &u, Float4 &v, Float4 &s)
...@@ -1675,7 +1675,7 @@ namespace sw ...@@ -1675,7 +1675,7 @@ namespace sw
void PixelPipeline::TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int sampler, bool project) void PixelPipeline::TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int sampler, bool project)
{ {
sampleTexture(dst, sampler, u, v, s, s, project); dst = sampleTexture(sampler, u, v, s, s, project);
} }
void PixelPipeline::TEXLD(Vector4s &dst, Vector4s &src, int sampler, bool project) void PixelPipeline::TEXLD(Vector4s &dst, Vector4s &src, int sampler, bool project)
...@@ -1684,7 +1684,7 @@ namespace sw ...@@ -1684,7 +1684,7 @@ namespace sw
Float4 v = Float4(src.y) * Float4(1.0f / 0x0FFE); Float4 v = Float4(src.y) * Float4(1.0f / 0x0FFE);
Float4 s = Float4(src.z) * Float4(1.0f / 0x0FFE); Float4 s = Float4(src.z) * Float4(1.0f / 0x0FFE);
sampleTexture(dst, sampler, u, v, s, s, project); dst = sampleTexture(sampler, u, v, s, s, project);
} }
void PixelPipeline::TEXBEM(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage) void PixelPipeline::TEXBEM(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage)
...@@ -1705,7 +1705,7 @@ namespace sw ...@@ -1705,7 +1705,7 @@ namespace sw
Float4 u_ = u + du; Float4 u_ = u + du;
Float4 v_ = v + dv; Float4 v_ = v + dv;
sampleTexture(dst, stage, u_, v_, s, s); dst = sampleTexture(stage, u_, v_, s, s);
} }
void PixelPipeline::TEXBEML(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage) void PixelPipeline::TEXBEML(Vector4s &dst, Vector4s &src, Float4 &u, Float4 &v, Float4 &s, int stage)
...@@ -1726,7 +1726,7 @@ namespace sw ...@@ -1726,7 +1726,7 @@ namespace sw
Float4 u_ = u + du; Float4 u_ = u + du;
Float4 v_ = v + dv; Float4 v_ = v + dv;
sampleTexture(dst, stage, u_, v_, s, s); dst = sampleTexture(stage, u_, v_, s, s);
Short4 L; Short4 L;
...@@ -1748,7 +1748,7 @@ namespace sw ...@@ -1748,7 +1748,7 @@ namespace sw
Float4 v = Float4(src0.x) * Float4(1.0f / 0x0FFE); Float4 v = Float4(src0.x) * Float4(1.0f / 0x0FFE);
Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE);
sampleTexture(dst, stage, u, v, s, s); dst = sampleTexture(stage, u, v, s, s);
} }
void PixelPipeline::TEXREG2GB(Vector4s &dst, Vector4s &src0, int stage) void PixelPipeline::TEXREG2GB(Vector4s &dst, Vector4s &src0, int stage)
...@@ -1757,7 +1757,7 @@ namespace sw ...@@ -1757,7 +1757,7 @@ namespace sw
Float4 v = Float4(src0.z) * Float4(1.0f / 0x0FFE); Float4 v = Float4(src0.z) * Float4(1.0f / 0x0FFE);
Float4 s = v; Float4 s = v;
sampleTexture(dst, stage, u, v, s, s); dst = sampleTexture(stage, u, v, s, s);
} }
void PixelPipeline::TEXREG2RGB(Vector4s &dst, Vector4s &src0, int stage) void PixelPipeline::TEXREG2RGB(Vector4s &dst, Vector4s &src0, int stage)
...@@ -1766,7 +1766,7 @@ namespace sw ...@@ -1766,7 +1766,7 @@ namespace sw
Float4 v = Float4(src0.y) * Float4(1.0f / 0x0FFE); Float4 v = Float4(src0.y) * Float4(1.0f / 0x0FFE);
Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE); Float4 s = Float4(src0.z) * Float4(1.0f / 0x0FFE);
sampleTexture(dst, stage, u, v, s, s); dst = sampleTexture(stage, u, v, s, s);
} }
void PixelPipeline::TEXM3X2DEPTH(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src, bool signedScaling) void PixelPipeline::TEXM3X2DEPTH(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src, bool signedScaling)
...@@ -1790,7 +1790,7 @@ namespace sw ...@@ -1790,7 +1790,7 @@ namespace sw
w_ = Float4(0.0f); w_ = Float4(0.0f);
sampleTexture(dst, stage, u_, v_, w_, w_); dst = sampleTexture(stage, u_, v_, w_, w_);
} }
void PixelPipeline::TEXM3X3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, bool signedScaling) void PixelPipeline::TEXM3X3(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, Vector4s &src0, bool signedScaling)
...@@ -1861,14 +1861,14 @@ namespace sw ...@@ -1861,14 +1861,14 @@ namespace sw
v__ -= E[1] * u_; v__ -= E[1] * u_;
w__ -= E[2] * u_; w__ -= E[2] * u_;
sampleTexture(dst, stage, u__, v__, w__, w__); dst = sampleTexture(stage, u__, v__, w__, w__);
} }
void PixelPipeline::TEXM3X3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool signedScaling) void PixelPipeline::TEXM3X3TEX(Vector4s &dst, Float4 &u, Float4 &v, Float4 &s, int stage, Vector4s &src0, bool signedScaling)
{ {
TEXM3X3PAD(u, v, s, src0, 2, signedScaling); TEXM3X3PAD(u, v, s, src0, 2, signedScaling);
sampleTexture(dst, stage, u_, v_, w_, w_); dst = sampleTexture(stage, u_, v_, w_, w_);
} }
void PixelPipeline::TEXM3X3VSPEC(Vector4s &dst, Float4 &x, Float4 &y, Float4 &z, int stage, Vector4s &src0) void PixelPipeline::TEXM3X3VSPEC(Vector4s &dst, Float4 &x, Float4 &y, Float4 &z, int stage, Vector4s &src0)
...@@ -1905,7 +1905,7 @@ namespace sw ...@@ -1905,7 +1905,7 @@ namespace sw
v__ -= E[1] * u_; v__ -= E[1] * u_;
w__ -= E[2] * u_; w__ -= E[2] * u_;
sampleTexture(dst, stage, u__, v__, w__, w__); dst = sampleTexture(stage, u__, v__, w__, w__);
} }
void PixelPipeline::TEXDEPTH() void PixelPipeline::TEXDEPTH()
......
...@@ -59,8 +59,8 @@ namespace sw ...@@ -59,8 +59,8 @@ namespace sw
void fogBlend(Vector4s &current, Float4 &fog); void fogBlend(Vector4s &current, Float4 &fog);
void specularPixel(Vector4s &current, Vector4s &specular); void specularPixel(Vector4s &current, Vector4s &specular);
void sampleTexture(Vector4s &c, int coordinates, int sampler, bool project = false); Vector4s sampleTexture(int coordinates, int sampler, bool project = false);
void sampleTexture(Vector4s &c, int sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project = false); Vector4s sampleTexture(int sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, bool project = false);
Short4 convertFixed12(RValue<Float4> cf); Short4 convertFixed12(RValue<Float4> cf);
void convertFixed12(Vector4s &cs, Vector4f &cf); void convertFixed12(Vector4s &cs, Vector4f &cf);
......
...@@ -678,13 +678,13 @@ namespace sw ...@@ -678,13 +678,13 @@ namespace sw
} }
} }
void PixelProgram::sampleTexture(Vector4f &c, const Src &sampler, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function) Vector4f PixelProgram::sampleTexture(const Src &sampler, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
{ {
Vector4f tmp; Vector4f tmp;
if(sampler.type == Shader::PARAMETER_SAMPLER && sampler.rel.type == Shader::PARAMETER_VOID) if(sampler.type == Shader::PARAMETER_SAMPLER && sampler.rel.type == Shader::PARAMETER_VOID)
{ {
sampleTexture(tmp, sampler.index, uvwq, dsx, dsy, offset, function); tmp = sampleTexture(sampler.index, uvwq, dsx, dsy, offset, function);
} }
else else
{ {
...@@ -696,31 +696,36 @@ namespace sw ...@@ -696,31 +696,36 @@ namespace sw
{ {
If(index == i) If(index == i)
{ {
sampleTexture(tmp, i, uvwq, dsx, dsy, offset, function); tmp = sampleTexture(i, uvwq, dsx, dsy, offset, function);
// FIXME: When the sampler states are the same, we could use one sampler and just index the texture // FIXME: When the sampler states are the same, we could use one sampler and just index the texture
} }
} }
} }
} }
Vector4f c;
c.x = tmp[(sampler.swizzle >> 0) & 0x3]; c.x = tmp[(sampler.swizzle >> 0) & 0x3];
c.y = tmp[(sampler.swizzle >> 2) & 0x3]; c.y = tmp[(sampler.swizzle >> 2) & 0x3];
c.z = tmp[(sampler.swizzle >> 4) & 0x3]; c.z = tmp[(sampler.swizzle >> 4) & 0x3];
c.w = tmp[(sampler.swizzle >> 6) & 0x3]; c.w = tmp[(sampler.swizzle >> 6) & 0x3];
return c;
} }
void PixelProgram::sampleTexture(Vector4f &c, int samplerIndex, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function) Vector4f PixelProgram::sampleTexture(int samplerIndex, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
{ {
#if PERF_PROFILE #if PERF_PROFILE
Long texTime = Ticks(); Long texTime = Ticks();
#endif #endif
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + samplerIndex * sizeof(Texture); Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + samplerIndex * sizeof(Texture);
SamplerCore(constants, state.sampler[samplerIndex]).sampleTexture(texture, c, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function); Vector4f c = SamplerCore(constants, state.sampler[samplerIndex]).sampleTexture(texture, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
#if PERF_PROFILE #if PERF_PROFILE
cycles[PERF_TEX] += Ticks() - texTime; cycles[PERF_TEX] += Ticks() - texTime;
#endif #endif
return c;
} }
void PixelProgram::clampColor(Vector4f oC[RENDERTARGETS]) void PixelProgram::clampColor(Vector4f oC[RENDERTARGETS])
...@@ -1118,58 +1123,58 @@ namespace sw ...@@ -1118,58 +1123,58 @@ namespace sw
proj.y = src0.y * rw; proj.y = src0.y * rw;
proj.z = src0.z * rw; proj.z = src0.z * rw;
sampleTexture(dst, src1, proj, src0, src0, src0, Implicit); dst = sampleTexture(src1, proj, src0, src0, src0, Implicit);
} }
else else
{ {
sampleTexture(dst, src1, src0, src0, src0, src0, bias ? Bias : Implicit); dst = sampleTexture(src1, src0, src0, src0, src0, bias ? Bias : Implicit);
} }
} }
void PixelProgram::TEXOFFSET(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, bool bias) void PixelProgram::TEXOFFSET(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, bool bias)
{ {
sampleTexture(dst, src1, src0, src0, src0, src2, {bias ? Bias : Implicit, Offset}); dst = sampleTexture(src1, src0, src0, src0, src2, {bias ? Bias : Implicit, Offset});
} }
void PixelProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &offset, bool bias) void PixelProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &offset, bool bias)
{ {
sampleTexture(dst, src1, src0, src0, src0, offset, {Lod, Offset}); dst = sampleTexture(src1, src0, src0, src0, offset, {Lod, Offset});
} }
void PixelProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1) void PixelProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1)
{ {
sampleTexture(dst, src1, src0, src0, src0, src0, Fetch); dst = sampleTexture(src1, src0, src0, src0, src0, Fetch);
} }
void PixelProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &offset) void PixelProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &offset)
{ {
sampleTexture(dst, src1, src0, src0, src0, offset, {Fetch, Offset}); dst = sampleTexture(src1, src0, src0, src0, offset, {Fetch, Offset});
} }
void PixelProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3) void PixelProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3)
{ {
sampleTexture(dst, src1, src0, src2, src3, src0, Grad); dst = sampleTexture(src1, src0, src2, src3, src0, Grad);
} }
void PixelProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3, Vector4f &offset) void PixelProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3, Vector4f &offset)
{ {
sampleTexture(dst, src1, src0, src2, src3, offset, {Grad, Offset}); dst = sampleTexture(src1, src0, src2, src3, offset, {Grad, Offset});
} }
void PixelProgram::TEXLDD(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, Vector4f &src3) void PixelProgram::TEXLDD(Vector4f &dst, Vector4f &src0, const Src &src1, Vector4f &src2, Vector4f &src3)
{ {
sampleTexture(dst, src1, src0, src2, src3, src0, Grad); dst = sampleTexture(src1, src0, src2, src3, src0, Grad);
} }
void PixelProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1) void PixelProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1)
{ {
sampleTexture(dst, src1, src0, src0, src0, src0, Lod); dst = sampleTexture(src1, src0, src0, src0, src0, Lod);
} }
void PixelProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1) void PixelProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1)
{ {
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + src1.index * sizeof(Texture); Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + src1.index * sizeof(Texture);
SamplerCore::textureSize(texture, dst, lod); dst = SamplerCore::textureSize(texture, lod);
} }
void PixelProgram::TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask) void PixelProgram::TEXKILL(Int cMask[4], Vector4f &src, unsigned char mask)
......
...@@ -82,8 +82,8 @@ namespace sw ...@@ -82,8 +82,8 @@ namespace sw
Int4 enableContinue; Int4 enableContinue;
Int4 enableLeave; Int4 enableLeave;
void sampleTexture(Vector4f &c, const Src &sampler, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function); Vector4f sampleTexture(const Src &sampler, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
void sampleTexture(Vector4f &c, int samplerIndex, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function); Vector4f sampleTexture(int samplerIndex, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
// Raster operations // Raster operations
void clampColor(Vector4f oC[RENDERTARGETS]); void clampColor(Vector4f oC[RENDERTARGETS]);
......
...@@ -56,13 +56,15 @@ namespace sw ...@@ -56,13 +56,15 @@ namespace sw
{ {
} }
void SamplerCore::sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy) Vector4s SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy)
{ {
sampleTexture(texture, c, u, v, w, q, dsx, dsy, dsx, Implicit, true); return sampleTexture(texture, u, v, w, q, dsx, dsy, dsx, Implicit, true);
} }
void SamplerCore::sampleTexture(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function, bool fixed12) Vector4s SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function, bool fixed12)
{ {
Vector4s c;
#if PERF_PROFILE #if PERF_PROFILE
AddAtomic(Pointer<Long>(&profiler.texOperations), 4); AddAtomic(Pointer<Long>(&profiler.texOperations), 4);
...@@ -127,13 +129,11 @@ namespace sw ...@@ -127,13 +129,11 @@ namespace sw
if(!hasFloatTexture()) if(!hasFloatTexture())
{ {
sampleFilter(texture, c, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function); c = sampleFilter(texture, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function);
} }
else else
{ {
Vector4f cf; Vector4f cf = sampleFloatFilter(texture, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function);
sampleFloatFilter(texture, cf, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function);
convertFixed12(c, cf); convertFixed12(c, cf);
} }
...@@ -295,10 +295,14 @@ namespace sw ...@@ -295,10 +295,14 @@ namespace sw
applySwizzle(state.swizzleB, c.z, col); applySwizzle(state.swizzleB, c.z, col);
applySwizzle(state.swizzleA, c.w, col); applySwizzle(state.swizzleA, c.w, col);
} }
return c;
} }
void SamplerCore::sampleTexture(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function) Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
{ {
Vector4f c;
#if PERF_PROFILE #if PERF_PROFILE
AddAtomic(Pointer<Long>(&profiler.texOperations), 4); AddAtomic(Pointer<Long>(&profiler.texOperations), 4);
...@@ -357,7 +361,7 @@ namespace sw ...@@ -357,7 +361,7 @@ namespace sw
computeLod3D(texture, lod, uuuu, vvvv, wwww, lodBias, dsx, dsy, function); computeLod3D(texture, lod, uuuu, vvvv, wwww, lodBias, dsx, dsy, function);
} }
sampleFloatFilter(texture, c, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function); c = sampleFloatFilter(texture, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function);
if(!hasFloatTexture() && !hasUnnormalizedIntegerTexture()) if(!hasFloatTexture() && !hasUnnormalizedIntegerTexture())
{ {
...@@ -385,9 +389,7 @@ namespace sw ...@@ -385,9 +389,7 @@ namespace sw
} }
else else
{ {
Vector4s cs; Vector4s cs = sampleTexture(texture, u, v, w, q, dsx, dsy, offset, function, false);
sampleTexture(texture, cs, u, v, w, q, dsx, dsy, offset, function, false);
if(has16bitTextureFormat()) if(has16bitTextureFormat())
{ {
...@@ -553,10 +555,14 @@ namespace sw ...@@ -553,10 +555,14 @@ namespace sw
applySwizzle(state.swizzleB, c.z, col); applySwizzle(state.swizzleB, c.z, col);
applySwizzle(state.swizzleA, c.w, col); applySwizzle(state.swizzleA, c.w, col);
} }
return c;
} }
void SamplerCore::textureSize(Pointer<Byte> &texture, Vector4f &size, Float4 &lod) Vector4f SamplerCore::textureSize(Pointer<Byte> &texture, Float4 &lod)
{ {
Vector4f size;
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
Int baseLevel = *Pointer<Int>(texture + OFFSET(Texture, baseLevel)); Int baseLevel = *Pointer<Int>(texture + OFFSET(Texture, baseLevel));
...@@ -565,6 +571,8 @@ namespace sw ...@@ -565,6 +571,8 @@ namespace sw
size.y = Insert(size.y, As<Float>(Int(*Pointer<Short>(mipmap + OFFSET(Mipmap, height)))), i); size.y = Insert(size.y, As<Float>(Int(*Pointer<Short>(mipmap + OFFSET(Mipmap, height)))), i);
size.z = Insert(size.z, As<Float>(Int(*Pointer<Short>(mipmap + OFFSET(Mipmap, depth)))), i); size.z = Insert(size.z, As<Float>(Int(*Pointer<Short>(mipmap + OFFSET(Mipmap, depth)))), i);
} }
return size;
} }
void SamplerCore::border(Short4 &mask, Float4 &coordinates) void SamplerCore::border(Short4 &mask, Float4 &coordinates)
...@@ -615,20 +623,18 @@ namespace sw ...@@ -615,20 +623,18 @@ namespace sw
return uvw; return uvw;
} }
void SamplerCore::sampleFilter(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function) Vector4s SamplerCore::sampleFilter(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function)
{ {
sampleAniso(texture, c, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, false, function); Vector4s c = sampleAniso(texture, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, false, function);
if(function == Fetch) if(function == Fetch)
{ {
return; return c;
} }
if(state.mipmapFilter > MIPMAP_POINT) if(state.mipmapFilter > MIPMAP_POINT)
{ {
Vector4s cc; Vector4s cc = sampleAniso(texture, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
sampleAniso(texture, cc, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
lod *= Float(1 << 16); lod *= Float(1 << 16);
...@@ -714,13 +720,17 @@ namespace sw ...@@ -714,13 +720,17 @@ namespace sw
c.z = (borderMask & c.z) | (~borderMask & (*Pointer<Short4>(texture + OFFSET(Texture,borderColor4[2])) >> (hasUnsignedTextureComponent(2) ? 0 : 1))); c.z = (borderMask & c.z) | (~borderMask & (*Pointer<Short4>(texture + OFFSET(Texture,borderColor4[2])) >> (hasUnsignedTextureComponent(2) ? 0 : 1)));
c.w = (borderMask & c.w) | (~borderMask & (*Pointer<Short4>(texture + OFFSET(Texture,borderColor4[3])) >> (hasUnsignedTextureComponent(3) ? 0 : 1))); c.w = (borderMask & c.w) | (~borderMask & (*Pointer<Short4>(texture + OFFSET(Texture,borderColor4[3])) >> (hasUnsignedTextureComponent(3) ? 0 : 1)));
} }
return c;
} }
void SamplerCore::sampleAniso(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function) Vector4s SamplerCore::sampleAniso(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function)
{ {
Vector4s c;
if(state.textureFilter != FILTER_ANISOTROPIC || function == Lod || function == Fetch) if(state.textureFilter != FILTER_ANISOTROPIC || function == Lod || function == Fetch)
{ {
sampleQuad(texture, c, u, v, w, offset, lod, face, secondLOD, function); c = sampleQuad(texture, u, v, w, offset, lod, face, secondLOD, function);
} }
else else
{ {
...@@ -751,7 +761,7 @@ namespace sw ...@@ -751,7 +761,7 @@ namespace sw
Do Do
{ {
sampleQuad(texture, c, u0, v0, w, offset, lod, face, secondLOD, function); c = sampleQuad(texture, u0, v0, w, offset, lod, face, secondLOD, function);
u0 += du; u0 += du;
v0 += dv; v0 += dv;
...@@ -770,22 +780,26 @@ namespace sw ...@@ -770,22 +780,26 @@ namespace sw
if(hasUnsignedTextureComponent(2)) c.z = cSum.z; else c.z = AddSat(cSum.z, cSum.z); if(hasUnsignedTextureComponent(2)) c.z = cSum.z; else c.z = AddSat(cSum.z, cSum.z);
if(hasUnsignedTextureComponent(3)) c.w = cSum.w; else c.w = AddSat(cSum.w, cSum.w); if(hasUnsignedTextureComponent(3)) c.w = cSum.w; else c.w = AddSat(cSum.w, cSum.w);
} }
return c;
} }
void SamplerCore::sampleQuad(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function) Vector4s SamplerCore::sampleQuad(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function)
{ {
if(state.textureType != TEXTURE_3D) if(state.textureType != TEXTURE_3D)
{ {
sampleQuad2D(texture, c, u, v, w, offset, lod, face, secondLOD, function); return sampleQuad2D(texture, u, v, w, offset, lod, face, secondLOD, function);
} }
else else
{ {
sample3D(texture, c, u, v, w, offset, lod, secondLOD, function); return sample3D(texture, u, v, w, offset, lod, secondLOD, function);
} }
} }
void SamplerCore::sampleQuad2D(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function) Vector4s SamplerCore::sampleQuad2D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function)
{ {
Vector4s c;
int componentCount = textureComponentCount(); int componentCount = textureComponentCount();
bool gather = state.textureFilter == FILTER_GATHER; bool gather = state.textureFilter == FILTER_GATHER;
...@@ -973,10 +987,14 @@ namespace sw ...@@ -973,10 +987,14 @@ namespace sw
c.w = c0.x; c.w = c0.x;
} }
} }
return c;
} }
void SamplerCore::sample3D(Pointer<Byte> &texture, Vector4s &c_, Float4 &u_, Float4 &v_, Float4 &w_, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function) Vector4s SamplerCore::sample3D(Pointer<Byte> &texture, Float4 &u_, Float4 &v_, Float4 &w_, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function)
{ {
Vector4s c_;
int componentCount = textureComponentCount(); int componentCount = textureComponentCount();
Pointer<Byte> mipmap; Pointer<Byte> mipmap;
...@@ -1094,22 +1112,22 @@ namespace sw ...@@ -1094,22 +1112,22 @@ namespace sw
if(componentCount >= 3) if(!hasUnsignedTextureComponent(2)) c_.z = AddSat(c_.z, c_.z); if(componentCount >= 3) if(!hasUnsignedTextureComponent(2)) c_.z = AddSat(c_.z, c_.z);
if(componentCount >= 4) if(!hasUnsignedTextureComponent(3)) c_.w = AddSat(c_.w, c_.w); if(componentCount >= 4) if(!hasUnsignedTextureComponent(3)) c_.w = AddSat(c_.w, c_.w);
} }
return c_;
} }
void SamplerCore::sampleFloatFilter(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function) Vector4f SamplerCore::sampleFloatFilter(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function)
{ {
sampleFloatAniso(texture, c, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, false, function); Vector4f c = sampleFloatAniso(texture, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, false, function);
if(function == Fetch) if(function == Fetch)
{ {
return; return c;
} }
if(state.mipmapFilter > MIPMAP_POINT) if(state.mipmapFilter > MIPMAP_POINT)
{ {
Vector4f cc; Vector4f cc = sampleFloatAniso(texture, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
sampleFloatAniso(texture, cc, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
Float4 lod4 = Float4(Frac(lod)); Float4 lod4 = Float4(Frac(lod));
...@@ -1174,13 +1192,17 @@ namespace sw ...@@ -1174,13 +1192,17 @@ namespace sw
c.z = As<Float4>((borderMask & As<Int4>(c.z)) | (~borderMask & *Pointer<Int4>(texture + OFFSET(Texture,borderColorF[2])))); c.z = As<Float4>((borderMask & As<Int4>(c.z)) | (~borderMask & *Pointer<Int4>(texture + OFFSET(Texture,borderColorF[2]))));
c.w = As<Float4>((borderMask & As<Int4>(c.w)) | (~borderMask & *Pointer<Int4>(texture + OFFSET(Texture,borderColorF[3])))); c.w = As<Float4>((borderMask & As<Int4>(c.w)) | (~borderMask & *Pointer<Int4>(texture + OFFSET(Texture,borderColorF[3]))));
} }
return c;
} }
void SamplerCore::sampleFloatAniso(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function) Vector4f SamplerCore::sampleFloatAniso(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function)
{ {
Vector4f c;
if(state.textureFilter != FILTER_ANISOTROPIC || function == Lod || function == Fetch) if(state.textureFilter != FILTER_ANISOTROPIC || function == Lod || function == Fetch)
{ {
sampleFloat(texture, c, u, v, w, offset, lod, face, secondLOD, function); c = sampleFloat(texture, u, v, w, offset, lod, face, secondLOD, function);
} }
else else
{ {
...@@ -1209,7 +1231,7 @@ namespace sw ...@@ -1209,7 +1231,7 @@ namespace sw
Do Do
{ {
sampleFloat(texture, c, u0, v0, w, offset, lod, face, secondLOD, function); c = sampleFloat(texture, u0, v0, w, offset, lod, face, secondLOD, function);
u0 += du; u0 += du;
v0 += dv; v0 += dv;
...@@ -1228,22 +1250,26 @@ namespace sw ...@@ -1228,22 +1250,26 @@ namespace sw
c.z = cSum.z; c.z = cSum.z;
c.w = cSum.w; c.w = cSum.w;
} }
return c;
} }
void SamplerCore::sampleFloat(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function) Vector4f SamplerCore::sampleFloat(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function)
{ {
if(state.textureType != TEXTURE_3D) if(state.textureType != TEXTURE_3D)
{ {
sampleFloat2D(texture, c, u, v, w, offset, lod, face, secondLOD, function); return sampleFloat2D(texture, u, v, w, offset, lod, face, secondLOD, function);
} }
else else
{ {
sampleFloat3D(texture, c, u, v, w, offset, lod, secondLOD, function); return sampleFloat3D(texture, u, v, w, offset, lod, secondLOD, function);
} }
} }
void SamplerCore::sampleFloat2D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function) Vector4f SamplerCore::sampleFloat2D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function)
{ {
Vector4f c;
int componentCount = textureComponentCount(); int componentCount = textureComponentCount();
bool gather = state.textureFilter == FILTER_GATHER; bool gather = state.textureFilter == FILTER_GATHER;
...@@ -1305,10 +1331,14 @@ namespace sw ...@@ -1305,10 +1331,14 @@ namespace sw
c.w = c0.x; c.w = c0.x;
} }
} }
return c;
} }
void SamplerCore::sampleFloat3D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function) Vector4f SamplerCore::sampleFloat3D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function)
{ {
Vector4f c;
int componentCount = textureComponentCount(); int componentCount = textureComponentCount();
Pointer<Byte> mipmap; Pointer<Byte> mipmap;
...@@ -1385,6 +1415,8 @@ namespace sw ...@@ -1385,6 +1415,8 @@ namespace sw
if(componentCount >= 3) c.z = c0.z + fw * (c4.z - c0.z); if(componentCount >= 3) c.z = c0.z + fw * (c4.z - c0.z);
if(componentCount >= 4) c.w = c0.w + fw * (c4.w - c0.w); if(componentCount >= 4) c.w = c0.w + fw * (c4.w - c0.w);
} }
return c;
} }
Float SamplerCore::log2sqrt(Float lod) Float SamplerCore::log2sqrt(Float lod)
...@@ -1639,7 +1671,7 @@ namespace sw ...@@ -1639,7 +1671,7 @@ namespace sw
Int4 tmp = Int4(As<UShort4>(uvw)); Int4 tmp = Int4(As<UShort4>(uvw));
tmp = tmp + As<Int4>(offset); tmp = tmp + As<Int4>(offset);
switch (mode) switch(mode)
{ {
case AddressingMode::ADDRESSING_WRAP: case AddressingMode::ADDRESSING_WRAP:
tmp = (tmp + whd * Int4(-MIN_PROGRAM_TEXEL_OFFSET)) % whd; tmp = (tmp + whd * Int4(-MIN_PROGRAM_TEXEL_OFFSET)) % whd;
...@@ -1690,13 +1722,16 @@ namespace sw ...@@ -1690,13 +1722,16 @@ namespace sw
{ {
wwww = MulHigh(As<UShort4>(wwww), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, depth))); wwww = MulHigh(As<UShort4>(wwww), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, depth)));
} }
if(hasOffset) if(hasOffset)
{ {
wwww = applyOffset(wwww, offset.z, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, depth))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeW); wwww = applyOffset(wwww, offset.z, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, depth))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeW);
} }
} }
UInt4 uv(As<UInt2>(uuuu), As<UInt2>(uuu2)); UInt4 uv(As<UInt2>(uuuu), As<UInt2>(uuu2));
uv += As<UInt4>(Int4(As<UShort4>(wwww))) * *Pointer<UInt4>(mipmap + OFFSET(Mipmap, sliceP)); uv += As<UInt4>(Int4(As<UShort4>(wwww))) * *Pointer<UInt4>(mipmap + OFFSET(Mipmap, sliceP));
index[0] = Extract(As<Int4>(uv), 0); index[0] = Extract(As<Int4>(uv), 0);
index[1] = Extract(As<Int4>(uv), 1); index[1] = Extract(As<Int4>(uv), 1);
index[2] = Extract(As<Int4>(uv), 2); index[2] = Extract(As<Int4>(uv), 2);
......
...@@ -49,26 +49,26 @@ namespace sw ...@@ -49,26 +49,26 @@ namespace sw
public: public:
SamplerCore(Pointer<Byte> &constants, 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); Vector4s sampleTexture(Pointer<Byte> &texture, 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); Vector4f sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
static void textureSize(Pointer<Byte> &mipmap, Vector4f &size, Float4 &lod); static Vector4f textureSize(Pointer<Byte> &mipmap, Float4 &lod);
private: 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); Vector4s sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function, bool fixed12);
void border(Short4 &mask, Float4 &coordinates); void border(Short4 &mask, Float4 &coordinates);
void border(Int4 &mask, Float4 &coordinates); void border(Int4 &mask, Float4 &coordinates);
Short4 offsetSample(Short4 &uvw, Pointer<Byte> &mipmap, int halfOffset, bool wrap, int count, Float &lod); Short4 offsetSample(Short4 &uvw, Pointer<Byte> &mipmap, int halfOffset, bool wrap, int count, Float &lod);
void sampleFilter(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function); Vector4s sampleFilter(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function);
void sampleAniso(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function); Vector4s sampleAniso(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function);
void sampleQuad(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function); Vector4s sampleQuad(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function);
void sampleQuad2D(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function); Vector4s sampleQuad2D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function);
void sample3D(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function); Vector4s sample3D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function);
void sampleFloatFilter(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function); Vector4f sampleFloatFilter(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], SamplerFunction function);
void sampleFloatAniso(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function); Vector4f sampleFloatAniso(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool secondLOD, SamplerFunction function);
void sampleFloat(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function); Vector4f sampleFloat(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function);
void sampleFloat2D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function); Vector4f sampleFloat2D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, Int face[4], bool secondLOD, SamplerFunction function);
void sampleFloat3D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function); Vector4f sampleFloat3D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function);
Float log2sqrt(Float lod); Float log2sqrt(Float lod);
void computeLod(Pointer<Byte> &texture, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &u, Float4 &v, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function); void computeLod(Pointer<Byte> &texture, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &u, Float4 &v, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function);
void computeLodCube(Pointer<Byte> &texture, Float &lod, Float4 &x, Float4 &y, Float4 &z, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function); void computeLodCube(Pointer<Byte> &texture, Float &lod, Float4 &x, Float4 &y, Float4 &z, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function);
...@@ -78,7 +78,6 @@ namespace sw ...@@ -78,7 +78,6 @@ namespace sw
void computeIndices(UInt index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, Vector4f &offset, const Pointer<Byte> &mipmap, SamplerFunction function); void computeIndices(UInt index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, Vector4f &offset, const Pointer<Byte> &mipmap, SamplerFunction function);
void computeIndices(UInt index[4], Int4& uuuu, Int4& vvvv, Int4& wwww, const Pointer<Byte> &mipmap, SamplerFunction function); void computeIndices(UInt index[4], Int4& uuuu, Int4& vvvv, Int4& wwww, const Pointer<Byte> &mipmap, SamplerFunction function);
Vector4s sampleTexel(Short4 &u, Short4 &v, Short4 &s, Vector4f &offset, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function); Vector4s sampleTexel(Short4 &u, Short4 &v, Short4 &s, Vector4f &offset, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
Vector4f sampleTexel(Short4 &u, Short4 &v, Short4 &s, Vector4f &offset, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
Vector4s sampleTexel(UInt index[4], Pointer<Byte> buffer[4]); Vector4s sampleTexel(UInt index[4], Pointer<Byte> buffer[4]);
Vector4f sampleTexel(Int4 &u, Int4 &v, Int4 &s, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function); Vector4f sampleTexel(Int4 &u, Int4 &v, Int4 &s, Float4 &z, Pointer<Byte> &mipmap, Pointer<Byte> buffer[4], SamplerFunction function);
void selectMipmap(Pointer<Byte> &texture, Pointer<Byte> buffer[4], Pointer<Byte> &mipmap, Float &lod, Int face[4], bool secondLOD); void selectMipmap(Pointer<Byte> &texture, Pointer<Byte> buffer[4], Pointer<Byte> &mipmap, Float &lod, Int face[4], bool secondLOD);
......
...@@ -1558,60 +1558,59 @@ namespace sw ...@@ -1558,60 +1558,59 @@ namespace sw
void VertexProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1) void VertexProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src &src1)
{ {
sampleTexture(dst, src1, src0, a0, a0, src0, Lod); dst = sampleTexture(src1, src0, a0, a0, src0, Lod);
} }
void VertexProgram::TEX(Vector4f &dst, Vector4f &src0, const Src &src1) void VertexProgram::TEX(Vector4f &dst, Vector4f &src0, const Src &src1)
{ {
src0.w = Float(0.0f); src0.w = Float(0.0f);
sampleTexture(dst, src1, src0, a0, a0, src0, Lod); dst = sampleTexture(src1, src0, a0, a0, src0, Lod);
} }
void VertexProgram::TEXOFFSET(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2) void VertexProgram::TEXOFFSET(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2)
{ {
src0.w = Float(0.0f); src0.w = Float(0.0f);
sampleTexture(dst, src1, src0, a0, a0, src2, {Lod, Offset}); dst = sampleTexture(src1, src0, a0, a0, src2, {Lod, Offset});
} }
void VertexProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &offset) void VertexProgram::TEXLDL(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &offset)
{ {
sampleTexture(dst, src1, src0, a0, a0, offset, {Lod, Offset}); dst = sampleTexture(src1, src0, a0, a0, offset, {Lod, Offset});
} }
void VertexProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1) void VertexProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1)
{ {
sampleTexture(dst, src1, src0, src0, src0, src0, Fetch); dst = sampleTexture(src1, src0, src0, src0, src0, Fetch);
} }
void VertexProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &offset) void VertexProgram::TEXELFETCH(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &offset)
{ {
sampleTexture(dst, src1, src0, src0, src0, offset, {Fetch, Offset}); dst = sampleTexture(src1, src0, src0, src0, offset, {Fetch, Offset});
} }
void VertexProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3) void VertexProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3)
{ {
sampleTexture(dst, src1, src0, src2, src3, src0, Grad); dst = sampleTexture(src1, src0, src2, src3, src0, Grad);
} }
void VertexProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3, Vector4f &offset) void VertexProgram::TEXGRAD(Vector4f &dst, Vector4f &src0, const Src& src1, Vector4f &src2, Vector4f &src3, Vector4f &offset)
{ {
sampleTexture(dst, src1, src0, src2, src3, offset, {Grad, Offset}); dst = sampleTexture(src1, src0, src2, src3, offset, {Grad, Offset});
} }
void VertexProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1) void VertexProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1)
{ {
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[16]) + src1.index * sizeof(Texture); Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[16]) + src1.index * sizeof(Texture);
SamplerCore::textureSize(texture, dst, lod); dst = SamplerCore::textureSize(texture, lod);
} }
void VertexProgram::sampleTexture(Vector4f &c, const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function) Vector4f VertexProgram::sampleTexture(const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
{ {
Vector4f tmp; Vector4f tmp;
if(s.type == Shader::PARAMETER_SAMPLER && s.rel.type == Shader::PARAMETER_VOID) 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); tmp = sampleTexture(s.index, uvwq, 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 else
{ {
...@@ -1623,17 +1622,25 @@ namespace sw ...@@ -1623,17 +1622,25 @@ namespace sw
{ {
If(index == i) If(index == i)
{ {
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + i * sizeof(Texture); tmp = sampleTexture(i, uvwq, 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 // FIXME: When the sampler states are the same, we could use one sampler and just index the texture
} }
} }
} }
} }
Vector4f c;
c.x = tmp[(s.swizzle >> 0) & 0x3]; c.x = tmp[(s.swizzle >> 0) & 0x3];
c.y = tmp[(s.swizzle >> 2) & 0x3]; c.y = tmp[(s.swizzle >> 2) & 0x3];
c.z = tmp[(s.swizzle >> 4) & 0x3]; c.z = tmp[(s.swizzle >> 4) & 0x3];
c.w = tmp[(s.swizzle >> 6) & 0x3]; c.w = tmp[(s.swizzle >> 6) & 0x3];
return c;
}
Vector4f VertexProgram::sampleTexture(int sampler, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
{
Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + sampler * sizeof(Texture);
return SamplerCore(constants, state.sampler[sampler]).sampleTexture(texture, uvwq.x, uvwq.y, uvwq.z, uvwq.w, dsx, dsy, offset, function);
} }
} }
...@@ -117,7 +117,8 @@ namespace sw ...@@ -117,7 +117,8 @@ namespace sw
void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, Vector4f &src4); void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, Vector4f &src4);
void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&); void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&);
void sampleTexture(Vector4f &c, const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function); Vector4f sampleTexture(const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
Vector4f sampleTexture(int sampler, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
int ifDepth; int ifDepth;
int loopRepDepth; int loopRepDepth;
......
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