In Vulkan, use 1000 for maxLod instead of maxMipLevel when using mips.

This has the side effect of making samplers in Vulkan only dependent on
the sampler state and not the texture size.

Bug: skia:
Change-Id: I03ccc2c2faead4a1e10b9dd1e5d5885a9d672cc5
Reviewed-on: https://skia-review.googlesource.com/c/173103
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2018-11-27 16:56:29 -05:00 committed by Skia Commit-Bot
parent a2e613c999
commit 6616efbdeb
6 changed files with 24 additions and 32 deletions

View File

@ -261,8 +261,7 @@ bool GrVkCopyManager::copySurfaceAsDraw(GrVkGpu* gpu,
GrSamplerState samplerState = GrSamplerState::ClampNearest();
GrVkSampler* sampler = resourceProv.findOrCreateCompatibleSampler(
samplerState, srcTex->texturePriv().maxMipMapLevel());
GrVkSampler* sampler = resourceProv.findOrCreateCompatibleSampler(samplerState);
VkDescriptorImageInfo imageInfo;
memset(&imageInfo, 0, sizeof(VkDescriptorImageInfo));

View File

@ -243,8 +243,7 @@ void GrVkPipelineState::setAndBindTextures(GrVkGpu* gpu,
GrVkTexture* texture = samplerBindings[i].fTexture;
const GrVkImageView* textureView = texture->textureView();
GrVkSampler* sampler = gpu->resourceProvider().findOrCreateCompatibleSampler(
state, texture->texturePriv().maxMipMapLevel());
GrVkSampler* sampler = gpu->resourceProvider().findOrCreateCompatibleSampler(state);
VkDescriptorImageInfo imageInfo;
memset(&imageInfo, 0, sizeof(VkDescriptorImageInfo));

View File

@ -166,11 +166,10 @@ GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool(
return new GrVkDescriptorPool(fGpu, type, count);
}
GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler(const GrSamplerState& params,
uint32_t maxMipLevel) {
GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params, maxMipLevel));
GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler(const GrSamplerState& params) {
GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params));
if (!sampler) {
sampler = GrVkSampler::Create(fGpu, params, maxMipLevel);
sampler = GrVkSampler::Create(fGpu, params);
fSamplers.add(sampler);
}
SkASSERT(sampler);
@ -350,7 +349,7 @@ void GrVkResourceProvider::destroyResources(bool deviceLost) {
fRenderPassArray.reset();
// Iterate through all store GrVkSamplers and unref them before resetting the hash.
SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers);
SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers);
for (; !iter.done(); ++iter) {
(*iter).unref(fGpu);
}
@ -409,7 +408,7 @@ void GrVkResourceProvider::abandonResources() {
fRenderPassArray.reset();
// Iterate through all store GrVkSamplers and unrefAndAbandon them before resetting the hash.
SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers);
SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers);
for (; !iter.done(); ++iter) {
(*iter).unrefAndAbandon();
}

View File

