Commit f948cd1e by Nicolas Capens Committed by Nicolas Capens

Split vk::Sampler state off into a structure

This enables deriving the state structure from Memset<> so we can ensure it is fully zero-initialized and becomes comparable, while vk::Sampler holds the identifier for the state. Bug: b/151235334 Change-Id: I23a09eda9b50409c761bdd6ed10911ec159dc3ba Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42768 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 1885f694
......@@ -84,12 +84,9 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl
samplerState.compareOp = sampler->compareOp;
samplerState.unnormalizedCoordinates = (sampler->unnormalizedCoordinates != VK_FALSE);
if(sampler->ycbcrConversion)
{
samplerState.ycbcrModel = sampler->ycbcrConversion->ycbcrModel;
samplerState.studioSwing = (sampler->ycbcrConversion->ycbcrRange == VK_SAMPLER_YCBCR_RANGE_ITU_NARROW);
samplerState.swappedChroma = (sampler->ycbcrConversion->components.r != VK_COMPONENT_SWIZZLE_R);
}
samplerState.ycbcrModel = sampler->ycbcrModel;
samplerState.studioSwing = sampler->studioSwing;
samplerState.swappedChroma = sampler->swappedChroma;
samplerState.mipLodBias = sampler->mipLodBias;
samplerState.maxAnisotropy = sampler->maxAnisotropy;
......@@ -270,7 +267,7 @@ sw::MipmapType SpirvShader::convertMipmapMode(const vk::Sampler *sampler)
return MIPMAP_POINT; // Samplerless operations (OpImageFetch) can take an integer Lod operand.
}
if(sampler->ycbcrConversion)
if(sampler->ycbcrModel != VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY)
{
// TODO(b/151263485): Check image view level count instead.
return MIPMAP_NONE;
......
......@@ -18,4 +18,35 @@ namespace vk {
std::atomic<uint32_t> Sampler::nextID(1);
SamplerState::SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion)
: Memset(this, 0)
, magFilter(pCreateInfo->magFilter)
, minFilter(pCreateInfo->minFilter)
, mipmapMode(pCreateInfo->mipmapMode)
, addressModeU(pCreateInfo->addressModeU)
, addressModeV(pCreateInfo->addressModeV)
, addressModeW(pCreateInfo->addressModeW)
, mipLodBias(pCreateInfo->mipLodBias)
, anisotropyEnable(pCreateInfo->anisotropyEnable)
, maxAnisotropy(pCreateInfo->maxAnisotropy)
, compareEnable(pCreateInfo->compareEnable)
, compareOp(pCreateInfo->compareOp)
, minLod(ClampLod(pCreateInfo->minLod))
, maxLod(ClampLod(pCreateInfo->maxLod))
, borderColor(pCreateInfo->borderColor)
, unnormalizedCoordinates(pCreateInfo->unnormalizedCoordinates)
{
if(ycbcrConversion)
{
ycbcrModel = ycbcrConversion->ycbcrModel;
studioSwing = (ycbcrConversion->ycbcrRange == VK_SAMPLER_YCBCR_RANGE_ITU_NARROW);
swappedChroma = (ycbcrConversion->components.r != VK_COMPONENT_SWIZZLE_R);
}
}
Sampler::Sampler(const VkSamplerCreateInfo *pCreateInfo, void *mem, const vk::SamplerYcbcrConversion *ycbcrConversion)
: SamplerState(pCreateInfo, ycbcrConversion)
{
}
} // namespace vk
......@@ -15,42 +15,18 @@
#ifndef VK_SAMPLER_HPP_
#define VK_SAMPLER_HPP_
#include "VkDevice.hpp"
#include "VkImageView.hpp" // For ResolveIdentityMapping()
#include "Device/Config.hpp"
#include "Device/Memset.hpp"
#include "System/Math.hpp"
#include <atomic>
namespace vk {
class Sampler : public Object<Sampler, VkSampler>
struct SamplerState : sw::Memset<SamplerState>
{
public:
Sampler(const VkSamplerCreateInfo *pCreateInfo, void *mem, const vk::SamplerYcbcrConversion *ycbcrConversion)
: magFilter(pCreateInfo->magFilter)
, minFilter(pCreateInfo->minFilter)
, mipmapMode(pCreateInfo->mipmapMode)
, addressModeU(pCreateInfo->addressModeU)
, addressModeV(pCreateInfo->addressModeV)
, addressModeW(pCreateInfo->addressModeW)
, mipLodBias(pCreateInfo->mipLodBias)
, anisotropyEnable(pCreateInfo->anisotropyEnable)
, maxAnisotropy(pCreateInfo->maxAnisotropy)
, compareEnable(pCreateInfo->compareEnable)
, compareOp(pCreateInfo->compareOp)
, minLod(ClampLod(pCreateInfo->minLod))
, maxLod(ClampLod(pCreateInfo->maxLod))
, borderColor(pCreateInfo->borderColor)
, unnormalizedCoordinates(pCreateInfo->unnormalizedCoordinates)
, ycbcrConversion(ycbcrConversion)
{
}
static size_t ComputeRequiredAllocationSize(const VkSamplerCreateInfo *pCreateInfo)
{
return 0;
}
SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion);
// Prevents accessing mipmap levels out of range.
static float ClampLod(float lod)
......@@ -58,7 +34,6 @@ public:
return sw::clamp(lod, 0.0f, (float)(sw::MAX_TEXTURE_LOD));
}
const uint32_t id = nextID++;
const VkFilter magFilter = VK_FILTER_NEAREST;
const VkFilter minFilter = VK_FILTER_NEAREST;
const VkSamplerMipmapMode mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
......@@ -75,7 +50,22 @@ public:
const VkBorderColor borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
const VkBool32 unnormalizedCoordinates = VK_FALSE;
const vk::SamplerYcbcrConversion *ycbcrConversion = nullptr;
VkSamplerYcbcrModelConversion ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
bool studioSwing = false; // Narrow range
bool swappedChroma = false; // Cb/Cr components in reverse order
};
class Sampler : public Object<Sampler, VkSampler>, public SamplerState
{
public:
Sampler(const VkSamplerCreateInfo *pCreateInfo, void *mem, const vk::SamplerYcbcrConversion *ycbcrConversion);
static size_t ComputeRequiredAllocationSize(const VkSamplerCreateInfo *pCreateInfo)
{
return 0;
}
const uint32_t id = nextID++;
private:
static std::atomic<uint32_t> nextID;
......
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