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 | 28 |
28 static VkFilter vkMinFilterModes[] = { | 29 static VkFilter vkMinFilterModes[] = { |
29 VK_FILTER_NEAREST, | 30 VK_FILTER_NEAREST, |
30 VK_FILTER_LINEAR, | 31 VK_FILTER_LINEAR, |
31 VK_FILTER_LINEAR | 32 VK_FILTER_LINEAR |
32 }; | 33 }; |
33 static VkFilter vkMagFilterModes[] = { | 34 static VkFilter vkMagFilterModes[] = { |
34 VK_FILTER_NEAREST, | 35 VK_FILTER_NEAREST, |
35 VK_FILTER_LINEAR, | 36 VK_FILTER_LINEAR, |
36 VK_FILTER_LINEAR | 37 VK_FILTER_LINEAR |
(...skipping 14 matching lines...) Expand all Loading... |
51 createInfo.anisotropyEnable = VK_FALSE; | 52 createInfo.anisotropyEnable = VK_FALSE; |
52 createInfo.maxAnisotropy = 1.0f; | 53 createInfo.maxAnisotropy = 1.0f; |
53 createInfo.compareEnable = VK_FALSE; | 54 createInfo.compareEnable = VK_FALSE; |
54 createInfo.compareOp = VK_COMPARE_OP_NEVER; | 55 createInfo.compareOp = VK_COMPARE_OP_NEVER; |
55 // Vulkan doesn't have a direct mapping of GL's nearest or linear filters fo
r minFilter since | 56 // Vulkan doesn't have a direct mapping of GL's nearest or linear filters fo
r minFilter since |
56 // there is always a mipmapMode. To get the same effect as GL we can set min
Lod = maxLod = 0.0. | 57 // there is always a mipmapMode. To get the same effect as GL we can set min
Lod = maxLod = 0.0. |
57 // This works since our min and mag filters are the same (this forces us to
use mag on the 0 | 58 // This works since our min and mag filters are the same (this forces us to
use mag on the 0 |
58 // level mip). If the filters weren't the same we could set min = 0 and max
= 0.25 to force | 59 // level mip). If the filters weren't the same we could set min = 0 and max
= 0.25 to force |
59 // the minFilter on mip level 0. | 60 // the minFilter on mip level 0. |
60 createInfo.minLod = 0.0f; | 61 createInfo.minLod = 0.0f; |
61 createInfo.maxLod = 0.0f; | 62 createInfo.maxLod = (mipLevels == 1) ? 0.0f : (float)(mipLevels); |
62 createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; | 63 createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; |
63 createInfo.unnormalizedCoordinates = VK_FALSE; | 64 createInfo.unnormalizedCoordinates = VK_FALSE; |
64 | 65 |
65 VkSampler sampler; | 66 VkSampler sampler; |
66 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateSampler(gpu->device(), | 67 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateSampler(gpu->device(), |
67 &createInfo, | 68 &createInfo, |
68 nullptr, | 69 nullptr, |
69 &sampler)); | 70 &sampler)); |
70 | 71 |
71 return new GrVkSampler(sampler, GenerateKey(params)); | 72 return new GrVkSampler(sampler, GenerateKey(params, mipLevels)); |
72 } | 73 } |
73 | 74 |
74 void GrVkSampler::freeGPUData(const GrVkGpu* gpu) const { | 75 void GrVkSampler::freeGPUData(const GrVkGpu* gpu) const { |
75 SkASSERT(fSampler); | 76 SkASSERT(fSampler); |
76 GR_VK_CALL(gpu->vkInterface(), DestroySampler(gpu->device(), fSampler, nullp
tr)); | 77 GR_VK_CALL(gpu->vkInterface(), DestroySampler(gpu->device(), fSampler, nullp
tr)); |
77 } | 78 } |
78 | 79 |
79 uint8_t GrVkSampler::GenerateKey(const GrTextureParams& params) { | 80 uint16_t GrVkSampler::GenerateKey(const GrTextureParams& params, uint32_t mipLev
els) { |
| 81 const int kTileModeXShift = 2; |
| 82 const int kTileModeYShift = 4; |
| 83 const int kMipLevelShift = 6; |
80 | 84 |
81 uint8_t key = params.filterMode(); | 85 uint16_t key = params.filterMode(); |
82 | 86 |
83 SkASSERT(params.filterMode() <= 3); | 87 SkASSERT(params.filterMode() <= 3); |
84 key |= (params.getTileModeX() << 2); | 88 key |= (params.getTileModeX() << kTileModeXShift); |
85 | 89 |
86 GR_STATIC_ASSERT(SkShader::kTileModeCount <= 4); | 90 GR_STATIC_ASSERT(SkShader::kTileModeCount <= 4); |
87 key |= (params.getTileModeY() << 4); | 91 key |= (params.getTileModeY() << kTileModeYShift); |
| 92 |
| 93 SkASSERT(mipLevels < 1024); |
| 94 key |= (mipLevels << kMipLevelShift); |
88 | 95 |
89 return key; | 96 return key; |
90 } | 97 } |
OLD | NEW |