Commit b5d5f478 by Nicolas Capens Committed by Nicolas Capens

Refactor common sampler code

Bug: b/129523279 Change-Id: Id77a2168c11a66dddebf893d1527647b30584832 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29773Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 9e73510a
......@@ -40,9 +40,9 @@ namespace sw
{
}
Vector4s SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Float4 &bias, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
Vector4f SamplerCore::sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Float4 &bias, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
{
Vector4s c;
Vector4f c;
#if PERF_PROFILE
AddAtomic(Pointer<Long>(&profiler.texOperations), 4);
......@@ -82,57 +82,12 @@ namespace sw
computeLod3D(texture, lod, uuuu, vvvv, wwww, bias.x, dsx, dsy, function);
}
return sampleFilter(texture, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function);
}
Vector4f SamplerCore::sampleTextureF(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Float4 &bias, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function)
{
Vector4f c;
#if PERF_PROFILE
AddAtomic(Pointer<Long>(&profiler.texOperations), 4);
if(state.compressedFormat)
{
AddAtomic(Pointer<Long>(&profiler.compressedTex), 4);
}
#endif
// FIXME: YUV is not supported by the floating point path
bool forceFloatFiltering = state.highPrecisionFiltering && !hasYuvFormat() && (state.textureFilter != FILTER_POINT);
bool seamlessCube = (state.addressingModeU == ADDRESSING_SEAMLESS);
bool rectangleTexture = (state.textureType == TEXTURE_RECTANGLE);
if(hasFloatTexture() || hasUnnormalizedIntegerTexture() || forceFloatFiltering || seamlessCube || rectangleTexture) // FIXME: Mostly identical to integer sampling
{
Float4 uuuu = u;
Float4 vvvv = v;
Float4 wwww = w;
Float4 qqqq = q;
Int face[4];
Float lod;
Float anisotropy;
Float4 uDelta;
Float4 vDelta;
if(state.textureType != TEXTURE_3D)
{
if(state.textureType != TEXTURE_CUBE)
{
computeLod(texture, lod, anisotropy, uDelta, vDelta, uuuu, vvvv, bias.x, dsx, dsy, function);
}
else
{
Float4 M;
cubeFace(face, uuuu, vvvv, u, v, w, M);
computeLodCube(texture, lod, u, v, w, bias.x, dsx, dsy, M, function);
}
}
else
{
computeLod3D(texture, lod, uuuu, vvvv, wwww, bias.x, dsx, dsy, function);
}
c = sampleFloatFilter(texture, uuuu, vvvv, wwww, qqqq, offset, lod, anisotropy, uDelta, vDelta, face, function);
if(!hasFloatTexture() && !hasUnnormalizedIntegerTexture())
......@@ -161,7 +116,7 @@ namespace sw
}
else
{
Vector4s cs = sampleTexture(texture, u, v, w, q, bias, dsx, dsy, offset, function);
Vector4s cs = sampleFilter(texture, uuuu, vvvv, wwww, offset, lod, anisotropy, uDelta, vDelta, face, function);
if(state.textureFormat == VK_FORMAT_R5G6B5_UNORM_PACK16)
{
......
......@@ -50,11 +50,9 @@ namespace sw
public:
SamplerCore(Pointer<Byte> &constants, const Sampler::State &state);
Vector4f sampleTextureF(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Float4 &bias, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
Vector4f sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Float4 &bias, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
private:
Vector4s sampleTexture(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Float4 &bias, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
void border(Short4 &mask, Float4 &coordinates);
void border(Int4 &mask, Float4 &coordinates);
Short4 offsetSample(Short4 &uvw, Pointer<Byte> &mipmap, int halfOffset, bool wrap, int count, Float &lod);
......
......@@ -108,25 +108,13 @@ void SpirvShader::emitSamplerFunction(
Vector4f offset; // TODO(b/129523279)
SamplerFunction samplerFunction = { Implicit, None }; // ASSERT(insn.wordCount() == 5); // TODO(b/129523279)
Vector4f sample = s.sampleTextureF(texture, u, v, w, q, bias, dsx, dsy, offset, samplerFunction);
Vector4f sample = s.sampleTexture(texture, u, v, w, q, bias, dsx, dsy, offset, samplerFunction);
if(!vk::Format(imageView->getFormat()).isNonNormalizedInteger())
{
Pointer<SIMD::Float> rgba = out;
rgba[0] = sample.x;
rgba[1] = sample.y;
rgba[2] = sample.z;
rgba[3] = sample.w;
}
else
{
// TODO(b/129523279): Add a Sampler::sampleTextureI() method.
Pointer<SIMD::Int> rgba = out;
rgba[0] = As<SIMD::Int>(sample.x * SIMD::Float(0xFF));
rgba[1] = As<SIMD::Int>(sample.y * SIMD::Float(0xFF));
rgba[2] = As<SIMD::Int>(sample.z * SIMD::Float(0xFF));
rgba[3] = As<SIMD::Int>(sample.w * SIMD::Float(0xFF));
}
Pointer<SIMD::Float> rgba = out;
rgba[0] = sample.x;
rgba[1] = sample.y;
rgba[2] = sample.z;
rgba[3] = sample.w;
}
sw::FilterType SpirvShader::convertFilterMode(const vk::Sampler *sampler)
......
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