OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "GrVkSampler.h" | |
9 | |
10 #include "GrTextureAccess.h" | |
11 #include "GrVkGpu.h" | |
12 | |
13 static inline VkSamplerAddressMode tile_to_vk_sampler_address(SkShader::TileMode
tm) { | |
14 static const VkSamplerAddressMode gWrapModes[] = { | |
15 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, | |
16 VK_SAMPLER_ADDRESS_MODE_REPEAT, | |
17 VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT | |
18 }; | |
19 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); | |
20 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); | |
21 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); | |
22 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); | |
23 return gWrapModes[tm]; | |
24 } | |
25 | |
26 GrVkSampler* GrVkSampler::Create(const GrVkGpu* gpu, const GrTextureAccess& text
ureAccess) { | |
27 | |
28 static VkFilter vkMinFilterModes[] = { | |
29 VK_FILTER_NEAREST, | |
30 VK_FILTER_LINEAR, | |
31 VK_FILTER_LINEAR | |
32 }; | |
33 static VkFilter vkMagFilterModes[] = { | |
34 VK_FILTER_NEAREST, | |
35 VK_FILTER_LINEAR, | |
36 VK_FILTER_LINEAR | |
37 }; | |
38 | |
39 const GrTextureParams& params = textureAccess.getParams(); | |
40 | |
41 VkSamplerCreateInfo createInfo; | |
42 memset(&createInfo, 0, sizeof(VkSamplerCreateInfo)); | |
43 createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; | |
44 createInfo.pNext = 0; | |
45 createInfo.flags = 0; | |
46 createInfo.magFilter = vkMagFilterModes[params.filterMode()]; | |
47 createInfo.minFilter = vkMinFilterModes[params.filterMode()]; | |
48 createInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; | |
49 createInfo.addressModeU = tile_to_vk_sampler_address(params.getTileModeX()); | |
50 createInfo.addressModeV = tile_to_vk_sampler_address(params.getTileModeY()); | |
51 createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; // Shouldn'
t matter | |
52 createInfo.mipLodBias = 0.0f; | |
53 createInfo.anisotropyEnable = VK_FALSE; | |
54 createInfo.maxAnisotropy = 1.0f; | |
55 createInfo.compareEnable = VK_FALSE; | |
56 createInfo.compareOp = VK_COMPARE_OP_NEVER; | |
57 createInfo.minLod = 0.0f; | |
58 createInfo.maxLod = 0.0f; | |
59 createInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; | |
60 createInfo.unnormalizedCoordinates = VK_FALSE; | |
61 | |
62 VkSampler sampler; | |
63 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateSampler(gpu->device(), | |
64 &createInfo, | |
65 nullptr, | |
66 &sampler)); | |
67 | |
68 return new GrVkSampler(sampler); | |
69 } | |
70 | |
71 void GrVkSampler::freeGPUData(const GrVkGpu* gpu) const { | |
72 SkASSERT(fSampler); | |
73 GR_VK_CALL(gpu->vkInterface(), DestroySampler(gpu->device(), fSampler, nullp
tr)); | |
74 } | |
OLD | NEW |