@ -99,7 +99,7 @@ public:
// Finds or creates a compatible GrVkSampler based on the GrSamplerState.
// The refcount is incremented and a pointer returned.
GrVkSampler* findOrCreateCompatibleSampler(const GrSamplerState&, uint32_t maxMipLevel);
GrVkSampler* findOrCreateCompatibleSampler(const GrSamplerState&);
GrVkPipelineState* findOrCreateCompatiblePipelineState(const GrPipeline&,
const GrPrimitiveProcessor&,
@ -252,7 +252,7 @@ private:
// Stores GrVkSampler objects that we've already created so we can reuse them across multiple
// GrVkPipelineStates
SkTDynamicHash<GrVkSampler, uint16_t> fSamplers;
SkTDynamicHash<GrVkSampler, uint8_t> fSamplers;
// Cache of GrVkPipelineStates
PipelineStateCache* fPipelineStateCache;

View File

@ -23,8 +23,7 @@ static inline VkSamplerAddressMode wrap_mode_to_vk_sampler_address(
return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
}
GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerState& samplerState,
uint32_t maxMipLevel) {
GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerState& samplerState) {
static VkFilter vkMinFilterModes[] = {
VK_FILTER_NEAREST,
VK_FILTER_LINEAR,
@ -58,8 +57,8 @@ GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerState& sampl
// level mip). If the filters weren't the same we could set min = 0 and max = 0.25 to force
// the minFilter on mip level 0.
createInfo.minLod = 0.0f;
bool useMipMaps = GrSamplerState::Filter::kMipMap == samplerState.filter() && maxMipLevel > 0;
createInfo.maxLod = !useMipMaps ? 0.0f : (float)(maxMipLevel);
bool useMipMaps = GrSamplerState::Filter::kMipMap == samplerState.filter();
createInfo.maxLod = !useMipMaps ? 0.0f : 10000.0f;
createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
createInfo.unnormalizedCoordinates = VK_FALSE;
@ -69,7 +68,7 @@ GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerState& sampl
nullptr,
&sampler));
return new GrVkSampler(sampler, GenerateKey(samplerState, maxMipLevel));
return new GrVkSampler(sampler, GenerateKey(samplerState));
}
void GrVkSampler::freeGPUData(const GrVkGpu* gpu) const {
@ -77,22 +76,18 @@ void GrVkSampler::freeGPUData(const GrVkGpu* gpu) const {
GR_VK_CALL(gpu->vkInterface(), DestroySampler(gpu->device(), fSampler, nullptr));
}
uint16_t GrVkSampler::GenerateKey(const GrSamplerState& samplerState, uint32_t maxMipLevel) {
uint8_t GrVkSampler::GenerateKey(const GrSamplerState& samplerState) {
const int kTileModeXShift = 2;
const int kTileModeYShift = 4;
const int kMipLevelShift = 6;
SkASSERT(static_cast<int>(samplerState.filter()) <= 3);
uint16_t key = static_cast<uint16_t>(samplerState.filter());
uint8_t key = static_cast<uint8_t>(samplerState.filter());
SkASSERT(static_cast<int>(samplerState.wrapModeX()) <= 4);
key |= (static_cast<uint16_t>(samplerState.wrapModeX()) << kTileModeXShift);
SkASSERT(static_cast<int>(samplerState.wrapModeX()) <= 3);
key |= (static_cast<uint8_t>(samplerState.wrapModeX()) << kTileModeXShift);
SkASSERT(static_cast<int>(samplerState.wrapModeY()) <= 4);
key |= (static_cast<uint16_t>(samplerState.wrapModeY()) << kTileModeYShift);
SkASSERT(maxMipLevel < 1024);
key |= (maxMipLevel << kMipLevelShift);
SkASSERT(static_cast<int>(samplerState.wrapModeY()) <= 3);
key |= (static_cast<uint8_t>(samplerState.wrapModeY()) << kTileModeYShift);
return key;
}

View File

@ -18,14 +18,14 @@ class GrVkGpu;
class GrVkSampler : public GrVkResource {
public:
static GrVkSampler* Create(const GrVkGpu* gpu, const GrSamplerState&, uint32_t maxMipLevel);
static GrVkSampler* Create(const GrVkGpu* gpu, const GrSamplerState&);
VkSampler sampler() const { return fSampler; }
// Helpers for hashing GrVkSampler
static uint16_t GenerateKey(const GrSamplerState&, uint32_t maxMipLevel);
static uint8_t GenerateKey(const GrSamplerState&);
static const uint16_t& GetKey(const GrVkSampler& sampler) { return sampler.fKey; }
static const uint8_t& GetKey(const GrVkSampler& sampler) { return sampler.fKey; }
static uint32_t Hash(const uint16_t& key) { return key; }
#ifdef SK_TRACE_VK_RESOURCES
@ -39,8 +39,8 @@ private:
void freeGPUData(const GrVkGpu* gpu) const override;
VkSampler fSampler;
uint16_t fKey;
VkSampler fSampler;
uint8_t fKey;
typedef GrVkResource INHERITED;
};