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 "gen7_pack.h"
33 #include "gen75_pack.h"
35 #include "genX_state_util.h"
37 GENX_FUNC(GEN7
, GEN75
) void
38 genX(fill_buffer_surface_state
)(void *state
, enum isl_format format
,
39 uint32_t offset
, uint32_t range
,
42 uint32_t num_elements
= range
/ stride
;
44 struct GENX(RENDER_SURFACE_STATE
) surface_state
= {
45 .SurfaceType
= SURFTYPE_BUFFER
,
46 .SurfaceFormat
= format
,
47 .SurfaceVerticalAlignment
= VALIGN_4
,
48 .SurfaceHorizontalAlignment
= HALIGN_4
,
49 .TiledSurface
= false,
50 .RenderCacheReadWriteMode
= false,
51 .SurfaceObjectControlState
= GENX(MOCS
),
52 .Height
= (num_elements
>> 7) & 0x3fff,
53 .Width
= num_elements
& 0x7f,
54 .Depth
= (num_elements
>> 21) & 0x3f,
55 .SurfacePitch
= stride
- 1,
57 .ShaderChannelSelectR
= SCS_RED
,
58 .ShaderChannelSelectG
= SCS_GREEN
,
59 .ShaderChannelSelectB
= SCS_BLUE
,
60 .ShaderChannelSelectA
= SCS_ALPHA
,
62 .SurfaceBaseAddress
= { NULL
, offset
},
65 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
, &surface_state
);
68 static struct anv_state
69 alloc_surface_state(struct anv_device
*device
,
70 struct anv_cmd_buffer
*cmd_buffer
)
73 return anv_cmd_buffer_alloc_surface_state(cmd_buffer
);
75 return anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
79 VkResult
genX(CreateSampler
)(
81 const VkSamplerCreateInfo
* pCreateInfo
,
82 const VkAllocationCallbacks
* pAllocator
,
85 ANV_FROM_HANDLE(anv_device
, device
, _device
);
86 struct anv_sampler
*sampler
;
88 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
90 sampler
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
91 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
93 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
95 uint32_t filter
= vk_to_gen_tex_filter(pCreateInfo
->magFilter
,
96 pCreateInfo
->anisotropyEnable
);
98 struct GEN7_SAMPLER_STATE sampler_state
= {
99 .SamplerDisable
= false,
100 .TextureBorderColorMode
= DX10OGL
,
102 .MipModeFilter
= vk_to_gen_mipmap_mode
[pCreateInfo
->mipmapMode
],
103 .MagModeFilter
= filter
,
104 .MinModeFilter
= filter
,
105 .TextureLODBias
= pCreateInfo
->mipLodBias
* 256,
106 .AnisotropicAlgorithm
= EWAApproximation
,
107 .MinLOD
= pCreateInfo
->minLod
,
108 .MaxLOD
= pCreateInfo
->maxLod
,
109 .ChromaKeyEnable
= 0,
112 .ShadowFunction
= vk_to_gen_compare_op
[pCreateInfo
->compareOp
],
113 .CubeSurfaceControlMode
= 0,
115 .BorderColorPointer
=
116 device
->border_colors
.offset
+
117 pCreateInfo
->borderColor
* sizeof(float) * 4,
119 .MaximumAnisotropy
= vk_to_gen_max_anisotropy(pCreateInfo
->maxAnisotropy
),
120 .RAddressMinFilterRoundingEnable
= 0,
121 .RAddressMagFilterRoundingEnable
= 0,
122 .VAddressMinFilterRoundingEnable
= 0,
123 .VAddressMagFilterRoundingEnable
= 0,
124 .UAddressMinFilterRoundingEnable
= 0,
125 .UAddressMagFilterRoundingEnable
= 0,
126 .TrilinearFilterQuality
= 0,
127 .NonnormalizedCoordinateEnable
= pCreateInfo
->unnormalizedCoordinates
,
128 .TCXAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressModeU
],
129 .TCYAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressModeV
],
130 .TCZAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressModeW
],
133 GEN7_SAMPLER_STATE_pack(NULL
, sampler
->state
, &sampler_state
);
135 *pSampler
= anv_sampler_to_handle(sampler
);
140 static const uint8_t anv_halign
[] = {
145 static const uint8_t anv_valign
[] = {
150 GENX_FUNC(GEN7
, GEN75
) void
151 genX(image_view_init
)(struct anv_image_view
*iview
,
152 struct anv_device
*device
,
153 const VkImageViewCreateInfo
* pCreateInfo
,
154 struct anv_cmd_buffer
*cmd_buffer
)
156 ANV_FROM_HANDLE(anv_image
, image
, pCreateInfo
->image
);
158 const VkImageSubresourceRange
*range
= &pCreateInfo
->subresourceRange
;
160 struct anv_surface
*surface
=
161 anv_image_get_surface_for_aspect_mask(image
, range
->aspectMask
);
163 if (pCreateInfo
->viewType
!= VK_IMAGE_VIEW_TYPE_2D
)
164 anv_finishme("non-2D image views");
167 if (range
->layerCount
> 1) {
168 depth
= range
->layerCount
;
169 } else if (image
->extent
.depth
> 1) {
170 depth
= image
->extent
.depth
;
173 const struct isl_extent3d image_align_sa
=
174 isl_surf_get_image_alignment_sa(&surface
->isl
);
176 struct GENX(RENDER_SURFACE_STATE
) surface_state
= {
177 .SurfaceType
= anv_surftype(image
, pCreateInfo
->viewType
, false),
178 .SurfaceArray
= image
->array_size
> 1,
179 .SurfaceFormat
= iview
->format
,
180 .SurfaceVerticalAlignment
= anv_valign
[image_align_sa
.height
],
181 .SurfaceHorizontalAlignment
= anv_halign
[image_align_sa
.width
],
183 /* From bspec (DevSNB, DevIVB): "Set Tile Walk to TILEWALK_XMAJOR if
184 * Tiled Surface is False."
186 .TiledSurface
= surface
->isl
.tiling
!= ISL_TILING_LINEAR
,
187 .TileWalk
= surface
->isl
.tiling
== ISL_TILING_Y0
?
188 TILEWALK_YMAJOR
: TILEWALK_XMAJOR
,
190 .VerticalLineStride
= 0,
191 .VerticalLineStrideOffset
= 0,
193 .RenderCacheReadWriteMode
= 0, /* TEMPLATE */
195 .Height
= image
->extent
.height
- 1,
196 .Width
= image
->extent
.width
- 1,
198 .SurfacePitch
= surface
->isl
.row_pitch
- 1,
199 .MinimumArrayElement
= range
->baseArrayLayer
,
200 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
204 .SurfaceObjectControlState
= GENX(MOCS
),
206 .MIPCountLOD
= 0, /* TEMPLATE */
207 .SurfaceMinLOD
= 0, /* TEMPLATE */
210 # if (ANV_IS_HASWELL)
211 .ShaderChannelSelectR
= vk_to_gen_swizzle(pCreateInfo
->components
.r
,
212 VK_COMPONENT_SWIZZLE_R
),
213 .ShaderChannelSelectG
= vk_to_gen_swizzle(pCreateInfo
->components
.g
,
214 VK_COMPONENT_SWIZZLE_G
),
215 .ShaderChannelSelectB
= vk_to_gen_swizzle(pCreateInfo
->components
.b
,
216 VK_COMPONENT_SWIZZLE_B
),
217 .ShaderChannelSelectA
= vk_to_gen_swizzle(pCreateInfo
->components
.a
,
218 VK_COMPONENT_SWIZZLE_A
),
219 # else /* XXX: Seriously? */
221 .GreenClearColor
= 0,
223 .AlphaClearColor
= 0,
225 .ResourceMinLOD
= 0.0,
226 .SurfaceBaseAddress
= { NULL
, iview
->offset
},
229 if (image
->needs_nonrt_surface_state
) {
230 iview
->nonrt_surface_state
= alloc_surface_state(device
, cmd_buffer
);
232 surface_state
.RenderCacheReadWriteMode
= false;
234 /* For non render target surfaces, the hardware interprets field
235 * MIPCount/LOD as MIPCount. The range of levels accessible by the
236 * sampler engine is [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
238 surface_state
.SurfaceMinLOD
= range
->baseMipLevel
;
239 surface_state
.MIPCountLOD
= MAX2(range
->levelCount
, 1) - 1;
241 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, iview
->nonrt_surface_state
.map
,
244 if (!device
->info
.has_llc
)
245 anv_state_clflush(iview
->nonrt_surface_state
);
247 iview
->nonrt_surface_state
.alloc_size
= 0;
250 if (image
->needs_color_rt_surface_state
) {
251 iview
->color_rt_surface_state
= alloc_surface_state(device
, cmd_buffer
);
253 surface_state
.RenderCacheReadWriteMode
= 0; /* Write only */
255 /* For render target surfaces, the hardware interprets field MIPCount/LOD as
256 * LOD. The Broadwell PRM says:
258 * MIPCountLOD defines the LOD that will be rendered into.
259 * SurfaceMinLOD is ignored.
261 surface_state
.MIPCountLOD
= range
->baseMipLevel
;
262 surface_state
.SurfaceMinLOD
= 0;
264 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, iview
->color_rt_surface_state
.map
,
266 if (!device
->info
.has_llc
)
267 anv_state_clflush(iview
->color_rt_surface_state
);
269 iview
->color_rt_surface_state
.alloc_size
= 0;
272 if (image
->needs_storage_surface_state
) {
273 iview
->storage_surface_state
= alloc_surface_state(device
, cmd_buffer
);
275 surface_state
.SurfaceType
=
276 anv_surftype(image
, pCreateInfo
->viewType
, true),
278 surface_state
.SurfaceFormat
=
279 isl_lower_storage_image_format(&device
->isl_dev
, iview
->format
);
281 surface_state
.SurfaceMinLOD
= range
->baseMipLevel
;
282 surface_state
.MIPCountLOD
= MAX2(range
->levelCount
, 1) - 1;
284 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, iview
->storage_surface_state
.map
,
287 iview
->storage_surface_state
.alloc_size
= 0;