blob: 215e9ba30eb6565696db1c3972eed2fa996e164d [file] [log] [blame]
Jason Ekstrand5f5fc232015-12-31 13:51:15 -08001/*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24static const uint8_t
25anv_surftype(const struct anv_image *image, VkImageViewType view_type,
26 bool storage)
27{
28 switch (view_type) {
29 default:
30 unreachable("bad VkImageViewType");
31 case VK_IMAGE_VIEW_TYPE_1D:
32 case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
33 assert(image->type == VK_IMAGE_TYPE_1D);
34 return SURFTYPE_1D;
35 case VK_IMAGE_VIEW_TYPE_CUBE:
36 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
37 assert(image->type == VK_IMAGE_TYPE_2D);
38 return storage ? SURFTYPE_2D : SURFTYPE_CUBE;
39 case VK_IMAGE_VIEW_TYPE_2D:
40 case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
41 assert(image->type == VK_IMAGE_TYPE_2D);
42 return SURFTYPE_2D;
43 case VK_IMAGE_VIEW_TYPE_3D:
44 assert(image->type == VK_IMAGE_TYPE_3D);
45 return SURFTYPE_3D;
46 }
47}
48
49#if ANV_GEN > 7 || ANV_IS_HASWELL
50static const uint32_t vk_to_gen_swizzle_map[] = {
51 [VK_COMPONENT_SWIZZLE_ZERO] = SCS_ZERO,
52 [VK_COMPONENT_SWIZZLE_ONE] = SCS_ONE,
53 [VK_COMPONENT_SWIZZLE_R] = SCS_RED,
54 [VK_COMPONENT_SWIZZLE_G] = SCS_GREEN,
55 [VK_COMPONENT_SWIZZLE_B] = SCS_BLUE,
56 [VK_COMPONENT_SWIZZLE_A] = SCS_ALPHA
57};
58
59static inline uint32_t
60vk_to_gen_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component)
61{
62 if (swizzle == VK_COMPONENT_SWIZZLE_IDENTITY)
63 return vk_to_gen_swizzle_map[component];
64 else
65 return vk_to_gen_swizzle_map[swizzle];
66}
67#endif
Jason Ekstrandd8cd5e32016-01-06 19:33:46 -080068
Jason Ekstranded4fe3e2016-01-06 19:48:57 -080069static inline uint32_t
70vk_to_gen_tex_filter(VkFilter filter, bool anisotropyEnable)
71{
72 switch (filter) {
73 default:
74 assert(!"Invalid filter");
75 case VK_FILTER_NEAREST:
76 return MAPFILTER_NEAREST;
77 case VK_FILTER_LINEAR:
78 return anisotropyEnable ? MAPFILTER_ANISOTROPIC : MAPFILTER_LINEAR;
79 }
80}
81
82static inline uint32_t
83vk_to_gen_max_anisotropy(float ratio)
84{
85 return (anv_clamp_f(ratio, 2, 16) - 2) / 2;
86}
Jason Ekstrandd8cd5e32016-01-06 19:33:46 -080087
88static const uint32_t vk_to_gen_mipmap_mode[] = {
Jason Ekstrandd8cd5e32016-01-06 19:33:46 -080089 [VK_SAMPLER_MIPMAP_MODE_NEAREST] = MIPFILTER_NEAREST,
90 [VK_SAMPLER_MIPMAP_MODE_LINEAR] = MIPFILTER_LINEAR
91};
92
93static const uint32_t vk_to_gen_tex_address[] = {
94 [VK_SAMPLER_ADDRESS_MODE_REPEAT] = TCM_WRAP,
95 [VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT] = TCM_MIRROR,
96 [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE] = TCM_CLAMP,
97 [VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE] = TCM_MIRROR_ONCE,
98 [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER] = TCM_CLAMP_BORDER,
99};
100
101static const uint32_t vk_to_gen_compare_op[] = {
102 [VK_COMPARE_OP_NEVER] = PREFILTEROPNEVER,
103 [VK_COMPARE_OP_LESS] = PREFILTEROPLESS,
104 [VK_COMPARE_OP_EQUAL] = PREFILTEROPEQUAL,
105 [VK_COMPARE_OP_LESS_OR_EQUAL] = PREFILTEROPLEQUAL,
106 [VK_COMPARE_OP_GREATER] = PREFILTEROPGREATER,
107 [VK_COMPARE_OP_NOT_EQUAL] = PREFILTEROPNOTEQUAL,
108 [VK_COMPARE_OP_GREATER_OR_EQUAL] = PREFILTEROPGEQUAL,
109 [VK_COMPARE_OP_ALWAYS] = PREFILTEROPALWAYS,
110};