diff options
author | Brian Salomon <bsalomon@google.com> | 2017-09-07 12:36:34 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-07 16:58:31 +0000 |
commit | 2bbdcc44c63974f29f3743bb58d929601a3f65c6 (patch) | |
tree | d420f298f606b061054e56866d1930ab84f00ed5 /src/gpu/vk | |
parent | 4df0092eac6e9bb5afc516773a0c618630193dc6 (diff) |
Rework GrSamplerParams to be more compact and use its own wrap mode enum.
The main change is to make GrSamplerParams smaller by making its enums have byte-sized underlying types. The rest is cosmetic.
Change-Id: Ib71ea50612d24619a85e463826c6b8dfb9b445e3
Reviewed-on: https://skia-review.googlesource.com/43200
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/vk')
-rw-r--r-- | src/gpu/vk/GrVkCopyManager.cpp | 8 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpuCommandBuffer.cpp | 3 | ||||
-rw-r--r-- | src/gpu/vk/GrVkPipelineState.cpp | 6 | ||||
-rw-r--r-- | src/gpu/vk/GrVkResourceProvider.cpp | 4 | ||||
-rw-r--r-- | src/gpu/vk/GrVkResourceProvider.h | 6 | ||||
-rw-r--r-- | src/gpu/vk/GrVkSampler.cpp | 47 | ||||
-rw-r--r-- | src/gpu/vk/GrVkSampler.h | 6 | ||||
-rw-r--r-- | src/gpu/vk/GrVkTexture.cpp | 6 |
8 files changed, 43 insertions, 43 deletions
diff --git a/src/gpu/vk/GrVkCopyManager.cpp b/src/gpu/vk/GrVkCopyManager.cpp index 9e1decfcbb..2b54d37710 100644 --- a/src/gpu/vk/GrVkCopyManager.cpp +++ b/src/gpu/vk/GrVkCopyManager.cpp @@ -7,7 +7,7 @@ #include "GrVkCopyManager.h" -#include "GrSamplerParams.h" +#include "GrSamplerState.h" #include "GrShaderCaps.h" #include "GrSurface.h" #include "GrTexturePriv.h" @@ -259,10 +259,10 @@ bool GrVkCopyManager::copySurfaceAsDraw(GrVkGpu* gpu, const GrVkDescriptorSet* samplerDS = gpu->resourceProvider().getSamplerDescriptorSet(fSamplerDSHandle); - GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode); + GrSamplerState samplerState = GrSamplerState::ClampNearest(); - GrVkSampler* sampler = - resourceProv.findOrCreateCompatibleSampler(params, srcTex->texturePriv().maxMipMapLevel()); + GrVkSampler* sampler = resourceProv.findOrCreateCompatibleSampler( + samplerState, srcTex->texturePriv().maxMipMapLevel()); VkDescriptorImageInfo imageInfo; memset(&imageInfo, 0, sizeof(VkDescriptorImageInfo)); diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp index 15fdf4aa78..e6eb4c30de 100644 --- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp +++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp @@ -566,9 +566,8 @@ static void prepare_sampled_images(const GrResourceIOProcessor& processor, GrVkG gpu->onResolveRenderTarget(texRT, sampler.proxy()->origin()); } - const GrSamplerParams& params = sampler.params(); // Check if we need to regenerate any mip maps - if (GrSamplerParams::kMipMap_FilterMode == params.filterMode()) { + if (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter()) { if (vkTexture->texturePriv().mipMapsAreDirty()) { gpu->generateMipmap(vkTexture, sampler.proxy()->origin()); vkTexture->texturePriv().dirtyMipMaps(false); diff --git a/src/gpu/vk/GrVkPipelineState.cpp b/src/gpu/vk/GrVkPipelineState.cpp index ee2413547f..17197750ab 100644 --- a/src/gpu/vk/GrVkPipelineState.cpp +++ b/src/gpu/vk/GrVkPipelineState.cpp @@ -376,12 +376,12 @@ void GrVkPipelineState::writeSamplers( SkASSERT(fNumSamplers == textureBindings.count()); for (int i = 0; i < textureBindings.count(); ++i) { - const GrSamplerParams& params = textureBindings[i]->params(); + GrSamplerState state = textureBindings[i]->samplerState(); GrVkTexture* texture = static_cast<GrVkTexture*>(textureBindings[i]->peekTexture()); - fSamplers.push(gpu->resourceProvider().findOrCreateCompatibleSampler(params, - texture->texturePriv().maxMipMapLevel())); + fSamplers.push(gpu->resourceProvider().findOrCreateCompatibleSampler( + state, texture->texturePriv().maxMipMapLevel())); const GrVkResource* textureResource = texture->resource(); textureResource->ref(); diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp index cfce75f1ca..e0f6776599 100644 --- a/src/gpu/vk/GrVkResourceProvider.cpp +++ b/src/gpu/vk/GrVkResourceProvider.cpp @@ -7,7 +7,7 @@ #include "GrVkResourceProvider.h" -#include "GrSamplerParams.h" +#include "GrSamplerState.h" #include "GrVkCommandBuffer.h" #include "GrVkCopyPipeline.h" #include "GrVkGpu.h" @@ -165,7 +165,7 @@ GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool( return new GrVkDescriptorPool(fGpu, type, count); } -GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler(const GrSamplerParams& params, +GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler(const GrSamplerState& params, uint32_t maxMipLevel) { GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params, maxMipLevel)); if (!sampler) { diff --git a/src/gpu/vk/GrVkResourceProvider.h b/src/gpu/vk/GrVkResourceProvider.h index ba11c8db52..f48590a1ef 100644 --- a/src/gpu/vk/GrVkResourceProvider.h +++ b/src/gpu/vk/GrVkResourceProvider.h @@ -24,7 +24,7 @@ class GrPipeline; class GrPrimitiveProcessor; -class GrSamplerParams; +class GrSamplerState; class GrVkCopyPipeline; class GrVkGpu; class GrVkPipeline; @@ -96,9 +96,9 @@ public: // of our cache of GrVkDescriptorPools. GrVkDescriptorPool* findOrCreateCompatibleDescriptorPool(VkDescriptorType type, uint32_t count); - // Finds or creates a compatible GrVkSampler based on the GrSamplerParams. + // Finds or creates a compatible GrVkSampler based on the GrSamplerState. // The refcount is incremented and a pointer returned. - GrVkSampler* findOrCreateCompatibleSampler(const GrSamplerParams&, uint32_t maxMipLevel); + GrVkSampler* findOrCreateCompatibleSampler(const GrSamplerState&, uint32_t maxMipLevel); sk_sp<GrVkPipelineState> findOrCreateCompatiblePipelineState(const GrPipeline&, const GrPrimitiveProcessor&, diff --git a/src/gpu/vk/GrVkSampler.cpp b/src/gpu/vk/GrVkSampler.cpp index 740c14b4de..822817bed6 100644 --- a/src/gpu/vk/GrVkSampler.cpp +++ b/src/gpu/vk/GrVkSampler.cpp @@ -9,20 +9,21 @@ #include "GrVkGpu.h" -static inline VkSamplerAddressMode tile_to_vk_sampler_address(SkShader::TileMode tm) { - static const VkSamplerAddressMode gWrapModes[] = { - VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, - VK_SAMPLER_ADDRESS_MODE_REPEAT, - VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT - }; - GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); - GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); - GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); - GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); - return gWrapModes[tm]; +static inline VkSamplerAddressMode wrap_mode_to_vk_sampler_address( + GrSamplerState::WrapMode wrapMode) { + switch (wrapMode) { + case GrSamplerState::WrapMode::kClamp: + return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + case GrSamplerState::WrapMode::kRepeat: + return VK_SAMPLER_ADDRESS_MODE_REPEAT; + case GrSamplerState::WrapMode::kMirrorRepeat: + return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; + } + SK_ABORT("Unknown wrap mode."); + return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; } -GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerParams& params, +GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerState& samplerState, uint32_t maxMipLevel) { static VkFilter vkMinFilterModes[] = { VK_FILTER_NEAREST, @@ -40,11 +41,11 @@ GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerParams& para createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; createInfo.pNext = 0; createInfo.flags = 0; - createInfo.magFilter = vkMagFilterModes[params.filterMode()]; - createInfo.minFilter = vkMinFilterModes[params.filterMode()]; + createInfo.magFilter = vkMagFilterModes[static_cast<int>(samplerState.filter())]; + createInfo.minFilter = vkMinFilterModes[static_cast<int>(samplerState.filter())]; createInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - createInfo.addressModeU = tile_to_vk_sampler_address(params.getTileModeX()); - createInfo.addressModeV = tile_to_vk_sampler_address(params.getTileModeY()); + createInfo.addressModeU = wrap_mode_to_vk_sampler_address(samplerState.wrapModeX()); + createInfo.addressModeV = wrap_mode_to_vk_sampler_address(samplerState.wrapModeY()); createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; // Shouldn't matter createInfo.mipLodBias = 0.0f; createInfo.anisotropyEnable = VK_FALSE; @@ -57,7 +58,7 @@ GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerParams& para // 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 = GrSamplerParams::kMipMap_FilterMode == params.filterMode() && maxMipLevel > 0; + bool useMipMaps = GrSamplerState::Filter::kMipMap == samplerState.filter() && maxMipLevel > 0; createInfo.maxLod = !useMipMaps ? 0.0f : (float)(maxMipLevel); createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; createInfo.unnormalizedCoordinates = VK_FALSE; @@ -68,7 +69,7 @@ GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrSamplerParams& para nullptr, &sampler)); - return new GrVkSampler(sampler, GenerateKey(params, maxMipLevel)); + return new GrVkSampler(sampler, GenerateKey(samplerState, maxMipLevel)); } void GrVkSampler::freeGPUData(const GrVkGpu* gpu) const { @@ -76,18 +77,18 @@ void GrVkSampler::freeGPUData(const GrVkGpu* gpu) const { GR_VK_CALL(gpu->vkInterface(), DestroySampler(gpu->device(), fSampler, nullptr)); } -uint16_t GrVkSampler::GenerateKey(const GrSamplerParams& params, uint32_t maxMipLevel) { +uint16_t GrVkSampler::GenerateKey(const GrSamplerState& samplerState, uint32_t maxMipLevel) { const int kTileModeXShift = 2; const int kTileModeYShift = 4; const int kMipLevelShift = 6; - uint16_t key = params.filterMode(); + uint16_t key = static_cast<uint16_t>(samplerState.filter()); - SkASSERT(params.filterMode() <= 3); - key |= (params.getTileModeX() << kTileModeXShift); + SkASSERT(static_cast<int>(samplerState.filter()) <= 3); + key |= (static_cast<uint16_t>(samplerState.wrapModeX()) << kTileModeXShift); GR_STATIC_ASSERT(SkShader::kTileModeCount <= 4); - key |= (params.getTileModeY() << kTileModeYShift); + key |= (static_cast<uint16_t>(samplerState.wrapModeY()) << kTileModeYShift); SkASSERT(maxMipLevel < 1024); key |= (maxMipLevel << kMipLevelShift); diff --git a/src/gpu/vk/GrVkSampler.h b/src/gpu/vk/GrVkSampler.h index a413ea826a..59a56e78be 100644 --- a/src/gpu/vk/GrVkSampler.h +++ b/src/gpu/vk/GrVkSampler.h @@ -12,18 +12,18 @@ #include "vk/GrVkDefines.h" -class GrSamplerParams; +class GrSamplerState; class GrVkGpu; class GrVkSampler : public GrVkResource { public: - static GrVkSampler* Create(const GrVkGpu* gpu, const GrSamplerParams&, uint32_t maxMipLevel); + static GrVkSampler* Create(const GrVkGpu* gpu, const GrSamplerState&, uint32_t maxMipLevel); VkSampler sampler() const { return fSampler; } // Helpers for hashing GrVkSampler - static uint16_t GenerateKey(const GrSamplerParams&, uint32_t maxMipLevel); + static uint16_t GenerateKey(const GrSamplerState&, uint32_t maxMipLevel); static const uint16_t& GetKey(const GrVkSampler& sampler) { return sampler.fKey; } static uint32_t Hash(const uint16_t& key) { return key; } diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp index ce1d4875d6..1049e53e7b 100644 --- a/src/gpu/vk/GrVkTexture.cpp +++ b/src/gpu/vk/GrVkTexture.cpp @@ -18,12 +18,12 @@ #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) // This method parallels GrTextureProxy::highestFilterMode -static inline GrSamplerParams::FilterMode highest_filter_mode(GrPixelConfig config) { +static inline GrSamplerState::Filter highest_filter_mode(GrPixelConfig config) { if (GrPixelConfigIsSint(config)) { // We only ever want to nearest-neighbor sample signed int textures. - return GrSamplerParams::kNone_FilterMode; + return GrSamplerState::Filter::kNearest; } - return GrSamplerParams::kMipMap_FilterMode; + return GrSamplerState::Filter::kMipMap; } // Because this class is virtually derived from GrSurface we must explicitly call its constructor. |