2 * Copyright 2016 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
26 #define __gen_address_type uint64_t
27 #define __gen_user_data void
30 __gen_combine_address(__attribute__((unused
)) void *data
,
31 __attribute__((unused
)) void *loc
, uint64_t addr
,
37 #include "genxml/gen_macros.h"
38 #include "genxml/genX_pack.h"
43 static const uint8_t isl_to_gen_halign
[] = {
49 static const uint8_t isl_to_gen_halign
[] = {
56 static const uint8_t isl_to_gen_valign
[] = {
62 static const uint8_t isl_to_gen_valign
[] = {
69 static const uint8_t isl_to_gen_tiling
[] = {
70 [ISL_TILING_LINEAR
] = LINEAR
,
71 [ISL_TILING_X
] = XMAJOR
,
72 [ISL_TILING_Y0
] = YMAJOR
,
73 [ISL_TILING_Yf
] = YMAJOR
,
74 [ISL_TILING_Ys
] = YMAJOR
,
75 [ISL_TILING_W
] = WMAJOR
,
80 static const uint32_t isl_to_gen_multisample_layout
[] = {
81 [ISL_MSAA_LAYOUT_NONE
] = MSFMT_MSS
,
82 [ISL_MSAA_LAYOUT_INTERLEAVED
] = MSFMT_DEPTH_STENCIL
,
83 [ISL_MSAA_LAYOUT_ARRAY
] = MSFMT_MSS
,
88 static const uint32_t isl_to_gen_aux_mode
[] = {
89 [ISL_AUX_USAGE_NONE
] = AUX_NONE
,
90 [ISL_AUX_USAGE_HIZ
] = AUX_HIZ
,
91 [ISL_AUX_USAGE_MCS
] = AUX_CCS_D
,
92 [ISL_AUX_USAGE_CCS_D
] = AUX_CCS_D
,
93 [ISL_AUX_USAGE_CCS_E
] = AUX_CCS_E
,
96 static const uint32_t isl_to_gen_aux_mode
[] = {
97 [ISL_AUX_USAGE_NONE
] = AUX_NONE
,
98 [ISL_AUX_USAGE_HIZ
] = AUX_HIZ
,
99 [ISL_AUX_USAGE_MCS
] = AUX_MCS
,
100 [ISL_AUX_USAGE_CCS_D
] = AUX_MCS
,
105 get_surftype(enum isl_surf_dim dim
, isl_surf_usage_flags_t usage
)
109 unreachable("bad isl_surf_dim");
110 case ISL_SURF_DIM_1D
:
111 assert(!(usage
& ISL_SURF_USAGE_CUBE_BIT
));
113 case ISL_SURF_DIM_2D
:
114 if ((usage
& ISL_SURF_USAGE_CUBE_BIT
) &&
115 (usage
& ISL_SURF_USAGE_TEXTURE_BIT
)) {
116 /* We need SURFTYPE_CUBE to make cube sampling work */
117 return SURFTYPE_CUBE
;
119 /* Everything else (render and storage) treat cubes as plain
124 case ISL_SURF_DIM_3D
:
125 assert(!(usage
& ISL_SURF_USAGE_CUBE_BIT
));
131 * Get the horizontal and vertical alignment in the units expected by the
132 * hardware. Note that this does NOT give you the actual hardware enum values
133 * but an index into the isl_to_gen_[hv]align arrays above.
135 UNUSED
static struct isl_extent3d
136 get_image_alignment(const struct isl_surf
*surf
)
139 if (isl_tiling_is_std_y(surf
->tiling
) ||
140 surf
->dim_layout
== ISL_DIM_LAYOUT_GEN9_1D
) {
141 /* The hardware ignores the alignment values. Anyway, the surface's
142 * true alignment is likely outside the enum range of HALIGN* and
145 return isl_extent3d(4, 4, 1);
147 /* In Skylake, RENDER_SUFFACE_STATE.SurfaceVerticalAlignment is in units
148 * of surface elements (not pixels nor samples). For compressed formats,
149 * a "surface element" is defined as a compression block. For example,
150 * if SurfaceVerticalAlignment is VALIGN_4 and SurfaceFormat is an ETC2
151 * format (ETC2 has a block height of 4), then the vertical alignment is
152 * 4 compression blocks or, equivalently, 16 pixels.
154 return isl_surf_get_image_alignment_el(surf
);
157 /* Pre-Skylake, RENDER_SUFFACE_STATE.SurfaceVerticalAlignment is in
158 * units of surface samples. For example, if SurfaceVerticalAlignment
159 * is VALIGN_4 and the surface is singlesampled, then for any surface
160 * format (compressed or not) the vertical alignment is
163 return isl_surf_get_image_alignment_sa(surf
);
169 get_qpitch(const struct isl_surf
*surf
)
171 switch (surf
->dim_layout
) {
173 unreachable("Bad isl_surf_dim");
174 case ISL_DIM_LAYOUT_GEN4_2D
:
176 if (surf
->dim
== ISL_SURF_DIM_3D
&& surf
->tiling
== ISL_TILING_W
) {
177 /* This is rather annoying and completely undocumented. It
178 * appears that the hardware has a bug (or undocumented feature)
179 * regarding stencil buffers most likely related to the way
180 * W-tiling is handled as modified Y-tiling. If you bind a 3-D
181 * stencil buffer normally, and use texelFetch on it, the z or
182 * array index will get implicitly multiplied by 2 for no obvious
183 * reason. The fix appears to be to divide qpitch by 2 for
186 return isl_surf_get_array_pitch_el_rows(surf
) / 2;
188 return isl_surf_get_array_pitch_el_rows(surf
);
191 /* From the Broadwell PRM for RENDER_SURFACE_STATE.QPitch
193 * "This field must be set to an integer multiple of the Surface
194 * Vertical Alignment. For compressed textures (BC*, FXT1,
195 * ETC*, and EAC* Surface Formats), this field is in units of
196 * rows in the uncompressed surface, and must be set to an
197 * integer multiple of the vertical alignment parameter "j"
198 * defined in the Common Surface Formats section."
200 return isl_surf_get_array_pitch_sa_rows(surf
);
202 case ISL_DIM_LAYOUT_GEN9_1D
:
203 /* QPitch is usually expressed as rows of surface elements (where
204 * a surface element is an compression block or a single surface
205 * sample). Skylake 1D is an outlier.
207 * From the Skylake BSpec >> Memory Views >> Common Surface
208 * Formats >> Surface Layout and Tiling >> 1D Surfaces:
210 * Surface QPitch specifies the distance in pixels between array
213 return isl_surf_get_array_pitch_el(surf
);
214 case ISL_DIM_LAYOUT_GEN4_3D
:
215 /* QPitch doesn't make sense for ISL_DIM_LAYOUT_GEN4_3D since it uses a
216 * different pitch at each LOD. Also, the QPitch field is ignored for
217 * these surfaces. From the Broadwell PRM documentation for QPitch:
219 * This field specifies the distance in rows between array slices. It
220 * is used only in the following cases:
221 * - Surface Array is enabled OR
222 * - Number of Mulitsamples is not NUMSAMPLES_1 and Multisampled
223 * Surface Storage Format set to MSFMT_MSS OR
224 * - Surface Type is SURFTYPE_CUBE
226 * None of the three conditions above can possibly apply to a 3D surface
227 * so it is safe to just set QPitch to 0.
232 #endif /* GEN_GEN >= 8 */
235 isl_genX(surf_fill_state_s
)(const struct isl_device
*dev
, void *state
,
236 const struct isl_surf_fill_state_info
*restrict info
)
238 struct GENX(RENDER_SURFACE_STATE
) s
= { 0 };
240 s
.SurfaceType
= get_surftype(info
->surf
->dim
, info
->view
->usage
);
242 if (info
->view
->usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
)
243 assert(isl_format_supports_rendering(dev
->info
, info
->view
->format
));
244 else if (info
->view
->usage
& ISL_SURF_USAGE_TEXTURE_BIT
)
245 assert(isl_format_supports_sampling(dev
->info
, info
->view
->format
));
247 /* From the Sky Lake PRM Vol. 2d, RENDER_SURFACE_STATE::SurfaceFormat
249 * This field cannot be a compressed (BC*, DXT*, FXT*, ETC*, EAC*)
250 * format if the Surface Type is SURFTYPE_1D
252 if (info
->surf
->dim
== ISL_SURF_DIM_1D
)
253 assert(!isl_format_is_compressed(info
->view
->format
));
255 if (isl_format_is_compressed(info
->surf
->format
)) {
256 /* You're not allowed to make a view of a compressed format with any
257 * format other than the surface format. None of the userspace APIs
258 * allow for this directly and doing so would mess up a number of
259 * surface parameters such as Width, Height, and alignments. Ideally,
260 * we'd like to assert that the two formats match. However, we have an
261 * S3TC workaround that requires us to do reinterpretation. So assert
262 * that they're at least the same bpb and block size.
264 ASSERTED
const struct isl_format_layout
*surf_fmtl
=
265 isl_format_get_layout(info
->surf
->format
);
266 ASSERTED
const struct isl_format_layout
*view_fmtl
=
267 isl_format_get_layout(info
->surf
->format
);
268 assert(surf_fmtl
->bpb
== view_fmtl
->bpb
);
269 assert(surf_fmtl
->bw
== view_fmtl
->bw
);
270 assert(surf_fmtl
->bh
== view_fmtl
->bh
);
273 s
.SurfaceFormat
= info
->view
->format
;
276 s
.ColorBufferComponentWriteDisables
= info
->write_disables
;
278 assert(info
->write_disables
== 0);
282 s
.IntegerSurfaceFormat
=
283 isl_format_has_int_channel((enum isl_format
) s
.SurfaceFormat
);
286 assert(info
->surf
->logical_level0_px
.width
> 0 &&
287 info
->surf
->logical_level0_px
.height
> 0);
289 s
.Width
= info
->surf
->logical_level0_px
.width
- 1;
290 s
.Height
= info
->surf
->logical_level0_px
.height
- 1;
292 /* In the gen6 PRM Volume 1 Part 1: Graphics Core, Section 7.18.3.7.1
293 * (Surface Arrays For all surfaces other than separate stencil buffer):
295 * "[DevSNB] Errata: Sampler MSAA Qpitch will be 4 greater than the value
296 * calculated in the equation above , for every other odd Surface Height
297 * starting from 1 i.e. 1,5,9,13"
299 * Since this Qpitch errata only impacts the sampler, we have to adjust the
300 * input for the rendering surface to achieve the same qpitch. For the
301 * affected heights, we increment the height by 1 for the rendering
304 if (GEN_GEN
== 6 && (info
->view
->usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
) &&
305 info
->surf
->samples
> 1 &&
306 (info
->surf
->logical_level0_px
.height
% 4) == 1)
309 switch (s
.SurfaceType
) {
312 /* From the Ivy Bridge PRM >> RENDER_SURFACE_STATE::MinimumArrayElement:
314 * "If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
315 * must be set to zero if this surface is used with sampling engine
318 * This restriction appears to exist only on Ivy Bridge.
320 if (GEN_GEN
== 7 && !GEN_IS_HASWELL
&& !ISL_DEV_IS_BAYTRAIL(dev
) &&
321 (info
->view
->usage
& ISL_SURF_USAGE_TEXTURE_BIT
) &&
322 info
->surf
->samples
> 1)
323 assert(info
->view
->base_array_layer
== 0);
325 s
.MinimumArrayElement
= info
->view
->base_array_layer
;
327 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
329 * For SURFTYPE_1D, 2D, and CUBE: The range of this field is reduced
330 * by one for each increase from zero of Minimum Array Element. For
331 * example, if Minimum Array Element is set to 1024 on a 2D surface,
332 * the range of this field is reduced to [0,1023].
334 * In other words, 'Depth' is the number of array layers.
336 s
.Depth
= info
->view
->array_len
- 1;
338 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
340 * For Render Target and Typed Dataport 1D and 2D Surfaces:
341 * This field must be set to the same value as the Depth field.
343 if (info
->view
->usage
& (ISL_SURF_USAGE_RENDER_TARGET_BIT
|
344 ISL_SURF_USAGE_STORAGE_BIT
))
345 s
.RenderTargetViewExtent
= s
.Depth
;
348 s
.MinimumArrayElement
= info
->view
->base_array_layer
;
349 /* Same as SURFTYPE_2D, but divided by 6 */
350 s
.Depth
= info
->view
->array_len
/ 6 - 1;
351 if (info
->view
->usage
& (ISL_SURF_USAGE_RENDER_TARGET_BIT
|
352 ISL_SURF_USAGE_STORAGE_BIT
))
353 s
.RenderTargetViewExtent
= s
.Depth
;
356 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::Depth:
358 * If the volume texture is MIP-mapped, this field specifies the
359 * depth of the base MIP level.
361 s
.Depth
= info
->surf
->logical_level0_px
.depth
- 1;
363 /* From the Broadwell PRM >> RENDER_SURFACE_STATE::RenderTargetViewExtent:
365 * For Render Target and Typed Dataport 3D Surfaces: This field
366 * indicates the extent of the accessible 'R' coordinates minus 1 on
367 * the LOD currently being rendered to.
369 * The docs specify that this only matters for render targets and
370 * surfaces used with typed dataport messages. Prior to Ivy Bridge, the
371 * Depth field has more bits than RenderTargetViewExtent so we can have
372 * textures with more levels than we can render to. In order to prevent
373 * assert-failures in the packing function below, we only set the field
374 * when it's actually going to be used by the hardware.
376 * Similaraly, the MinimumArrayElement field is ignored by all hardware
377 * prior to Sky Lake when texturing and we want it set to 0 anyway.
378 * Since it's already initialized to 0, we can just leave it alone for
381 if (info
->view
->usage
& (ISL_SURF_USAGE_RENDER_TARGET_BIT
|
382 ISL_SURF_USAGE_STORAGE_BIT
)) {
383 s
.MinimumArrayElement
= info
->view
->base_array_layer
;
384 s
.RenderTargetViewExtent
= info
->view
->array_len
- 1;
388 unreachable("bad SurfaceType");
392 s
.SurfaceArray
= info
->surf
->dim
!= ISL_SURF_DIM_3D
;
395 if (info
->view
->usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
) {
396 /* For render target surfaces, the hardware interprets field
397 * MIPCount/LOD as LOD. The Broadwell PRM says:
399 * MIPCountLOD defines the LOD that will be rendered into.
400 * SurfaceMinLOD is ignored.
402 s
.MIPCountLOD
= info
->view
->base_level
;
405 /* For non render target surfaces, the hardware interprets field
406 * MIPCount/LOD as MIPCount. The range of levels accessible by the
407 * sampler engine is [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
409 s
.SurfaceMinLOD
= info
->view
->base_level
;
410 s
.MIPCountLOD
= MAX(info
->view
->levels
, 1) - 1;
414 /* We don't use miptails yet. The PRM recommends that you set "Mip Tail
415 * Start LOD" to 15 to prevent the hardware from trying to use them.
417 s
.TiledResourceMode
= NONE
;
418 s
.MipTailStartLOD
= 15;
422 const struct isl_extent3d image_align
= get_image_alignment(info
->surf
);
423 s
.SurfaceVerticalAlignment
= isl_to_gen_valign
[image_align
.height
];
425 s
.SurfaceHorizontalAlignment
= isl_to_gen_halign
[image_align
.width
];
429 if (info
->surf
->dim_layout
== ISL_DIM_LAYOUT_GEN9_1D
) {
430 /* For gen9 1-D textures, surface pitch is ignored */
433 s
.SurfacePitch
= info
->surf
->row_pitch_B
- 1;
437 s
.SurfaceQPitch
= get_qpitch(info
->surf
) >> 2;
439 s
.SurfaceArraySpacing
= info
->surf
->array_pitch_span
==
440 ISL_ARRAY_PITCH_SPAN_COMPACT
;
444 s
.TileMode
= isl_to_gen_tiling
[info
->surf
->tiling
];
446 s
.TiledSurface
= info
->surf
->tiling
!= ISL_TILING_LINEAR
,
447 s
.TileWalk
= info
->surf
->tiling
== ISL_TILING_Y0
? TILEWALK_YMAJOR
:
452 s
.RenderCacheReadWriteMode
= WriteOnlyCache
;
454 s
.RenderCacheReadWriteMode
= 0;
458 s
.EnableUnormPathInColorPipe
= true;
461 s
.CubeFaceEnablePositiveZ
= 1;
462 s
.CubeFaceEnableNegativeZ
= 1;
463 s
.CubeFaceEnablePositiveY
= 1;
464 s
.CubeFaceEnableNegativeY
= 1;
465 s
.CubeFaceEnablePositiveX
= 1;
466 s
.CubeFaceEnableNegativeX
= 1;
469 s
.NumberofMultisamples
= ffs(info
->surf
->samples
) - 1;
471 s
.MultisampledSurfaceStorageFormat
=
472 isl_to_gen_multisample_layout
[info
->surf
->msaa_layout
];
476 #if (GEN_GEN >= 8 || GEN_IS_HASWELL)
477 if (info
->view
->usage
& ISL_SURF_USAGE_RENDER_TARGET_BIT
)
478 assert(isl_swizzle_supports_rendering(dev
->info
, info
->view
->swizzle
));
480 s
.ShaderChannelSelectRed
= (enum GENX(ShaderChannelSelect
)) info
->view
->swizzle
.r
;
481 s
.ShaderChannelSelectGreen
= (enum GENX(ShaderChannelSelect
)) info
->view
->swizzle
.g
;
482 s
.ShaderChannelSelectBlue
= (enum GENX(ShaderChannelSelect
)) info
->view
->swizzle
.b
;
483 s
.ShaderChannelSelectAlpha
= (enum GENX(ShaderChannelSelect
)) info
->view
->swizzle
.a
;
485 assert(isl_swizzle_is_identity(info
->view
->swizzle
));
488 s
.SurfaceBaseAddress
= info
->address
;
494 #if GEN_GEN > 4 || GEN_IS_G4X
495 if (info
->x_offset_sa
!= 0 || info
->y_offset_sa
!= 0) {
496 /* There are fairly strict rules about when the offsets can be used.
497 * These are mostly taken from the Sky Lake PRM documentation for
498 * RENDER_SURFACE_STATE.
500 assert(info
->surf
->tiling
!= ISL_TILING_LINEAR
);
501 assert(info
->surf
->dim
== ISL_SURF_DIM_2D
);
502 assert(isl_is_pow2(isl_format_get_layout(info
->view
->format
)->bpb
));
503 assert(info
->surf
->levels
== 1);
504 assert(info
->surf
->logical_level0_px
.array_len
== 1);
505 assert(info
->aux_usage
== ISL_AUX_USAGE_NONE
);
508 /* Broadwell added more rules. */
509 assert(info
->surf
->samples
== 1);
510 if (isl_format_get_layout(info
->view
->format
)->bpb
== 8)
511 assert(info
->x_offset_sa
% 16 == 0);
512 if (isl_format_get_layout(info
->view
->format
)->bpb
== 16)
513 assert(info
->x_offset_sa
% 8 == 0);
517 s
.SurfaceArray
= false;
521 const unsigned x_div
= 4;
522 const unsigned y_div
= GEN_GEN
>= 8 ? 4 : 2;
523 assert(info
->x_offset_sa
% x_div
== 0);
524 assert(info
->y_offset_sa
% y_div
== 0);
525 s
.XOffset
= info
->x_offset_sa
/ x_div
;
526 s
.YOffset
= info
->y_offset_sa
/ y_div
;
528 assert(info
->x_offset_sa
== 0);
529 assert(info
->y_offset_sa
== 0);
533 if (info
->aux_surf
&& info
->aux_usage
!= ISL_AUX_USAGE_NONE
) {
534 /* The docs don't appear to say anything whatsoever about compression
535 * and the data port. Testing seems to indicate that the data port
536 * completely ignores the AuxiliarySurfaceMode field.
538 assert(!(info
->view
->usage
& ISL_SURF_USAGE_STORAGE_BIT
));
540 struct isl_tile_info tile_info
;
541 isl_surf_get_tile_info(info
->aux_surf
, &tile_info
);
542 uint32_t pitch_in_tiles
=
543 info
->aux_surf
->row_pitch_B
/ tile_info
.phys_extent_B
.width
;
545 s
.AuxiliarySurfaceBaseAddress
= info
->aux_address
;
546 s
.AuxiliarySurfacePitch
= pitch_in_tiles
- 1;
549 assert(GEN_GEN
>= 9 || info
->aux_usage
!= ISL_AUX_USAGE_CCS_E
);
550 /* Auxiliary surfaces in ISL have compressed formats but the hardware
551 * doesn't expect our definition of the compression, it expects qpitch
552 * in units of samples on the main surface.
554 s
.AuxiliarySurfaceQPitch
=
555 isl_surf_get_array_pitch_sa_rows(info
->aux_surf
) >> 2;
557 if (info
->aux_usage
== ISL_AUX_USAGE_HIZ
) {
558 /* The number of samples must be 1 */
559 assert(info
->surf
->samples
== 1);
561 /* The dimension must not be 3D */
562 assert(info
->surf
->dim
!= ISL_SURF_DIM_3D
);
564 /* The format must be one of the following: */
565 switch (info
->view
->format
) {
566 case ISL_FORMAT_R32_FLOAT
:
567 case ISL_FORMAT_R24_UNORM_X8_TYPELESS
:
568 case ISL_FORMAT_R16_UNORM
:
571 assert(!"Incompatible HiZ Sampling format");
576 s
.AuxiliarySurfaceMode
= isl_to_gen_aux_mode
[info
->aux_usage
];
578 assert(info
->aux_usage
== ISL_AUX_USAGE_MCS
||
579 info
->aux_usage
== ISL_AUX_USAGE_CCS_D
);
586 /* From the CHV PRM, Volume 2d, page 321 (RENDER_SURFACE_STATE dword 0
587 * bit 9 "Sampler L2 Bypass Mode Disable" Programming Notes):
589 * This bit must be set for the following surface types: BC2_UNORM
590 * BC3_UNORM BC5_UNORM BC5_SNORM BC7_UNORM
592 if (GEN_GEN
>= 9 || dev
->info
->is_cherryview
) {
593 switch (info
->view
->format
) {
594 case ISL_FORMAT_BC2_UNORM
:
595 case ISL_FORMAT_BC3_UNORM
:
596 case ISL_FORMAT_BC5_UNORM
:
597 case ISL_FORMAT_BC5_SNORM
:
598 case ISL_FORMAT_BC7_UNORM
:
599 s
.SamplerL2BypassModeDisable
= true;
602 /* From the SKL PRM, Programming Note under Sampler Output Channel
605 * If a surface has an associated HiZ Auxilliary surface, the
606 * Sampler L2 Bypass Mode Disable field in the RENDER_SURFACE_STATE
609 if (GEN_GEN
>= 9 && info
->aux_usage
== ISL_AUX_USAGE_HIZ
)
610 s
.SamplerL2BypassModeDisable
= true;
616 if (info
->aux_usage
!= ISL_AUX_USAGE_NONE
) {
617 if (info
->use_clear_address
) {
619 s
.ClearValueAddressEnable
= true;
620 s
.ClearValueAddress
= info
->clear_address
;
622 unreachable("Gen9 and earlier do not support indirect clear colors");
628 * From BXML > GT > Shared Functions > vol5c Shared Functions >
629 * [Structure] RENDER_SURFACE_STATE [BDW+] > ClearColorConversionEnable:
633 * "Enables Pixel backend hw to convert clear values into native format
634 * and write back to clear address, so that display and sampler can use
635 * the converted value for resolving fast cleared RTs."
638 * Clear color conversion must be enabled if the clear color is stored
639 * indirectly and fast color clears are enabled.
641 if (info
->use_clear_address
) {
642 s
.ClearColorConversionEnable
= true;
647 if (!info
->use_clear_address
) {
648 s
.RedClearColor
= info
->clear_color
.u32
[0];
649 s
.GreenClearColor
= info
->clear_color
.u32
[1];
650 s
.BlueClearColor
= info
->clear_color
.u32
[2];
651 s
.AlphaClearColor
= info
->clear_color
.u32
[3];
654 /* Prior to Sky Lake, we only have one bit for the clear color which
655 * gives us 0 or 1 in whatever the surface's format happens to be.
657 if (isl_format_has_int_channel(info
->view
->format
)) {
658 for (unsigned i
= 0; i
< 4; i
++) {
659 assert(info
->clear_color
.u32
[i
] == 0 ||
660 info
->clear_color
.u32
[i
] == 1);
662 s
.RedClearColor
= info
->clear_color
.u32
[0] != 0;
663 s
.GreenClearColor
= info
->clear_color
.u32
[1] != 0;
664 s
.BlueClearColor
= info
->clear_color
.u32
[2] != 0;
665 s
.AlphaClearColor
= info
->clear_color
.u32
[3] != 0;
667 for (unsigned i
= 0; i
< 4; i
++) {
668 assert(info
->clear_color
.f32
[i
] == 0.0f
||
669 info
->clear_color
.f32
[i
] == 1.0f
);
671 s
.RedClearColor
= info
->clear_color
.f32
[0] != 0.0f
;
672 s
.GreenClearColor
= info
->clear_color
.f32
[1] != 0.0f
;
673 s
.BlueClearColor
= info
->clear_color
.f32
[2] != 0.0f
;
674 s
.AlphaClearColor
= info
->clear_color
.f32
[3] != 0.0f
;
679 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
, &s
);
683 isl_genX(buffer_fill_state_s
)(void *state
,
684 const struct isl_buffer_fill_state_info
*restrict info
)
686 uint64_t buffer_size
= info
->size_B
;
688 /* Uniform and Storage buffers need to have surface size not less that the
689 * aligned 32-bit size of the buffer. To calculate the array lenght on
690 * unsized arrays in StorageBuffer the last 2 bits store the padding size
691 * added to the surface, so we can calculate latter the original buffer
692 * size to know the number of elements.
694 * surface_size = isl_align(buffer_size, 4) +
695 * (isl_align(buffer_size) - buffer_size)
697 * buffer_size = (surface_size & ~3) - (surface_size & 3)
699 if (info
->format
== ISL_FORMAT_RAW
||
700 info
->stride_B
< isl_format_get_layout(info
->format
)->bpb
/ 8) {
701 assert(info
->stride_B
== 1);
702 uint64_t aligned_size
= isl_align(buffer_size
, 4);
703 buffer_size
= aligned_size
+ (aligned_size
- buffer_size
);
706 uint32_t num_elements
= buffer_size
/ info
->stride_B
;
709 /* From the IVB PRM, SURFACE_STATE::Height,
711 * For typed buffer and structured buffer surfaces, the number
712 * of entries in the buffer ranges from 1 to 2^27. For raw buffer
713 * surfaces, the number of entries in the buffer is the number of bytes
714 * which can range from 1 to 2^30.
716 if (info
->format
== ISL_FORMAT_RAW
) {
717 assert(num_elements
<= (1ull << 30));
718 assert(num_elements
> 0);
720 assert(num_elements
<= (1ull << 27));
723 assert(num_elements
<= (1ull << 27));
726 struct GENX(RENDER_SURFACE_STATE
) s
= { 0, };
728 s
.SurfaceType
= SURFTYPE_BUFFER
;
729 s
.SurfaceFormat
= info
->format
;
732 s
.SurfaceVerticalAlignment
= isl_to_gen_valign
[4];
734 s
.SurfaceHorizontalAlignment
= isl_to_gen_halign
[4];
735 s
.SurfaceArray
= false;
740 s
.Height
= ((num_elements
- 1) >> 7) & 0x3fff;
741 s
.Width
= (num_elements
- 1) & 0x7f;
742 s
.Depth
= ((num_elements
- 1) >> 21) & 0x3ff;
744 s
.Height
= ((num_elements
- 1) >> 7) & 0x1fff;
745 s
.Width
= (num_elements
- 1) & 0x7f;
746 s
.Depth
= ((num_elements
- 1) >> 20) & 0x7f;
749 s
.SurfacePitch
= info
->stride_B
- 1;
752 s
.NumberofMultisamples
= MULTISAMPLECOUNT_1
;
758 s
.TiledSurface
= false;
762 s
.RenderCacheReadWriteMode
= WriteOnlyCache
;
764 s
.RenderCacheReadWriteMode
= 0;
768 s
.EnableUnormPathInColorPipe
= true;
771 s
.SurfaceBaseAddress
= info
->address
;
776 #if (GEN_GEN >= 8 || GEN_IS_HASWELL)
777 s
.ShaderChannelSelectRed
= (enum GENX(ShaderChannelSelect
)) info
->swizzle
.r
;
778 s
.ShaderChannelSelectGreen
= (enum GENX(ShaderChannelSelect
)) info
->swizzle
.g
;
779 s
.ShaderChannelSelectBlue
= (enum GENX(ShaderChannelSelect
)) info
->swizzle
.b
;
780 s
.ShaderChannelSelectAlpha
= (enum GENX(ShaderChannelSelect
)) info
->swizzle
.a
;
783 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
, &s
);
787 isl_genX(null_fill_state
)(void *state
, struct isl_extent3d size
)
789 struct GENX(RENDER_SURFACE_STATE
) s
= {
790 .SurfaceType
= SURFTYPE_NULL
,
791 .SurfaceFormat
= ISL_FORMAT_B8G8R8A8_UNORM
,
793 .SurfaceArray
= size
.depth
> 0,
798 .TiledSurface
= true,
799 .TileWalk
= TILEWALK_YMAJOR
,
801 .Width
= size
.width
- 1,
802 .Height
= size
.height
- 1,
803 .Depth
= size
.depth
- 1,
804 .RenderTargetViewExtent
= size
.depth
- 1,
806 .ColorBufferComponentWriteDisables
= 0xf,
809 GENX(RENDER_SURFACE_STATE_pack
)(NULL
, state
, &s
);