2 * Copyright © 2015 Intel Corporation
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:
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
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
25 anv_surftype(const struct anv_image
*image
, VkImageViewType view_type
,
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
);
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
);
43 case VK_IMAGE_VIEW_TYPE_3D
:
44 assert(image
->type
== VK_IMAGE_TYPE_3D
);
49 static enum isl_format
50 anv_surface_format(const struct anv_device
*device
, enum isl_format format
,
54 return isl_lower_storage_image_format(&device
->isl_dev
, format
);
60 #if ANV_GEN > 7 || ANV_IS_HASWELL
61 static const uint32_t vk_to_gen_swizzle
[] = {
62 [VK_COMPONENT_SWIZZLE_ZERO
] = SCS_ZERO
,
63 [VK_COMPONENT_SWIZZLE_ONE
] = SCS_ONE
,
64 [VK_COMPONENT_SWIZZLE_R
] = SCS_RED
,
65 [VK_COMPONENT_SWIZZLE_G
] = SCS_GREEN
,
66 [VK_COMPONENT_SWIZZLE_B
] = SCS_BLUE
,
67 [VK_COMPONENT_SWIZZLE_A
] = SCS_ALPHA
71 static inline uint32_t
72 vk_to_gen_tex_filter(VkFilter filter
, bool anisotropyEnable
)
76 assert(!"Invalid filter");
77 case VK_FILTER_NEAREST
:
78 return MAPFILTER_NEAREST
;
79 case VK_FILTER_LINEAR
:
80 return anisotropyEnable
? MAPFILTER_ANISOTROPIC
: MAPFILTER_LINEAR
;
84 static inline uint32_t
85 vk_to_gen_max_anisotropy(float ratio
)
87 return (anv_clamp_f(ratio
, 2, 16) - 2) / 2;
90 static const uint32_t vk_to_gen_mipmap_mode
[] = {
91 [VK_SAMPLER_MIPMAP_MODE_NEAREST
] = MIPFILTER_NEAREST
,
92 [VK_SAMPLER_MIPMAP_MODE_LINEAR
] = MIPFILTER_LINEAR
95 static const uint32_t vk_to_gen_tex_address
[] = {
96 [VK_SAMPLER_ADDRESS_MODE_REPEAT
] = TCM_WRAP
,
97 [VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
] = TCM_MIRROR
,
98 [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
] = TCM_CLAMP
,
99 [VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
] = TCM_MIRROR_ONCE
,
100 [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
] = TCM_CLAMP_BORDER
,
103 static const uint32_t vk_to_gen_compare_op
[] = {
104 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
105 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
106 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
107 [VK_COMPARE_OP_LESS_OR_EQUAL
] = PREFILTEROPLEQUAL
,
108 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
109 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
110 [VK_COMPARE_OP_GREATER_OR_EQUAL
] = PREFILTEROPGEQUAL
,
111 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,