Commit e396a499 by Nicolas Capens Committed by Nicolas Capens

Fix initializing LOD for 3D sampling.

The LOD value was not being computed for 3D texture sampling when no mipmapping is done. We still need the LOD in case the minification and magnification filters differ. Change-Id: If32d7aaf8a92ace33bcc6ca6f0b60fe33c7e771b Reviewed-on: https://swiftshader-review.googlesource.com/15588Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 5d507bc5
...@@ -2057,15 +2057,12 @@ namespace es2sw ...@@ -2057,15 +2057,12 @@ namespace es2sw
case GL_NEAREST: case GL_NEAREST:
case GL_LINEAR: case GL_LINEAR:
return sw::MIPMAP_NONE; return sw::MIPMAP_NONE;
break;
case GL_NEAREST_MIPMAP_NEAREST: case GL_NEAREST_MIPMAP_NEAREST:
case GL_LINEAR_MIPMAP_NEAREST: case GL_LINEAR_MIPMAP_NEAREST:
return sw::MIPMAP_POINT; return sw::MIPMAP_POINT;
break;
case GL_NEAREST_MIPMAP_LINEAR: case GL_NEAREST_MIPMAP_LINEAR:
case GL_LINEAR_MIPMAP_LINEAR: case GL_LINEAR_MIPMAP_LINEAR:
return sw::MIPMAP_LINEAR; return sw::MIPMAP_LINEAR;
break;
default: default:
UNREACHABLE(minFilter); UNREACHABLE(minFilter);
return sw::MIPMAP_NONE; return sw::MIPMAP_NONE;
...@@ -2079,12 +2076,13 @@ namespace es2sw ...@@ -2079,12 +2076,13 @@ namespace es2sw
return sw::FILTER_ANISOTROPIC; return sw::FILTER_ANISOTROPIC;
} }
sw::FilterType magFilterType = sw::FILTER_POINT;
switch(magFilter) switch(magFilter)
{ {
case GL_NEAREST: magFilterType = sw::FILTER_POINT; break; case GL_NEAREST:
case GL_LINEAR: magFilterType = sw::FILTER_LINEAR; break; case GL_LINEAR:
default: UNREACHABLE(magFilter); break;
default:
UNREACHABLE(magFilter);
} }
switch(minFilter) switch(minFilter)
...@@ -2092,14 +2090,14 @@ namespace es2sw ...@@ -2092,14 +2090,14 @@ namespace es2sw
case GL_NEAREST: case GL_NEAREST:
case GL_NEAREST_MIPMAP_NEAREST: case GL_NEAREST_MIPMAP_NEAREST:
case GL_NEAREST_MIPMAP_LINEAR: case GL_NEAREST_MIPMAP_LINEAR:
return (magFilterType == sw::FILTER_POINT) ? sw::FILTER_POINT : sw::FILTER_MIN_POINT_MAG_LINEAR; return (magFilter == GL_NEAREST) ? sw::FILTER_POINT : sw::FILTER_MIN_POINT_MAG_LINEAR;
case GL_LINEAR: case GL_LINEAR:
case GL_LINEAR_MIPMAP_NEAREST: case GL_LINEAR_MIPMAP_NEAREST:
case GL_LINEAR_MIPMAP_LINEAR: case GL_LINEAR_MIPMAP_LINEAR:
return (magFilterType == sw::FILTER_POINT) ? sw::FILTER_MIN_LINEAR_MAG_POINT : sw::FILTER_LINEAR; return (magFilter == GL_NEAREST) ? sw::FILTER_MIN_LINEAR_MAG_POINT : sw::FILTER_LINEAR;
default: default:
UNREACHABLE(minFilter); UNREACHABLE(minFilter);
return (magFilterType == sw::FILTER_POINT) ? sw::FILTER_POINT : sw::FILTER_MIN_POINT_MAG_LINEAR; return sw::FILTER_POINT;
} }
} }
......
...@@ -573,7 +573,7 @@ namespace sw ...@@ -573,7 +573,7 @@ namespace sw
return c; return c;
} }
if(state.mipmapFilter > MIPMAP_POINT) if(state.mipmapFilter == MIPMAP_LINEAR)
{ {
Vector4s cc = sampleAniso(texture, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, true, function); Vector4s cc = sampleAniso(texture, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
...@@ -1066,7 +1066,7 @@ namespace sw ...@@ -1066,7 +1066,7 @@ namespace sw
return c; return c;
} }
if(state.mipmapFilter > MIPMAP_POINT) if(state.mipmapFilter == MIPMAP_LINEAR)
{ {
Vector4f cc = sampleFloatAniso(texture, u, v, w, q, offset, lod, anisotropy, uDelta, vDelta, face, true, function); Vector4f cc = sampleFloatAniso(texture, u, v, w, q, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
...@@ -1518,67 +1518,61 @@ namespace sw ...@@ -1518,67 +1518,61 @@ namespace sw
void SamplerCore::computeLod3D(Pointer<Byte> &texture, Float &lod, Float4 &uuuu, Float4 &vvvv, Float4 &wwww, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function) void SamplerCore::computeLod3D(Pointer<Byte> &texture, Float &lod, Float4 &uuuu, Float4 &vvvv, Float4 &wwww, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function)
{ {
if(state.mipmapFilter == MIPMAP_NONE) if(function != Lod && function != Fetch)
{
}
else // Point and linear filter
{ {
if(function != Lod && function != Fetch) Float4 dudxy, dvdxy, dsdxy;
{
Float4 dudxy, dvdxy, dsdxy;
if(function != Grad) // Implicit if(function != Grad) // Implicit
{ {
dudxy = uuuu - uuuu.xxxx; dudxy = uuuu - uuuu.xxxx;
dvdxy = vvvv - vvvv.xxxx; dvdxy = vvvv - vvvv.xxxx;
dsdxy = wwww - wwww.xxxx; dsdxy = wwww - wwww.xxxx;
} }
else else
{ {
dudxy = Float4(dsx.x.xx, dsy.x.xx); dudxy = Float4(dsx.x.xx, dsy.x.xx);
dvdxy = Float4(dsx.y.xx, dsy.y.xx); dvdxy = Float4(dsx.y.xx, dsy.y.xx);
dsdxy = Float4(dsx.z.xx, dsy.z.xx); dsdxy = Float4(dsx.z.xx, dsy.z.xx);
} }
// Scale by texture dimensions and global LOD. // Scale by texture dimensions and global LOD.
dudxy *= *Pointer<Float4>(texture + OFFSET(Texture,widthLOD)); dudxy *= *Pointer<Float4>(texture + OFFSET(Texture,widthLOD));
dvdxy *= *Pointer<Float4>(texture + OFFSET(Texture,heightLOD)); dvdxy *= *Pointer<Float4>(texture + OFFSET(Texture,heightLOD));
dsdxy *= *Pointer<Float4>(texture + OFFSET(Texture,depthLOD)); dsdxy *= *Pointer<Float4>(texture + OFFSET(Texture,depthLOD));
dudxy *= dudxy; dudxy *= dudxy;
dvdxy *= dvdxy; dvdxy *= dvdxy;
dsdxy *= dsdxy; dsdxy *= dsdxy;
dudxy += dvdxy; dudxy += dvdxy;
dudxy += dsdxy; dudxy += dsdxy;
lod = Max(Float(dudxy.y), Float(dudxy.z)); // FIXME: Max(dudxy.y, dudxy.z); lod = Max(Float(dudxy.y), Float(dudxy.z)); // FIXME: Max(dudxy.y, dudxy.z);
lod = log2sqrt(lod); // log2(sqrt(lod)) lod = log2sqrt(lod); // log2(sqrt(lod))
if(function == Bias) if(function == Bias)
{
lod += lodBias;
}
}
else if(function == Lod)
{
lod = lodBias;
}
else if(function == Fetch)
{
// TODO: Eliminate int-float-int conversion.
lod = Float(As<Int>(lodBias));
}
else if(function == Base)
{ {
lod = Float(0); lod += lodBias;
} }
else assert(false);
lod = Max(lod, *Pointer<Float>(texture + OFFSET(Texture, minLod)));
lod = Min(lod, *Pointer<Float>(texture + OFFSET(Texture, maxLod)));
} }
else if(function == Lod)
{
lod = lodBias;
}
else if(function == Fetch)
{
// TODO: Eliminate int-float-int conversion.
lod = Float(As<Int>(lodBias));
}
else if(function == Base)
{
lod = Float(0);
}
else assert(false);
lod = Max(lod, *Pointer<Float>(texture + OFFSET(Texture, minLod)));
lod = Min(lod, *Pointer<Float>(texture + OFFSET(Texture, maxLod)));
} }
void SamplerCore::cubeFace(Int face[4], Float4 &U, Float4 &V, Float4 &x, Float4 &y, Float4 &z, Float4 &M) void SamplerCore::cubeFace(Int face[4], Float4 &U, Float4 &V, Float4 &x, Float4 &y, Float4 &z, Float4 &M)
...@@ -2240,7 +2234,7 @@ namespace sw ...@@ -2240,7 +2234,7 @@ namespace sw
void SamplerCore::selectMipmap(Pointer<Byte> &texture, Pointer<Byte> buffer[4], Pointer<Byte> &mipmap, Float &lod, Int face[4], bool secondLOD) void SamplerCore::selectMipmap(Pointer<Byte> &texture, Pointer<Byte> buffer[4], Pointer<Byte> &mipmap, Float &lod, Int face[4], bool secondLOD)
{ {
if(state.mipmapFilter < MIPMAP_POINT) if(state.mipmapFilter == MIPMAP_NONE)
{ {
mipmap = texture + OFFSET(Texture,mipmap[0]); mipmap = texture + OFFSET(Texture,mipmap[0]);
} }
...@@ -2252,7 +2246,7 @@ namespace sw ...@@ -2252,7 +2246,7 @@ namespace sw
{ {
ilod = RoundInt(lod); ilod = RoundInt(lod);
} }
else // Linear else // MIPMAP_LINEAR
{ {
ilod = Int(lod); ilod = Int(lod);
} }
......
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