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
30 #include "anv_private.h"
32 #include "genxml/gen_macros.h"
33 #include "genxml/genX_pack.h"
36 genX(init_device_state
)(struct anv_device
*device
)
38 GENX(MEMORY_OBJECT_CONTROL_STATE_pack
)(NULL
, &device
->default_mocs
,
41 struct anv_batch batch
;
44 batch
.start
= batch
.next
= cmds
;
45 batch
.end
= (void *) cmds
+ sizeof(cmds
);
47 anv_batch_emit(&batch
, GENX(PIPELINE_SELECT
), ps
) {
51 ps
.PipelineSelection
= _3D
;
54 anv_batch_emit(&batch
, GENX(3DSTATE_VF_STATISTICS
), vfs
)
55 vfs
.StatisticsEnable
= true;
57 anv_batch_emit(&batch
, GENX(3DSTATE_HS
), hs
);
58 anv_batch_emit(&batch
, GENX(3DSTATE_TE
), ts
);
59 anv_batch_emit(&batch
, GENX(3DSTATE_DS
), ds
);
61 anv_batch_emit(&batch
, GENX(3DSTATE_STREAMOUT
), so
);
62 anv_batch_emit(&batch
, GENX(3DSTATE_AA_LINE_PARAMETERS
), aa
);
64 anv_batch_emit(&batch
, GENX(3DSTATE_DRAWING_RECTANGLE
), rect
) {
65 rect
.ClippedDrawingRectangleYMin
= 0;
66 rect
.ClippedDrawingRectangleXMin
= 0;
67 rect
.ClippedDrawingRectangleYMax
= UINT16_MAX
;
68 rect
.ClippedDrawingRectangleXMax
= UINT16_MAX
;
69 rect
.DrawingRectangleOriginY
= 0;
70 rect
.DrawingRectangleOriginX
= 0;
74 anv_batch_emit(&batch
, GENX(3DSTATE_WM_CHROMAKEY
), ck
);
76 /* See the Vulkan 1.0 spec Table 24.1 "Standard sample locations" and
77 * VkPhysicalDeviceFeatures::standardSampleLocations.
79 anv_batch_emit(&batch
, GENX(3DSTATE_SAMPLE_PATTERN
), sp
) {
80 sp
._1xSample0XOffset
= 0.5;
81 sp
._1xSample0YOffset
= 0.5;
82 sp
._2xSample0XOffset
= 0.25;
83 sp
._2xSample0YOffset
= 0.25;
84 sp
._2xSample1XOffset
= 0.75;
85 sp
._2xSample1YOffset
= 0.75;
86 sp
._4xSample0XOffset
= 0.375;
87 sp
._4xSample0YOffset
= 0.125;
88 sp
._4xSample1XOffset
= 0.875;
89 sp
._4xSample1YOffset
= 0.375;
90 sp
._4xSample2XOffset
= 0.125;
91 sp
._4xSample2YOffset
= 0.625;
92 sp
._4xSample3XOffset
= 0.625;
93 sp
._4xSample3YOffset
= 0.875;
94 sp
._8xSample0XOffset
= 0.5625;
95 sp
._8xSample0YOffset
= 0.3125;
96 sp
._8xSample1XOffset
= 0.4375;
97 sp
._8xSample1YOffset
= 0.6875;
98 sp
._8xSample2XOffset
= 0.8125;
99 sp
._8xSample2YOffset
= 0.5625;
100 sp
._8xSample3XOffset
= 0.3125;
101 sp
._8xSample3YOffset
= 0.1875;
102 sp
._8xSample4XOffset
= 0.1875;
103 sp
._8xSample4YOffset
= 0.8125;
104 sp
._8xSample5XOffset
= 0.0625;
105 sp
._8xSample5YOffset
= 0.4375;
106 sp
._8xSample6XOffset
= 0.6875;
107 sp
._8xSample6YOffset
= 0.9375;
108 sp
._8xSample7XOffset
= 0.9375;
109 sp
._8xSample7YOffset
= 0.0625;
111 sp
._16xSample0XOffset
= 0.5625;
112 sp
._16xSample0YOffset
= 0.5625;
113 sp
._16xSample1XOffset
= 0.4375;
114 sp
._16xSample1YOffset
= 0.3125;
115 sp
._16xSample2XOffset
= 0.3125;
116 sp
._16xSample2YOffset
= 0.6250;
117 sp
._16xSample3XOffset
= 0.7500;
118 sp
._16xSample3YOffset
= 0.4375;
119 sp
._16xSample4XOffset
= 0.1875;
120 sp
._16xSample4YOffset
= 0.3750;
121 sp
._16xSample5XOffset
= 0.6250;
122 sp
._16xSample5YOffset
= 0.8125;
123 sp
._16xSample6XOffset
= 0.8125;
124 sp
._16xSample6YOffset
= 0.6875;
125 sp
._16xSample7XOffset
= 0.6875;
126 sp
._16xSample7YOffset
= 0.1875;
127 sp
._16xSample8XOffset
= 0.3750;
128 sp
._16xSample8YOffset
= 0.8750;
129 sp
._16xSample9XOffset
= 0.5000;
130 sp
._16xSample9YOffset
= 0.0625;
131 sp
._16xSample10XOffset
= 0.2500;
132 sp
._16xSample10YOffset
= 0.1250;
133 sp
._16xSample11XOffset
= 0.1250;
134 sp
._16xSample11YOffset
= 0.7500;
135 sp
._16xSample12XOffset
= 0.0000;
136 sp
._16xSample12YOffset
= 0.5000;
137 sp
._16xSample13XOffset
= 0.9375;
138 sp
._16xSample13YOffset
= 0.2500;
139 sp
._16xSample14XOffset
= 0.8750;
140 sp
._16xSample14YOffset
= 0.9375;
141 sp
._16xSample15XOffset
= 0.0625;
142 sp
._16xSample15YOffset
= 0.0000;
147 anv_batch_emit(&batch
, GENX(MI_BATCH_BUFFER_END
), bbe
);
149 assert(batch
.next
<= batch
.end
);
151 return anv_device_submit_simple_batch(device
, &batch
);
154 static inline uint32_t
155 vk_to_gen_tex_filter(VkFilter filter
, bool anisotropyEnable
)
159 assert(!"Invalid filter");
160 case VK_FILTER_NEAREST
:
161 return MAPFILTER_NEAREST
;
162 case VK_FILTER_LINEAR
:
163 return anisotropyEnable
? MAPFILTER_ANISOTROPIC
: MAPFILTER_LINEAR
;
167 static inline uint32_t
168 vk_to_gen_max_anisotropy(float ratio
)
170 return (anv_clamp_f(ratio
, 2, 16) - 2) / 2;
173 static const uint32_t vk_to_gen_mipmap_mode
[] = {
174 [VK_SAMPLER_MIPMAP_MODE_NEAREST
] = MIPFILTER_NEAREST
,
175 [VK_SAMPLER_MIPMAP_MODE_LINEAR
] = MIPFILTER_LINEAR
178 static const uint32_t vk_to_gen_tex_address
[] = {
179 [VK_SAMPLER_ADDRESS_MODE_REPEAT
] = TCM_WRAP
,
180 [VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
] = TCM_MIRROR
,
181 [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
] = TCM_CLAMP
,
182 [VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
] = TCM_MIRROR_ONCE
,
183 [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
] = TCM_CLAMP_BORDER
,
186 /* Vulkan specifies the result of shadow comparisons as:
187 * 1 if ref <op> texel,
191 * 0 if texel <op> ref,
194 * So, these look a bit strange because there's both a negation
195 * and swapping of the arguments involved.
197 static const uint32_t vk_to_gen_shadow_compare_op
[] = {
198 [VK_COMPARE_OP_NEVER
] = PREFILTEROPALWAYS
,
199 [VK_COMPARE_OP_LESS
] = PREFILTEROPLEQUAL
,
200 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPNOTEQUAL
,
201 [VK_COMPARE_OP_LESS_OR_EQUAL
] = PREFILTEROPLESS
,
202 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGEQUAL
,
203 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPEQUAL
,
204 [VK_COMPARE_OP_GREATER_OR_EQUAL
] = PREFILTEROPGREATER
,
205 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPNEVER
,
208 VkResult
genX(CreateSampler
)(
210 const VkSamplerCreateInfo
* pCreateInfo
,
211 const VkAllocationCallbacks
* pAllocator
,
214 ANV_FROM_HANDLE(anv_device
, device
, _device
);
215 struct anv_sampler
*sampler
;
217 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
219 sampler
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
220 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
222 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
224 uint32_t border_color_offset
= device
->border_colors
.offset
+
225 pCreateInfo
->borderColor
* 64;
227 struct GENX(SAMPLER_STATE
) sampler_state
= {
228 .SamplerDisable
= false,
229 .TextureBorderColorMode
= DX10OGL
,
232 .LODPreClampMode
= CLAMP_MODE_OGL
,
234 .LODPreClampEnable
= CLAMP_ENABLE_OGL
,
240 .MipModeFilter
= vk_to_gen_mipmap_mode
[pCreateInfo
->mipmapMode
],
241 .MagModeFilter
= vk_to_gen_tex_filter(pCreateInfo
->magFilter
,
242 pCreateInfo
->anisotropyEnable
),
243 .MinModeFilter
= vk_to_gen_tex_filter(pCreateInfo
->minFilter
,
244 pCreateInfo
->anisotropyEnable
),
245 .TextureLODBias
= anv_clamp_f(pCreateInfo
->mipLodBias
, -16, 15.996),
246 .AnisotropicAlgorithm
= EWAApproximation
,
247 .MinLOD
= anv_clamp_f(pCreateInfo
->minLod
, 0, 14),
248 .MaxLOD
= anv_clamp_f(pCreateInfo
->maxLod
, 0, 14),
249 .ChromaKeyEnable
= 0,
252 .ShadowFunction
= vk_to_gen_shadow_compare_op
[pCreateInfo
->compareOp
],
253 .CubeSurfaceControlMode
= OVERRIDE
,
255 .BorderColorPointer
= border_color_offset
,
258 .LODClampMagnificationMode
= MIPNONE
,
261 .MaximumAnisotropy
= vk_to_gen_max_anisotropy(pCreateInfo
->maxAnisotropy
),
262 .RAddressMinFilterRoundingEnable
= 0,
263 .RAddressMagFilterRoundingEnable
= 0,
264 .VAddressMinFilterRoundingEnable
= 0,
265 .VAddressMagFilterRoundingEnable
= 0,
266 .UAddressMinFilterRoundingEnable
= 0,
267 .UAddressMagFilterRoundingEnable
= 0,
268 .TrilinearFilterQuality
= 0,
269 .NonnormalizedCoordinateEnable
= pCreateInfo
->unnormalizedCoordinates
,
270 .TCXAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressModeU
],
271 .TCYAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressModeV
],
272 .TCZAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressModeW
],
275 GENX(SAMPLER_STATE_pack
)(NULL
, sampler
->state
, &sampler_state
);
277 *pSampler
= anv_sampler_to_handle(sampler
);