summaryrefslogtreecommitdiffstats
path: root/src/vulkan/isl_gen8.c
blob: fe118cae000327d47bd8376e2c3596b49b8162a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * Copyright 2015 Intel Corporation
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a
 *  copy of this software and associated documentation files (the "Software"),
 *  to deal in the Software without restriction, including without limitation
 *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
 *  and/or sell copies of the Software, and to permit persons to whom the
 *  Software is furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice (including the next
 *  paragraph) shall be included in all copies or substantial portions of the
 *  Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 *  IN THE SOFTWARE.
 */

#include "isl_gen8.h"
#include "isl_priv.h"

bool
gen8_choose_msaa_layout(const struct isl_device *dev,
                        const struct isl_surf_init_info *info,
                        enum isl_tiling tiling,
                        enum isl_msaa_layout *msaa_layout)
{
   bool require_array = false;
   bool require_interleaved = false;

   assert(info->samples >= 1);

   if (info->samples == 1) {
      *msaa_layout = ISL_MSAA_LAYOUT_NONE;
      return true;
   }

   /* From the Broadwell PRM >> Volume2d: Command Structures >>
    * RENDER_SURFACE_STATE Tile Mode:
    *
    *    - If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
    *      must be YMAJOR.
    *
    * As usual, though, stencil is special.
    */
   if (!isl_tiling_is_std_y(tiling) && !isl_surf_usage_is_stencil(info->usage))
      return false;

   /* From the Broadwell PRM >> Volume2d: Command Structures >>
    * RENDER_SURFACE_STATE Multisampled Surface Storage Format:
    *
    *    All multisampled render target surfaces must have this field set to
    *    MSFMT_MSS
    */
   if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT)
      require_array = true;

   /* From the Broadwell PRM >> Volume2d: Command Structures >>
    * RENDER_SURFACE_STATE Number of Multisamples:
    *
    *    - If this field is any value other than MULTISAMPLECOUNT_1, the
    *      Surface Type must be SURFTYPE_2D This field must be set to
    *      MULTISAMPLECOUNT_1 unless the surface is a Sampling Engine surface
    *      or Render Target surface.
    *
    *    - If this field is any value other than MULTISAMPLECOUNT_1, Surface
    *      Min LOD, Mip Count / LOD, and Resource Min LOD must be set to zero.
    */
   if (info->dim != ISL_SURF_DIM_2D)
      return false;
   if (info->levels > 1)
      return false;

   /* More obvious restrictions */
   if (isl_surf_usage_is_display(info->usage))
      return false;
   if (isl_format_is_compressed(info->format))
      return false;
   if (isl_format_is_yuv(info->format))
      return false;

   if (isl_surf_usage_is_depth_or_stencil(info->usage))
      require_interleaved = true;

   if (require_array && require_interleaved)
      return false;

   if (require_interleaved) {
      *msaa_layout = ISL_MSAA_LAYOUT_INTERLEAVED;
      return true;
   }

   *msaa_layout = ISL_MSAA_LAYOUT_ARRAY;
   return true;
}

/**
 * Choose horizontal LOD alignment, in units of surface elements.
 */
