Commit 1e7120e4 by Nicolas Capens Committed by Nicolas Capens

Use sampler data from sampler descriptor

Bug: b/129523279 Test: dEQP-VK.glsl.texture_functions.* Test: dEQP-VK.spirv_assembly.instruction.graphics.image_sampler.* Change-Id: I4c02a36b35a25772e233346266ff6177a9186b9e Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/30249 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 97da7826
......@@ -212,7 +212,6 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
<ClCompile Include="$(SolutionDir)src\Device\Renderer.cpp" />
<ClInclude Include="$(SolutionDir)src\Device\Renderer.hpp" />
<ClInclude Include="$(SolutionDir)src\Device\RoutineCache.hpp" />
<ClCompile Include="$(SolutionDir)src\Device\Sampler.cpp" />
<ClInclude Include="$(SolutionDir)src\Device\Sampler.hpp" />
<ClCompile Include="$(SolutionDir)src\Device\SetupProcessor.cpp" />
<ClInclude Include="$(SolutionDir)src\Device\SetupProcessor.hpp" />
......
......@@ -37,9 +37,6 @@
<ClCompile Include="$(SolutionDir)src\Device\Renderer.cpp">
<Filter>src\Device</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)src\Device\Sampler.cpp">
<Filter>src\Device</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)src\Device\SetupProcessor.cpp">
<Filter>src\Device</Filter>
</ClCompile>
......
......@@ -34,7 +34,7 @@ namespace vk
namespace sw
{
class Sampler;
struct Sampler;
class PixelShader;
class VertexShader;
class SpirvShader;
......
......@@ -65,7 +65,7 @@ namespace sw
bool frontFaceCCW;
VkFormat depthFormat;
Sampler::State sampler[TEXTURE_IMAGE_UNITS];
Sampler sampler[TEXTURE_IMAGE_UNITS];
};
struct State : States
......
......@@ -1509,21 +1509,6 @@ namespace sw
PixelProcessor::setRoutineCacheSize(configuration.pixelRoutineCacheSize);
SetupProcessor::setRoutineCacheSize(configuration.setupRoutineCacheSize);
switch(configuration.textureSampleQuality)
{
case 0: Sampler::setFilterQuality(FILTER_POINT); break;
case 1: Sampler::setFilterQuality(FILTER_LINEAR); break;
case 2: Sampler::setFilterQuality(FILTER_ANISOTROPIC); break;
default: Sampler::setFilterQuality(FILTER_ANISOTROPIC); break;
}
switch(configuration.mipmapQuality)
{
case 0: Sampler::setMipmapQuality(MIPMAP_POINT); break;
case 1: Sampler::setMipmapQuality(MIPMAP_LINEAR); break;
default: Sampler::setMipmapQuality(MIPMAP_LINEAR); break;
}
setPerspectiveCorrection(configuration.perspectiveCorrection);
switch(configuration.transcendentalPrecision)
......
......@@ -50,14 +50,10 @@ namespace sw
{
Mipmap mipmap[MIPMAP_LEVELS];
float4 widthHeightLOD;
float4 widthLOD;
float4 heightLOD;
float4 depthLOD;
float maxAnisotropy; // FIXME(b/129523279): Part of Vulkan sampler.
float minLod; // FIXME(b/129523279): Part of Vulkan sampler.
float maxLod; // FIXME(b/129523279): Part of Vulkan sampler.
float4 widthWidthHeightHeight;
float4 width;
float4 height;
float4 depth;
};
enum SamplerType
......@@ -143,91 +139,24 @@ namespace sw
SWIZZLE_LAST = SWIZZLE_ONE
};
class Sampler
struct Sampler
{
public:
struct State
{
State();
TextureType textureType;
vk::Format textureFormat;
FilterType textureFilter;
AddressingMode addressingModeU;
AddressingMode addressingModeV;
AddressingMode addressingModeW;
MipmapType mipmapFilter;
VkComponentMapping swizzle;
bool highPrecisionFiltering;
CompareFunc compare;
VkBorderColor border;
#if PERF_PROFILE
bool compressedFormat;
#endif
};
Sampler();
~Sampler();
State samplerState() const;
void setTextureLevel(int face, int level, vk::Image *image, TextureType type);
void setTextureFilter(FilterType textureFilter);
void setMipmapFilter(MipmapType mipmapFilter);
void setGatherEnable(bool enable);
void setAddressingModeU(AddressingMode addressingMode);
void setAddressingModeV(AddressingMode addressingMode);
void setAddressingModeW(AddressingMode addressingMode);
void setMaxAnisotropy(float maxAnisotropy);
void setHighPrecisionFiltering(bool highPrecisionFiltering);
void setCompareFunc(CompareFunc compare);
void setMinLod(float minLod);
void setMaxLod(float maxLod);
static void setFilterQuality(FilterType maximumFilterQuality);
static void setMipmapQuality(MipmapType maximumFilterQuality);
void setMipmapLOD(float lod);
bool hasTexture() const;
bool hasUnsignedTexture() const;
bool hasCubeTexture() const;
bool hasVolumeTexture() const;
const Texture &getTextureData();
private:
MipmapType mipmapFilter() const;
TextureType getTextureType() const;
FilterType getTextureFilter() const;
AddressingMode getAddressingModeU() const;
AddressingMode getAddressingModeV() const;
AddressingMode getAddressingModeW() const;
CompareFunc getCompareFunc() const;
vk::Format textureFormat;
TextureType textureType;
vk::Format textureFormat;
FilterType textureFilter;
AddressingMode addressingModeU;
AddressingMode addressingModeV;
AddressingMode addressingModeW;
MipmapType mipmapFilterState;
MipmapType mipmapFilter;
bool sRGB;
bool gather;
bool highPrecisionFiltering;
int border;
VkComponentMapping swizzle;
bool highPrecisionFiltering;
CompareFunc compare;
VkBorderColor border;
Texture texture;
float exp2LOD;
static FilterType maximumTextureFilterQuality;
static MipmapType maximumMipmapFilterQuality;
#if PERF_PROFILE
bool compressedFormat;
#endif
};
}
......
......@@ -53,7 +53,7 @@ namespace sw
bool textureSampling : 1; // TODO: Eliminate by querying shader.
unsigned char verticesPerPrimitive : 2; // 1 (points), 2 (lines) or 3 (triangles)
Sampler::State sampler[VERTEX_TEXTURE_IMAGE_UNITS];
Sampler sampler[VERTEX_TEXTURE_IMAGE_UNITS];
struct Input
{
......
......@@ -47,7 +47,7 @@ namespace
namespace sw
{
SamplerCore::SamplerCore(Pointer<Byte> &constants, const Sampler::State &state) : constants(constants), state(state)
SamplerCore::SamplerCore(Pointer<Byte> &constants, const Sampler &state) : constants(constants), state(state)
{
}
......@@ -79,18 +79,18 @@ namespace sw
{
if(state.textureType != TEXTURE_CUBE)
{
computeLod(texture, lod, anisotropy, uDelta, vDelta, uuuu, vvvv, lodOrBias.x, dsx, dsy, function);
computeLod(texture, sampler, lod, anisotropy, uDelta, vDelta, uuuu, vvvv, lodOrBias.x, dsx, dsy, function);
}
else
{
Float4 M;
cubeFace(face, uuuu, vvvv, u, v, w, M);
computeLodCube(texture, lod, u, v, w, lodOrBias.x, dsx, dsy, M, function);
computeLodCube(texture, sampler, lod, u, v, w, lodOrBias.x, dsx, dsy, M, function);
}
}
else
{
computeLod3D(texture, lod, uuuu, vvvv, wwww, lodOrBias.x, dsx, dsy, function);
computeLod3D(texture, sampler, lod, uuuu, vvvv, wwww, lodOrBias.x, dsx, dsy, function);
}
// FIXME: YUV is not supported by the floating point path
......@@ -1154,7 +1154,7 @@ namespace sw
return lod;
}
void SamplerCore::computeLod(Pointer<Byte> &texture, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &uuuu, Float4 &vvvv, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function)
void SamplerCore::computeLod(Pointer<Byte> &texture, Pointer<Byte> &sampler, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &uuuu, Float4 &vvvv, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function)
{
if(function != Lod && function != Fetch)
{
......@@ -1172,8 +1172,8 @@ namespace sw
duvdxy = Float4(dudxy.xz, dvdxy.xz);
}
// Scale by texture dimensions and sampler LOD bias.
Float4 dUVdxy = duvdxy * *Pointer<Float4>(texture + OFFSET(Texture,widthHeightLOD));
// Scale by texture dimensions.
Float4 dUVdxy = duvdxy * *Pointer<Float4>(texture + OFFSET(Texture, widthWidthHeightHeight));
Float4 dUV2dxy = dUVdxy * dUVdxy;
Float4 dUV2 = dUV2dxy.xy + dUV2dxy.zw;
......@@ -1194,7 +1194,7 @@ namespace sw
vDelta = As<Float4>((As<Int4>(dvdx) & mask) | ((As<Int4>(dvdy) & ~mask)));
anisotropy = lod * Rcp_pp(det);
anisotropy = Min(anisotropy, *Pointer<Float>(texture + OFFSET(Texture,maxAnisotropy)));
anisotropy = Min(anisotropy, *Pointer<Float>(sampler + OFFSET(vk::Sampler,maxAnisotropy)));
lod *= Rcp_pp(anisotropy * anisotropy);
}
......@@ -1221,11 +1221,11 @@ namespace sw
}
else assert(false);
lod = Max(lod, *Pointer<Float>(texture + OFFSET(Texture, minLod)));
lod = Min(lod, *Pointer<Float>(texture + OFFSET(Texture, maxLod)));
lod = Max(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, minLod)));
lod = Min(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, maxLod)));
}
void SamplerCore::computeLodCube(Pointer<Byte> &texture, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, Float4 &M, SamplerFunction function)
void SamplerCore::computeLodCube(Pointer<Byte> &texture, Pointer<Byte> &sampler, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, Float4 &M, SamplerFunction function)
{
if(function != Lod && function != Fetch)
{
......@@ -1263,7 +1263,7 @@ namespace sw
lod = Max(Float(dudxy.y), Float(dudxy.z)); // FIXME: Max(dudxy.y, dudxy.z);
// Scale by texture dimension and global LOD.
lod *= *Pointer<Float>(texture + OFFSET(Texture,widthLOD));
lod *= *Pointer<Float>(texture + OFFSET(Texture,width));
lod = log2(lod);
......@@ -1287,11 +1287,11 @@ namespace sw
}
else assert(false);
lod = Max(lod, *Pointer<Float>(texture + OFFSET(Texture, minLod)));
lod = Min(lod, *Pointer<Float>(texture + OFFSET(Texture, maxLod)));
lod = Max(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, minLod)));
lod = Min(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, maxLod)));
}
void SamplerCore::computeLod3D(Pointer<Byte> &texture, Float &lod, Float4 &uuuu, Float4 &vvvv, Float4 &wwww, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function)
void SamplerCore::computeLod3D(Pointer<Byte> &texture, Pointer<Byte> &sampler, Float &lod, Float4 &uuuu, Float4 &vvvv, Float4 &wwww, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function)
{
if(function != Lod && function != Fetch)
{
......@@ -1311,9 +1311,9 @@ namespace sw
}
// Scale by texture dimensions and global LOD.
dudxy *= *Pointer<Float4>(texture + OFFSET(Texture,widthLOD));
dvdxy *= *Pointer<Float4>(texture + OFFSET(Texture,heightLOD));
dsdxy *= *Pointer<Float4>(texture + OFFSET(Texture,depthLOD));
dudxy *= *Pointer<Float4>(texture + OFFSET(Texture, width));
dvdxy *= *Pointer<Float4>(texture + OFFSET(Texture, height));
dsdxy *= *Pointer<Float4>(texture + OFFSET(Texture, depth));
dudxy *= dudxy;
dvdxy *= dvdxy;
......@@ -1346,8 +1346,8 @@ namespace sw
}
else assert(false);
lod = Max(lod, *Pointer<Float>(texture + OFFSET(Texture, minLod)));
lod = Min(lod, *Pointer<Float>(texture + OFFSET(Texture, maxLod)));
lod = Max(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, minLod)));
lod = Min(lod, *Pointer<Float>(sampler + OFFSET(vk::Sampler, maxLod)));
}
void SamplerCore::cubeFace(Int face[4], Float4 &U, Float4 &V, Float4 &x, Float4 &y, Float4 &z, Float4 &M)
......
......@@ -58,7 +58,7 @@ namespace sw
class SamplerCore
{
public:
SamplerCore(Pointer<Byte> &constants, const Sampler::State &state);
SamplerCore(Pointer<Byte> &constants, const Sampler &state);
Vector4f sampleTexture(Pointer<Byte> &texture, Pointer<Byte> &sampler, Float4 &u, Float4 &v, Float4 &w, Float4 &q, Float4 &lodOrBias, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
......@@ -78,9 +78,9 @@ namespace sw
Vector4f sampleFloat3D(Pointer<Byte> &texture, Float4 &u, Float4 &v, Float4 &w, Vector4f &offset, Float &lod, bool secondLOD, SamplerFunction function);
Float log2sqrt(Float lod);
Float log2(Float lod);
void computeLod(Pointer<Byte> &texture, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &u, Float4 &v, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function);
void computeLodCube(Pointer<Byte> &texture, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, Float4 &M, SamplerFunction function);
void computeLod3D(Pointer<Byte> &texture, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function);
void computeLod(Pointer<Byte> &texture, Pointer<Byte> &sampler, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Float4 &u, Float4 &v, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function);
void computeLodCube(Pointer<Byte> &texture, Pointer<Byte> &sampler, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, Float4 &M, SamplerFunction function);
void computeLod3D(Pointer<Byte> &texture, Pointer<Byte> &sampler, Float &lod, Float4 &u, Float4 &v, Float4 &w, const Float &lodOrBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function);
void cubeFace(Int face[4], Float4 &U, Float4 &V, Float4 &x, Float4 &y, Float4 &z, Float4 &M);
Short4 applyOffset(Short4 &uvw, Float4 &offset, const Int4 &whd, AddressingMode mode);
void computeIndices(UInt index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, Vector4f &offset, const Pointer<Byte> &mipmap, SamplerFunction function);
......@@ -110,7 +110,7 @@ namespace sw
bool isRGBComponent(int component) const;
Pointer<Byte> &constants;
const Sampler::State &state;
const Sampler &state;
};
}
......
......@@ -928,7 +928,7 @@ namespace sw
std::pair<SIMD::Float, SIMD::Int> Frexp(RValue<SIMD::Float> val) const;
static ImageSampler *getImageSampler(uint32_t instruction, const vk::ImageView *imageView, const vk::Sampler *sampler);
static ImageSampler *emitSamplerFunction(ImageInstruction instruction, const Sampler::State &samplerState);
static ImageSampler *emitSamplerFunction(ImageInstruction instruction, const Sampler &samplerState);
// TODO(b/129523279): Eliminate conversion and use vk::Sampler members directly.
static sw::TextureType convertTextureType(VkImageViewType imageViewType);
......
......@@ -50,7 +50,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t instruction, co
auto it = cache.find(key);
if (it != cache.end()) { return it->second; }
Sampler::State samplerState = {};
Sampler samplerState = {};
samplerState.textureType = convertTextureType(imageView->getType());
samplerState.textureFormat = imageView->getFormat();
samplerState.textureFilter = convertFilterMode(sampler);
......@@ -78,7 +78,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t instruction, co
return fptr;
}
SpirvShader::ImageSampler *SpirvShader::emitSamplerFunction(ImageInstruction instruction, const Sampler::State &samplerState)
SpirvShader::ImageSampler *SpirvShader::emitSamplerFunction(ImageInstruction instruction, const Sampler &samplerState)
{
// TODO(b/129523279): Hold a separate mutex lock for the sampler being built.
Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<SIMD::Float>, Pointer<SIMD::Float>, Pointer<Byte>)> function;
......
......@@ -258,12 +258,9 @@ uint8_t* DescriptorSetLayout::getOffsetPointer(DescriptorSet *descriptorSet, uin
void SampledImageDescriptor::updateSampler(const vk::Sampler *sampler)
{
if (sampler)
if(sampler)
{
memcpy(&this->sampler, sampler, sizeof(*sampler));
texture.minLod = sampler->minLod;
texture.maxLod = sampler->maxLod;
memcpy(&this->sampler, sampler, sizeof(this->sampler));
}
}
......@@ -357,29 +354,27 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
int pitchP = imageView->rowPitchBytes(aspect, level) / format.bytes();
int sliceP = (layers > 1 ? imageView->layerPitchBytes(aspect) : imageView->slicePitchBytes(aspect, level)) / format.bytes();
float exp2LOD = 1.0f;
if(mipmapLevel == 0)
{
texture->widthHeightLOD[0] = width * exp2LOD;
texture->widthHeightLOD[1] = width * exp2LOD;
texture->widthHeightLOD[2] = height * exp2LOD;
texture->widthHeightLOD[3] = height * exp2LOD;
texture->widthLOD[0] = width * exp2LOD;
texture->widthLOD[1] = width * exp2LOD;
texture->widthLOD[2] = width * exp2LOD;
texture->widthLOD[3] = width * exp2LOD;
texture->heightLOD[0] = height * exp2LOD;
texture->heightLOD[1] = height * exp2LOD;
texture->heightLOD[2] = height * exp2LOD;
texture->heightLOD[3] = height * exp2LOD;
texture->depthLOD[0] = depth * exp2LOD;
texture->depthLOD[1] = depth * exp2LOD;
texture->depthLOD[2] = depth * exp2LOD;
texture->depthLOD[3] = depth * exp2LOD;
texture->widthWidthHeightHeight[0] = width;
texture->widthWidthHeightHeight[1] = width;
texture->widthWidthHeightHeight[2] = height;
texture->widthWidthHeightHeight[3] = height;
texture->width[0] = width;
texture->width[1] = width;
texture->width[2] = width;
texture->width[3] = width;
texture->height[0] = height;
texture->height[1] = height;
texture->height[2] = height;
texture->height[3] = height;
texture->depth[0] = depth;
texture->depth[1] = depth;
texture->depth[2] = depth;
texture->depth[3] = depth;
}
if(format.isFloatFormat())
......
......@@ -148,7 +148,6 @@ IF EXIST "$(SolutionDir)..\deqp\build\external\vulkancts\modules\vulkan\" (copy
<ClCompile Include="..\Device\Point.cpp" />
<ClCompile Include="..\Device\QuadRasterizer.cpp" />
<ClCompile Include="..\Device\Renderer.cpp" />
<ClCompile Include="..\Device\Sampler.cpp" />
<ClCompile Include="..\Device\SetupProcessor.cpp" />
<ClCompile Include="..\Device\SwiftConfig.cpp" />
<ClCompile Include="..\Device\Vector.cpp" />
......
......@@ -57,9 +57,6 @@
<ClCompile Include="..\Device\SetupProcessor.cpp">
<Filter>Source Files\Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Sampler.cpp">
<Filter>Source Files\Device</Filter>
</ClCompile>
<ClCompile Include="..\Device\Renderer.cpp">
<Filter>Source Files\Device</Filter>
</ClCompile>
......
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