| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrVkSampler.h" | 8 #include "GrVkSampler.h" |
| 9 | 9 |
| 10 #include "GrTextureAccess.h" | 10 #include "GrTextureAccess.h" |
| 11 #include "GrVkGpu.h" | 11 #include "GrVkGpu.h" |
| 12 | 12 |
| 13 static inline VkSamplerAddressMode tile_to_vk_sampler_address(SkShader::TileMode
tm) { | 13 static inline VkSamplerAddressMode tile_to_vk_sampler_address(SkShader::TileMode
tm) { |
| 14 static const VkSamplerAddressMode gWrapModes[] = { | 14 static const VkSamplerAddressMode gWrapModes[] = { |
| 15 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, | 15 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, |
| 16 VK_SAMPLER_ADDRESS_MODE_REPEAT, | 16 VK_SAMPLER_ADDRESS_MODE_REPEAT, |
| 17 VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT | 17 VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT |
| 18 }; | 18 }; |
| 19 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); | 19 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); |
| 20 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); | 20 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); |
| 21 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); | 21 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); |
| 22 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); | 22 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); |
| 23 return gWrapModes[tm]; | 23 return gWrapModes[tm]; |
| 24 } | 24 } |
| 25 | 25 |
| 26 GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrTextureParams& para
ms, | 26 GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrTextureParams& para
ms, |
| 27 uint32_t mipLevels) { | 27 uint32_t mipLevels) { |
| 28 | |
| 29 static VkFilter vkMinFilterModes[] = { | 28 static VkFilter vkMinFilterModes[] = { |
| 30 VK_FILTER_NEAREST, | 29 VK_FILTER_NEAREST, |
| 31 VK_FILTER_LINEAR, | 30 VK_FILTER_LINEAR, |
| 32 VK_FILTER_LINEAR | 31 VK_FILTER_LINEAR |
| 33 }; | 32 }; |
| 34 static VkFilter vkMagFilterModes[] = { | 33 static VkFilter vkMagFilterModes[] = { |
| 35 VK_FILTER_NEAREST, | 34 VK_FILTER_NEAREST, |
| 36 VK_FILTER_LINEAR, | 35 VK_FILTER_LINEAR, |
| 37 VK_FILTER_LINEAR | 36 VK_FILTER_LINEAR |
| 38 }; | 37 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 52 createInfo.anisotropyEnable = VK_FALSE; | 51 createInfo.anisotropyEnable = VK_FALSE; |
| 53 createInfo.maxAnisotropy = 1.0f; | 52 createInfo.maxAnisotropy = 1.0f; |
| 54 createInfo.compareEnable = VK_FALSE; | 53 createInfo.compareEnable = VK_FALSE; |
| 55 createInfo.compareOp = VK_COMPARE_OP_NEVER; | 54 createInfo.compareOp = VK_COMPARE_OP_NEVER; |
| 56 // Vulkan doesn't have a direct mapping of GL's nearest or linear filters fo
r minFilter since | 55 // Vulkan doesn't have a direct mapping of GL's nearest or linear filters fo
r minFilter since |
| 57 // there is always a mipmapMode. To get the same effect as GL we can set min
Lod = maxLod = 0.0. | 56 // there is always a mipmapMode. To get the same effect as GL we can set min
Lod = maxLod = 0.0. |
| 58 // This works since our min and mag filters are the same (this forces us to
use mag on the 0 | 57 // This works since our min and mag filters are the same (this forces us to
use mag on the 0 |
| 59 // level mip). If the filters weren't the same we could set min = 0 and max
= 0.25 to force | 58 // level mip). If the filters weren't the same we could set min = 0 and max
= 0.25 to force |
| 60 // the minFilter on mip level 0. | 59 // the minFilter on mip level 0. |
| 61 createInfo.minLod = 0.0f; | 60 createInfo.minLod = 0.0f; |
| 62 createInfo.maxLod = (mipLevels == 1) ? 0.0f : (float)(mipLevels); | 61 bool useMipMaps = GrTextureParams::kMipMap_FilterMode == params.filterMode()
&& mipLevels > 1; |
| 62 createInfo.maxLod = !useMipMaps ? 0.0f : (float)(mipLevels); |
| 63 createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; | 63 createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; |
| 64 createInfo.unnormalizedCoordinates = VK_FALSE; | 64 createInfo.unnormalizedCoordinates = VK_FALSE; |
| 65 | 65 |
| 66 VkSampler sampler; | 66 VkSampler sampler; |
| 67 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateSampler(gpu->device(), | 67 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateSampler(gpu->device(), |
| 68 &createInfo, | 68 &createInfo, |
| 69 nullptr, | 69 nullptr, |
| 70 &sampler)); | 70 &sampler)); |
| 71 | 71 |
| 72 return new GrVkSampler(sampler, GenerateKey(params, mipLevels)); | 72 return new GrVkSampler(sampler, GenerateKey(params, mipLevels)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 88 key |= (params.getTileModeX() << kTileModeXShift); | 88 key |= (params.getTileModeX() << kTileModeXShift); |
| 89 | 89 |
| 90 GR_STATIC_ASSERT(SkShader::kTileModeCount <= 4); | 90 GR_STATIC_ASSERT(SkShader::kTileModeCount <= 4); |
| 91 key |= (params.getTileModeY() << kTileModeYShift); | 91 key |= (params.getTileModeY() << kTileModeYShift); |
| 92 | 92 |
| 93 SkASSERT(mipLevels < 1024); | 93 SkASSERT(mipLevels < 1024); |
| 94 key |= (mipLevels << kMipLevelShift); | 94 key |= (mipLevels << kMipLevelShift); |
| 95 | 95 |
| 96 return key; | 96 return key; |
| 97 } | 97 } |
| OLD | NEW |