Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/intel/blorp/blorp_priv.h
7237 views
1
/*
2
* Copyright © 2012 Intel Corporation
3
*
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:
10
*
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
13
* Software.
14
*
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
21
* IN THE SOFTWARE.
22
*/
23
24
#ifndef BLORP_PRIV_H
25
#define BLORP_PRIV_H
26
27
#include <stdint.h>
28
29
#include "common/intel_measure.h"
30
#include "compiler/nir/nir.h"
31
#include "compiler/brw_compiler.h"
32
33
#include "blorp.h"
34
35
#ifdef __cplusplus
36
extern "C" {
37
#endif
38
39
/**
40
* Binding table indices used by BLORP.
41
*/
42
enum {
43
BLORP_RENDERBUFFER_BT_INDEX,
44
BLORP_TEXTURE_BT_INDEX,
45
BLORP_NUM_BT_ENTRIES
46
};
47
48
struct brw_blorp_surface_info
49
{
50
bool enabled;
51
52
struct isl_surf surf;
53
struct blorp_address addr;
54
55
struct isl_surf aux_surf;
56
struct blorp_address aux_addr;
57
enum isl_aux_usage aux_usage;
58
59
union isl_color_value clear_color;
60
struct blorp_address clear_color_addr;
61
62
struct isl_view view;
63
64
/* Z offset into a 3-D texture or slice of a 2-D array texture. */
65
float z_offset;
66
67
uint32_t tile_x_sa, tile_y_sa;
68
};
69
70
void
71
brw_blorp_surface_info_init(struct blorp_context *blorp,
72
struct brw_blorp_surface_info *info,
73
const struct blorp_surf *surf,
74
unsigned int level, float layer,
75
enum isl_format format, bool is_render_target);
76
void
77
blorp_surf_convert_to_single_slice(const struct isl_device *isl_dev,
78
struct brw_blorp_surface_info *info);
79
void
80
surf_fake_rgb_with_red(const struct isl_device *isl_dev,
81
struct brw_blorp_surface_info *info);
82
void
83
blorp_surf_convert_to_uncompressed(const struct isl_device *isl_dev,
84
struct brw_blorp_surface_info *info,
85
uint32_t *x, uint32_t *y,
86
uint32_t *width, uint32_t *height);
87
void
88
blorp_surf_fake_interleaved_msaa(const struct isl_device *isl_dev,
89
struct brw_blorp_surface_info *info);
90
void
91
blorp_surf_retile_w_to_y(const struct isl_device *isl_dev,
92
struct brw_blorp_surface_info *info);
93
94
95
struct brw_blorp_coord_transform
96
{
97
float multiplier;
98
float offset;
99
};
100
101
/**
102
* Bounding rectangle telling pixel discard which pixels are not to be
103
* touched. This is needed in when surfaces are configured as something else
104
* what they really are:
105
*
106
* - writing W-tiled stencil as Y-tiled
107
* - writing interleaved multisampled as single sampled.
108
*
109
* See blorp_nir_discard_if_outside_rect().
110
*/
111
struct brw_blorp_discard_rect
112
{
113
uint32_t x0;
114
uint32_t x1;
115
uint32_t y0;
116
uint32_t y1;
117
};
118
119
/**
120
* Grid needed for blended and scaled blits of integer formats, see
121
* blorp_nir_manual_blend_bilinear().
122
*/
123
struct brw_blorp_rect_grid
124
{
125
float x1;
126
float y1;
127
float pad[2];
128
};
129
130
struct blorp_surf_offset {
131
uint32_t x;
132
uint32_t y;
133
};
134
135
struct brw_blorp_wm_inputs
136
{
137
uint32_t clear_color[4];
138
139
struct brw_blorp_discard_rect discard_rect;
140
struct brw_blorp_rect_grid rect_grid;
141
struct brw_blorp_coord_transform coord_transform[2];
142
143
struct blorp_surf_offset src_offset;
144
struct blorp_surf_offset dst_offset;
145
146
/* (1/width, 1/height) for the source surface */
147
float src_inv_size[2];
148
149
/* Minimum layer setting works for all the textures types but texture_3d
150
* for which the setting has no effect. Use the z-coordinate instead.
151
*/
152
float src_z;
153
154
/* Pad out to an integral number of registers */
155
uint32_t pad[1];
156
};
157
158
#define BLORP_CREATE_NIR_INPUT(shader, name, type) ({ \
159
nir_variable *input = nir_variable_create((shader), nir_var_shader_in, \
160
type, #name); \
161
if ((shader)->info.stage == MESA_SHADER_FRAGMENT) \
162
input->data.interpolation = INTERP_MODE_FLAT; \
163
input->data.location = VARYING_SLOT_VAR0 + \
164
offsetof(struct brw_blorp_wm_inputs, name) / (4 * sizeof(float)); \
165
input->data.location_frac = \
166
(offsetof(struct brw_blorp_wm_inputs, name) / sizeof(float)) % 4; \
167
input; \
168
})
169
170
struct blorp_vs_inputs {
171
uint32_t base_layer;
172
uint32_t _instance_id; /* Set in hardware by SGVS */
173
uint32_t pad[2];
174
};
175
176
static inline unsigned
177
brw_blorp_get_urb_length(const struct brw_wm_prog_data *prog_data)
178
{
179
if (prog_data == NULL)
180
return 1;
181
182
/* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE
183
*
184
* read_length = ceiling((max_source_attr+1)/2)
185
*/
186
return MAX2((prog_data->num_varying_inputs + 1) / 2, 1);
187
}
188
189
struct blorp_params
190
{
191
uint32_t x0;
192
uint32_t y0;
193
uint32_t x1;
194
uint32_t y1;
195
float z;
196
uint8_t stencil_mask;
197
uint8_t stencil_ref;
198
struct brw_blorp_surface_info depth;
199
struct brw_blorp_surface_info stencil;
200
uint32_t depth_format;
201
struct brw_blorp_surface_info src;
202
struct brw_blorp_surface_info dst;
203
enum isl_aux_op hiz_op;
204
bool full_surface_hiz_op;
205
enum isl_aux_op fast_clear_op;
206
bool color_write_disable[4];
207
struct brw_blorp_wm_inputs wm_inputs;
208
struct blorp_vs_inputs vs_inputs;
209
bool dst_clear_color_as_input;
210
unsigned num_samples;
211
unsigned num_draw_buffers;
212
unsigned num_layers;
213
uint32_t vs_prog_kernel;
214
struct brw_vs_prog_data *vs_prog_data;
215
uint32_t sf_prog_kernel;
216
struct brw_sf_prog_data *sf_prog_data;
217
uint32_t wm_prog_kernel;
218
struct brw_wm_prog_data *wm_prog_data;
219
220
bool use_pre_baked_binding_table;
221
uint32_t pre_baked_binding_table_offset;
222
enum intel_measure_snapshot_type snapshot_type;
223
};
224
225
void blorp_params_init(struct blorp_params *params);
226
227
enum blorp_shader_type {
228
BLORP_SHADER_TYPE_COPY,
229
BLORP_SHADER_TYPE_BLIT,
230
BLORP_SHADER_TYPE_CLEAR,
231
BLORP_SHADER_TYPE_MCS_PARTIAL_RESOLVE,
232
BLORP_SHADER_TYPE_LAYER_OFFSET_VS,
233
BLORP_SHADER_TYPE_GFX4_SF,
234
};
235
236
struct brw_blorp_base_key
237
{
238
char name[8];
239
enum blorp_shader_type shader_type;
240
};
241
242
#define BRW_BLORP_BASE_KEY_INIT(_type) \
243
(struct brw_blorp_base_key) { \
244
.name = "blorp", \
245
.shader_type = _type, \
246
}
247
248
struct brw_blorp_blit_prog_key
249
{
250
struct brw_blorp_base_key base;
251
252
/* Number of samples per pixel that have been configured in the surface
253
* state for texturing from.
254
*/
255
unsigned tex_samples;
256
257
/* MSAA layout that has been configured in the surface state for texturing
258
* from.
259
*/
260
enum isl_msaa_layout tex_layout;
261
262
enum isl_aux_usage tex_aux_usage;
263
264
/* Actual number of samples per pixel in the source image. */
265
unsigned src_samples;
266
267
/* Actual MSAA layout used by the source image. */
268
enum isl_msaa_layout src_layout;
269
270
/* The swizzle to apply to the source in the shader */
271
struct isl_swizzle src_swizzle;
272
273
/* The format of the source if format-specific workarounds are needed
274
* and 0 (ISL_FORMAT_R32G32B32A32_FLOAT) if the destination is natively
275
* renderable.
276
*/
277
enum isl_format src_format;
278
279
/* True if the source requires normalized coordinates */
280
bool src_coords_normalized;
281
282
/* Number of samples per pixel that have been configured in the render
283
* target.
284
*/
285
unsigned rt_samples;
286
287
/* MSAA layout that has been configured in the render target. */
288
enum isl_msaa_layout rt_layout;
289
290
/* Actual number of samples per pixel in the destination image. */
291
unsigned dst_samples;
292
293
/* Actual MSAA layout used by the destination image. */
294
enum isl_msaa_layout dst_layout;
295
296
/* The swizzle to apply to the destination in the shader */
297
struct isl_swizzle dst_swizzle;
298
299
/* The format of the destination if format-specific workarounds are needed
300
* and 0 (ISL_FORMAT_R32G32B32A32_FLOAT) if the destination is natively
301
* renderable.
302
*/
303
enum isl_format dst_format;
304
305
/* Whether or not the format workarounds are a bitcast operation */
306
bool format_bit_cast;
307
308
/** True if we need to perform SINT -> UINT clamping. */
309
bool sint32_to_uint;
310
311
/** True if we need to perform UINT -> SINT clamping. */
312
bool uint32_to_sint;
313
314
/* Type of the data to be read from the texture (one of
315
* nir_type_(int|uint|float)).
316
*/
317
nir_alu_type texture_data_type;
318
319
/* True if the source image is W tiled. If true, the surface state for the
320
* source image must be configured as Y tiled, and tex_samples must be 0.
321
*/
322
bool src_tiled_w;
323
324
/* True if the destination image is W tiled. If true, the surface state
325
* for the render target must be configured as Y tiled, and rt_samples must
326
* be 0.
327
*/
328
bool dst_tiled_w;
329
330
/* True if the destination is an RGB format. If true, the surface state
331
* for the render target must be configured as red with three times the
332
* normal width. We need to do this because you cannot render to
333
* non-power-of-two formats.
334
*/
335
bool dst_rgb;
336
337
isl_surf_usage_flags_t dst_usage;
338
339
enum blorp_filter filter;
340
341
/* True if the rectangle being sent through the rendering pipeline might be
342
* larger than the destination rectangle, so the WM program should kill any
343
* pixels that are outside the destination rectangle.
344
*/
345
bool use_kill;
346
347
/**
348
* True if the WM program should be run in MSDISPMODE_PERSAMPLE with more
349
* than one sample per pixel.
350
*/
351
bool persample_msaa_dispatch;
352
353
/* True if this blit operation may involve intratile offsets on the source.
354
* In this case, we need to add the offset before texturing.
355
*/
356
bool need_src_offset;
357
358
/* True if this blit operation may involve intratile offsets on the
359
* destination. In this case, we need to add the offset to gl_FragCoord.
360
*/
361
bool need_dst_offset;
362
363
/* Scale factors between the pixel grid and the grid of samples. We're
364
* using grid of samples for bilinear filetring in multisample scaled blits.
365
*/
366
float x_scale;
367
float y_scale;
368
};
369
370
/**
371
* \name BLORP internals
372
* \{
373
*
374
* Used internally by gfx6_blorp_exec() and gfx7_blorp_exec().
375
*/
376
377
void brw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key);
378
379
const char *blorp_shader_type_to_name(enum blorp_shader_type type);
380
381
const unsigned *
382
blorp_compile_fs(struct blorp_context *blorp, void *mem_ctx,
383
struct nir_shader *nir,
384
struct brw_wm_prog_key *wm_key,
385
bool use_repclear,
386
struct brw_wm_prog_data *wm_prog_data);
387
388
const unsigned *
389
blorp_compile_vs(struct blorp_context *blorp, void *mem_ctx,
390
struct nir_shader *nir,
391
struct brw_vs_prog_data *vs_prog_data);
392
393
bool
394
blorp_ensure_sf_program(struct blorp_batch *batch,
395
struct blorp_params *params);
396
397
/** \} */
398
399
#ifdef __cplusplus
400
} /* end extern "C" */
401
#endif /* __cplusplus */
402
403
#endif /* BLORP_PRIV_H */
404
405