static uint32_t
gen8_choose_halign_el(const struct isl_device *dev,
                      const struct isl_surf_init_info *restrict info)
{
   if (isl_format_is_compressed(info->format))
      return 1;

   /* From the Broadwell PRM, Volume 2d "Command Reference: Structures",
    * RENDER_SURFACE_STATE Surface Horizontal Alignment, p326:
    *
    *    - This field is intended to be set to HALIGN_8 only if the surface
    *      was rendered as a depth buffer with Z16 format or a stencil buffer.
    *      In this case it must be set to HALIGN_8 since these surfaces
    *      support only alignment of 8. [...]
    */
   if (isl_surf_info_is_z16(info))
      return 8;
   if (isl_surf_usage_is_stencil(info->usage))
      return 8;

   /* From the Broadwell PRM, Volume 2d "Command Reference: Structures",
    * RENDER_SURFACE_STATE Surface Horizontal Alignment, p326:
    *
    *      [...] For Z32 formats it must be set to HALIGN_4.
    */
   if (isl_surf_usage_is_depth(info->usage))
      return 4;

   if (!(info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)) {
      /* From the Broadwell PRM, Volume 2d "Command Reference: Structures",
       * RENDER_SURFACE_STATE Surface Horizontal Alignment, p326:
       *
       *    - When Auxiliary Surface Mode is set to AUX_CCS_D or AUX_CCS_E,
       *      HALIGN 16 must be used.
       *
       * This case handles color surfaces that may own an auxiliary MCS, CCS_D,
       * or CCS_E. Depth buffers, including those that own an auxiliary HiZ
       * surface, are handled above and do not require HALIGN_16.
       */
      assert(!isl_surf_usage_is_depth(info->usage));
      return 16;
   }

   /* XXX(chadv): I believe the hardware requires each image to be
    * cache-aligned. If that's true, then defaulting to halign=4 is wrong for
    * many formats. Depending on the format's block size, we may need to
    * increase halign to 8.
    */
   return 4;
}

/**
 * Choose vertical LOD alignment, in units of surface elements.
 */
static uint32_t
gen8_choose_valign_el(const struct isl_device *dev,
                      const struct isl_surf_init_info *restrict info)
{
   /* From the Broadwell PRM > Volume 2d: Command Reference: Structures
    * > RENDER_SURFACE_STATE Surface Vertical Alignment (p325):
    *
    *    - For Sampling Engine and Render Target Surfaces: This field
    *      specifies the vertical alignment requirement in elements for the
    *      surface. [...] An element is defined as a pixel in uncompresed
    *      surface formats, and as a compression block in compressed surface
    *      formats. For MSFMT_DEPTH_STENCIL type multisampled surfaces, an
    *      element is a sample.
    *
    *    - This field is intended to be set to VALIGN_4 if the surface was
    *      rendered as a depth buffer, for a multisampled (4x) render target,
    *      or for a multisampled (8x) render target, since these surfaces
    *      support only alignment of 4. Use of VALIGN_4 for other surfaces is
    *      supported, but increases memory usage.
    *
    *    - This field is intended to be set to VALIGN_8 only if the surface
    *       was rendered as a stencil buffer, since stencil buffer surfaces
    *       support only alignment of 8. If set to VALIGN_8, Surface Format
    *       must be R8_UINT.
    */

   if (isl_format_is_compressed(info->format))
      return 1;

   if (isl_surf_usage_is_stencil(info->usage))
      return 8;

   return 4;
}

void
gen8_choose_lod_alignment_el(const struct isl_device *dev,
                             const struct isl_surf_init_info *restrict info,
                             enum isl_tiling tiling,
                             enum isl_msaa_layout msaa_layout,
                             struct isl_extent3d *lod_align_el)
{
   assert(!isl_tiling_is_std_y(tiling));

   /* The below text from the Broadwell PRM provides some insight into the
    * hardware's requirements for LOD alignment.  From the Broadwell PRM >>
    * Volume 5: Memory Views >> Surface Layout >> 2D Surfaces:
    *
    *    These [2D surfaces] must adhere to the following memory organization
    *    rules:
    *
    *       - For non-compressed texture formats, each mipmap must start on an
    *         even row within the monolithic rectangular area. For
    *         1-texel-high mipmaps, this may require a row of padding below
    *         the previous mipmap. This restriction does not apply to any
    *         compressed texture formats; each subsequent (lower-res)
    *         compressed mipmap is positioned directly below the previous
    *         mipmap.
    *
    *       - Vertical alignment restrictions vary with memory tiling type:
    *         1 DWord for linear, 16-byte (DQWord) for tiled. (Note that tiled
    *         mipmaps are not required to start at the left edge of a tile
    *         row.)
    */

   *lod_align_el = (struct isl_extent3d) {
      .w = gen8_choose_halign_el(dev, info),
      .h = gen8_choose_valign_el(dev, info),
      .d = 1,
   };
}