Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/broadcom/vulkan/v3dvx_pipeline.c
4560 views
1
/*
2
* Copyright © 2021 Raspberry Pi
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
#include "v3dv_private.h"
25
#include "broadcom/common/v3d_macros.h"
26
#include "broadcom/cle/v3dx_pack.h"
27
#include "broadcom/compiler/v3d_compiler.h"
28
29
#include "vk_format_info.h"
30
31
static uint8_t
32
blend_factor(VkBlendFactor factor, bool dst_alpha_one, bool *needs_constants)
33
{
34
switch (factor) {
35
case VK_BLEND_FACTOR_ZERO:
36
case VK_BLEND_FACTOR_ONE:
37
case VK_BLEND_FACTOR_SRC_COLOR:
38
case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
39
case VK_BLEND_FACTOR_DST_COLOR:
40
case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
41
case VK_BLEND_FACTOR_SRC_ALPHA:
42
case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
43
case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE:
44
return factor;
45
case VK_BLEND_FACTOR_CONSTANT_COLOR:
46
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
47
case VK_BLEND_FACTOR_CONSTANT_ALPHA:
48
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
49
*needs_constants = true;
50
return factor;
51
case VK_BLEND_FACTOR_DST_ALPHA:
52
return dst_alpha_one ? V3D_BLEND_FACTOR_ONE :
53
V3D_BLEND_FACTOR_DST_ALPHA;
54
case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
55
return dst_alpha_one ? V3D_BLEND_FACTOR_ZERO :
56
V3D_BLEND_FACTOR_INV_DST_ALPHA;
57
case VK_BLEND_FACTOR_SRC1_COLOR:
58
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
59
case VK_BLEND_FACTOR_SRC1_ALPHA:
60
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
61
assert(!"Invalid blend factor: dual source blending not supported.");
62
default:
63
assert(!"Unknown blend factor.");
64
}
65
66
/* Should be handled by the switch, added to avoid a "end of non-void
67
* function" error
68
*/
69
unreachable("Unknown blend factor.");
70
}
71
72
static void
73
pack_blend(struct v3dv_pipeline *pipeline,
74
const VkPipelineColorBlendStateCreateInfo *cb_info)
75
{
76
/* By default, we are not enabling blending and all color channel writes are
77
* enabled. Color write enables are independent of whether blending is
78
* enabled or not.
79
*
80
* Vulkan specifies color write masks so that bits set correspond to
81
* enabled channels. Our hardware does it the other way around.
82
*/
83
pipeline->blend.enables = 0;
84
pipeline->blend.color_write_masks = 0; /* All channels enabled */
85
86
if (!cb_info)
87
return;
88
89
assert(pipeline->subpass);
90
if (pipeline->subpass->color_count == 0)
91
return;
92
93
assert(pipeline->subpass->color_count == cb_info->attachmentCount);
94
95
pipeline->blend.needs_color_constants = false;
96
uint32_t color_write_masks = 0;
97
for (uint32_t i = 0; i < pipeline->subpass->color_count; i++) {
98
const VkPipelineColorBlendAttachmentState *b_state =
99
&cb_info->pAttachments[i];
100
101
uint32_t attachment_idx =
102
pipeline->subpass->color_attachments[i].attachment;
103
if (attachment_idx == VK_ATTACHMENT_UNUSED)
104
continue;
105
106
color_write_masks |= (~b_state->colorWriteMask & 0xf) << (4 * i);
107
108
if (!b_state->blendEnable)
109
continue;
110
111
VkAttachmentDescription *desc =
112
&pipeline->pass->attachments[attachment_idx].desc;
113
const struct v3dv_format *format = v3dX(get_format)(desc->format);
114
bool dst_alpha_one = (format->swizzle[3] == PIPE_SWIZZLE_1);
115
116
uint8_t rt_mask = 1 << i;
117
pipeline->blend.enables |= rt_mask;
118
119
v3dvx_pack(pipeline->blend.cfg[i], BLEND_CFG, config) {
120
config.render_target_mask = rt_mask;
121
122
config.color_blend_mode = b_state->colorBlendOp;
123
config.color_blend_dst_factor =
124
blend_factor(b_state->dstColorBlendFactor, dst_alpha_one,
125
&pipeline->blend.needs_color_constants);
126
config.color_blend_src_factor =
127
blend_factor(b_state->srcColorBlendFactor, dst_alpha_one,
128
&pipeline->blend.needs_color_constants);
129
130
config.alpha_blend_mode = b_state->alphaBlendOp;
131
config.alpha_blend_dst_factor =
132
blend_factor(b_state->dstAlphaBlendFactor, dst_alpha_one,
133
&pipeline->blend.needs_color_constants);
134
config.alpha_blend_src_factor =
135
blend_factor(b_state->srcAlphaBlendFactor, dst_alpha_one,
136
&pipeline->blend.needs_color_constants);
137
}
138
}
139
140
pipeline->blend.color_write_masks = color_write_masks;
141
}
142
143
/* This requires that pack_blend() had been called before so we can set
144
* the overall blend enable bit in the CFG_BITS packet.
145
*/
146
static void
147
pack_cfg_bits(struct v3dv_pipeline *pipeline,
148
const VkPipelineDepthStencilStateCreateInfo *ds_info,
149
const VkPipelineRasterizationStateCreateInfo *rs_info,
150
const VkPipelineMultisampleStateCreateInfo *ms_info)
151
{
152
assert(sizeof(pipeline->cfg_bits) == cl_packet_length(CFG_BITS));
153
154
pipeline->msaa =
155
ms_info && ms_info->rasterizationSamples > VK_SAMPLE_COUNT_1_BIT;
156
157
v3dvx_pack(pipeline->cfg_bits, CFG_BITS, config) {
158
config.enable_forward_facing_primitive =
159
rs_info ? !(rs_info->cullMode & VK_CULL_MODE_FRONT_BIT) : false;
160
161
config.enable_reverse_facing_primitive =
162
rs_info ? !(rs_info->cullMode & VK_CULL_MODE_BACK_BIT) : false;
163
164
/* Seems like the hardware is backwards regarding this setting... */
165
config.clockwise_primitives =
166
rs_info ? rs_info->frontFace == VK_FRONT_FACE_COUNTER_CLOCKWISE : false;
167
168
config.enable_depth_offset = rs_info ? rs_info->depthBiasEnable: false;
169
170
/* This is required to pass line rasterization tests in CTS while
171
* exposing, at least, a minimum of 4-bits of subpixel precision
172
* (the minimum requirement).
173
*/
174
config.line_rasterization = 1; /* perp end caps */
175
176
if (rs_info && rs_info->polygonMode != VK_POLYGON_MODE_FILL) {
177
config.direct3d_wireframe_triangles_mode = true;
178
config.direct3d_point_fill_mode =
179
rs_info->polygonMode == VK_POLYGON_MODE_POINT;
180
}
181
182
config.rasterizer_oversample_mode = pipeline->msaa ? 1 : 0;
183
184
/* From the Vulkan spec:
185
*
186
* "Provoking Vertex:
187
*
188
* The vertex in a primitive from which flat shaded attribute
189
* values are taken. This is generally the “first” vertex in the
190
* primitive, and depends on the primitive topology."
191
*
192
* First vertex is the Direct3D style for provoking vertex. OpenGL uses
193
* the last vertex by default.
194
*/
195
config.direct3d_provoking_vertex = true;
196
197
config.blend_enable = pipeline->blend.enables != 0;
198
199
/* Disable depth/stencil if we don't have a D/S attachment */
200
bool has_ds_attachment =
201
pipeline->subpass->ds_attachment.attachment != VK_ATTACHMENT_UNUSED;
202
203
if (ds_info && ds_info->depthTestEnable && has_ds_attachment) {
204
config.z_updates_enable = ds_info->depthWriteEnable;
205
config.depth_test_function = ds_info->depthCompareOp;
206
} else {
207
config.depth_test_function = VK_COMPARE_OP_ALWAYS;
208
}
209
210
/* EZ state will be updated at draw time based on bound pipeline state */
211
config.early_z_updates_enable = false;
212
config.early_z_enable = false;
213
214
config.stencil_enable =
215
ds_info ? ds_info->stencilTestEnable && has_ds_attachment: false;
216
217
pipeline->z_updates_enable = config.z_updates_enable;
218
};
219
}
220
221
static uint32_t
222
translate_stencil_op(enum pipe_stencil_op op)
223
{
224
switch (op) {
225
case VK_STENCIL_OP_KEEP:
226
return V3D_STENCIL_OP_KEEP;
227
case VK_STENCIL_OP_ZERO:
228
return V3D_STENCIL_OP_ZERO;
229
case VK_STENCIL_OP_REPLACE:
230
return V3D_STENCIL_OP_REPLACE;
231
case VK_STENCIL_OP_INCREMENT_AND_CLAMP:
232
return V3D_STENCIL_OP_INCR;
233
case VK_STENCIL_OP_DECREMENT_AND_CLAMP:
234
return V3D_STENCIL_OP_DECR;
235
case VK_STENCIL_OP_INVERT:
236
return V3D_STENCIL_OP_INVERT;
237
case VK_STENCIL_OP_INCREMENT_AND_WRAP:
238
return V3D_STENCIL_OP_INCWRAP;
239
case VK_STENCIL_OP_DECREMENT_AND_WRAP:
240
return V3D_STENCIL_OP_DECWRAP;
241
default:
242
unreachable("bad stencil op");
243
}
244
}
245
246
static void
247
pack_single_stencil_cfg(struct v3dv_pipeline *pipeline,
248
uint8_t *stencil_cfg,
249
bool is_front,
250
bool is_back,
251
const VkStencilOpState *stencil_state)
252
{
253
/* From the Vulkan spec:
254
*
255
* "Reference is an integer reference value that is used in the unsigned
256
* stencil comparison. The reference value used by stencil comparison
257
* must be within the range [0,2^s-1] , where s is the number of bits in
258
* the stencil framebuffer attachment, otherwise the reference value is
259
* considered undefined."
260
*
261
* In our case, 's' is always 8, so we clamp to that to prevent our packing
262
* functions to assert in debug mode if they see larger values.
263
*
264
* If we have dynamic state we need to make sure we set the corresponding
265
* state bits to 0, since cl_emit_with_prepacked ORs the new value with
266
* the old.
267
*/
268
const uint8_t write_mask =
269
pipeline->dynamic_state.mask & V3DV_DYNAMIC_STENCIL_WRITE_MASK ?
270
0 : stencil_state->writeMask & 0xff;
271
272
const uint8_t compare_mask =
273
pipeline->dynamic_state.mask & V3DV_DYNAMIC_STENCIL_COMPARE_MASK ?
274
0 : stencil_state->compareMask & 0xff;
275
276
const uint8_t reference =
277
pipeline->dynamic_state.mask & V3DV_DYNAMIC_STENCIL_COMPARE_MASK ?
278
0 : stencil_state->reference & 0xff;
279
280
v3dvx_pack(stencil_cfg, STENCIL_CFG, config) {
281
config.front_config = is_front;
282
config.back_config = is_back;
283
config.stencil_write_mask = write_mask;
284
config.stencil_test_mask = compare_mask;
285
config.stencil_test_function = stencil_state->compareOp;
286
config.stencil_pass_op = translate_stencil_op(stencil_state->passOp);
287
config.depth_test_fail_op = translate_stencil_op(stencil_state->depthFailOp);
288
config.stencil_test_fail_op = translate_stencil_op(stencil_state->failOp);
289
config.stencil_ref_value = reference;
290
}
291
}
292
293
static void
294
pack_stencil_cfg(struct v3dv_pipeline *pipeline,
295
const VkPipelineDepthStencilStateCreateInfo *ds_info)
296
{
297
assert(sizeof(pipeline->stencil_cfg) == 2 * cl_packet_length(STENCIL_CFG));
298
299
if (!ds_info || !ds_info->stencilTestEnable)
300
return;
301
302
if (pipeline->subpass->ds_attachment.attachment == VK_ATTACHMENT_UNUSED)
303
return;
304
305
const uint32_t dynamic_stencil_states = V3DV_DYNAMIC_STENCIL_COMPARE_MASK |
306
V3DV_DYNAMIC_STENCIL_WRITE_MASK |
307
V3DV_DYNAMIC_STENCIL_REFERENCE;
308
309
310
/* If front != back or we have dynamic stencil state we can't emit a single
311
* packet for both faces.
312
*/
313
bool needs_front_and_back = false;
314
if ((pipeline->dynamic_state.mask & dynamic_stencil_states) ||
315
memcmp(&ds_info->front, &ds_info->back, sizeof(ds_info->front)))
316
needs_front_and_back = true;
317
318
/* If the front and back configurations are the same we can emit both with
319
* a single packet.
320
*/
321
pipeline->emit_stencil_cfg[0] = true;
322
if (!needs_front_and_back) {
323
pack_single_stencil_cfg(pipeline, pipeline->stencil_cfg[0],
324
true, true, &ds_info->front);
325
} else {
326
pipeline->emit_stencil_cfg[1] = true;
327
pack_single_stencil_cfg(pipeline, pipeline->stencil_cfg[0],
328
true, false, &ds_info->front);
329
pack_single_stencil_cfg(pipeline, pipeline->stencil_cfg[1],
330
false, true, &ds_info->back);
331
}
332
}
333
334
void
335
v3dX(pipeline_pack_state)(struct v3dv_pipeline *pipeline,
336
const VkPipelineColorBlendStateCreateInfo *cb_info,
337
const VkPipelineDepthStencilStateCreateInfo *ds_info,
338
const VkPipelineRasterizationStateCreateInfo *rs_info,
339
const VkPipelineMultisampleStateCreateInfo *ms_info)
340
{
341
pack_blend(pipeline, cb_info);
342
pack_cfg_bits(pipeline, ds_info, rs_info, ms_info);
343
pack_stencil_cfg(pipeline, ds_info);
344
}
345
346
static void
347
pack_shader_state_record(struct v3dv_pipeline *pipeline)
348
{
349
assert(sizeof(pipeline->shader_state_record) ==
350
cl_packet_length(GL_SHADER_STATE_RECORD));
351
352
struct v3d_fs_prog_data *prog_data_fs =
353
pipeline->shared_data->variants[BROADCOM_SHADER_FRAGMENT]->prog_data.fs;
354
355
struct v3d_vs_prog_data *prog_data_vs =
356
pipeline->shared_data->variants[BROADCOM_SHADER_VERTEX]->prog_data.vs;
357
358
struct v3d_vs_prog_data *prog_data_vs_bin =
359
pipeline->shared_data->variants[BROADCOM_SHADER_VERTEX_BIN]->prog_data.vs;
360
361
362
/* Note: we are not packing addresses, as we need the job (see
363
* cl_pack_emit_reloc). Additionally uniforms can't be filled up at this
364
* point as they depend on dynamic info that can be set after create the
365
* pipeline (like viewport), . Would need to be filled later, so we are
366
* doing a partial prepacking.
367
*/
368
v3dvx_pack(pipeline->shader_state_record, GL_SHADER_STATE_RECORD, shader) {
369
shader.enable_clipping = true;
370
371
if (!pipeline->has_gs) {
372
shader.point_size_in_shaded_vertex_data =
373
pipeline->topology == PIPE_PRIM_POINTS;
374
} else {
375
struct v3d_gs_prog_data *prog_data_gs =
376
pipeline->shared_data->variants[BROADCOM_SHADER_GEOMETRY]->prog_data.gs;
377
shader.point_size_in_shaded_vertex_data = prog_data_gs->writes_psiz;
378
}
379
380
/* Must be set if the shader modifies Z, discards, or modifies
381
* the sample mask. For any of these cases, the fragment
382
* shader needs to write the Z value (even just discards).
383
*/
384
shader.fragment_shader_does_z_writes = prog_data_fs->writes_z;
385
/* Set if the EZ test must be disabled (due to shader side
386
* effects and the early_z flag not being present in the
387
* shader).
388
*/
389
shader.turn_off_early_z_test = prog_data_fs->disable_ez;
390
391
shader.fragment_shader_uses_real_pixel_centre_w_in_addition_to_centroid_w2 =
392
prog_data_fs->uses_center_w;
393
394
/* The description for gl_SampleID states that if a fragment shader reads
395
* it, then we should automatically activate per-sample shading. However,
396
* the Vulkan spec also states that if a framebuffer has no attachments:
397
*
398
* "The subpass continues to use the width, height, and layers of the
399
* framebuffer to define the dimensions of the rendering area, and the
400
* rasterizationSamples from each pipeline’s
401
* VkPipelineMultisampleStateCreateInfo to define the number of
402
* samples used in rasterization multisample rasterization."
403
*
404
* So in this scenario, if the pipeline doesn't enable multiple samples
405
* but the fragment shader accesses gl_SampleID we would be requested
406
* to do per-sample shading in single sample rasterization mode, which
407
* is pointless, so just disable it in that case.
408
*/
409
shader.enable_sample_rate_shading =
410
pipeline->sample_rate_shading ||
411
(pipeline->msaa && prog_data_fs->force_per_sample_msaa);
412
413
shader.any_shader_reads_hardware_written_primitive_id = false;
414
415
shader.do_scoreboard_wait_on_first_thread_switch =
416
prog_data_fs->lock_scoreboard_on_first_thrsw;
417
shader.disable_implicit_point_line_varyings =
418
!prog_data_fs->uses_implicit_point_line_varyings;
419
420
shader.number_of_varyings_in_fragment_shader =
421
prog_data_fs->num_inputs;
422
423
shader.coordinate_shader_propagate_nans = true;
424
shader.vertex_shader_propagate_nans = true;
425
shader.fragment_shader_propagate_nans = true;
426
427
/* Note: see previous note about adresses */
428
/* shader.coordinate_shader_code_address */
429
/* shader.vertex_shader_code_address */
430
/* shader.fragment_shader_code_address */
431
432
/* FIXME: Use combined input/output size flag in the common case (also
433
* on v3d, see v3dx_draw).
434
*/
435
shader.coordinate_shader_has_separate_input_and_output_vpm_blocks =
436
prog_data_vs_bin->separate_segments;
437
shader.vertex_shader_has_separate_input_and_output_vpm_blocks =
438
prog_data_vs->separate_segments;
439
440
shader.coordinate_shader_input_vpm_segment_size =
441
prog_data_vs_bin->separate_segments ?
442
prog_data_vs_bin->vpm_input_size : 1;
443
shader.vertex_shader_input_vpm_segment_size =
444
prog_data_vs->separate_segments ?
445
prog_data_vs->vpm_input_size : 1;
446
447
shader.coordinate_shader_output_vpm_segment_size =
448
prog_data_vs_bin->vpm_output_size;
449
shader.vertex_shader_output_vpm_segment_size =
450
prog_data_vs->vpm_output_size;
451
452
/* Note: see previous note about adresses */
453
/* shader.coordinate_shader_uniforms_address */
454
/* shader.vertex_shader_uniforms_address */
455
/* shader.fragment_shader_uniforms_address */
456
457
shader.min_coord_shader_input_segments_required_in_play =
458
pipeline->vpm_cfg_bin.As;
459
shader.min_vertex_shader_input_segments_required_in_play =
460
pipeline->vpm_cfg.As;
461
462
shader.min_coord_shader_output_segments_required_in_play_in_addition_to_vcm_cache_size =
463
pipeline->vpm_cfg_bin.Ve;
464
shader.min_vertex_shader_output_segments_required_in_play_in_addition_to_vcm_cache_size =
465
pipeline->vpm_cfg.Ve;
466
467
shader.coordinate_shader_4_way_threadable =
468
prog_data_vs_bin->base.threads == 4;
469
shader.vertex_shader_4_way_threadable =
470
prog_data_vs->base.threads == 4;
471
shader.fragment_shader_4_way_threadable =
472
prog_data_fs->base.threads == 4;
473
474
shader.coordinate_shader_start_in_final_thread_section =
475
prog_data_vs_bin->base.single_seg;
476
shader.vertex_shader_start_in_final_thread_section =
477
prog_data_vs->base.single_seg;
478
shader.fragment_shader_start_in_final_thread_section =
479
prog_data_fs->base.single_seg;
480
481
shader.vertex_id_read_by_coordinate_shader =
482
prog_data_vs_bin->uses_vid;
483
shader.base_instance_id_read_by_coordinate_shader =
484
prog_data_vs_bin->uses_biid;
485
shader.instance_id_read_by_coordinate_shader =
486
prog_data_vs_bin->uses_iid;
487
shader.vertex_id_read_by_vertex_shader =
488
prog_data_vs->uses_vid;
489
shader.base_instance_id_read_by_vertex_shader =
490
prog_data_vs->uses_biid;
491
shader.instance_id_read_by_vertex_shader =
492
prog_data_vs->uses_iid;
493
494
/* Note: see previous note about adresses */
495
/* shader.address_of_default_attribute_values */
496
}
497
}
498
499
static void
500
pack_vcm_cache_size(struct v3dv_pipeline *pipeline)
501
{
502
assert(sizeof(pipeline->vcm_cache_size) ==
503
cl_packet_length(VCM_CACHE_SIZE));
504
505
v3dvx_pack(pipeline->vcm_cache_size, VCM_CACHE_SIZE, vcm) {
506
vcm.number_of_16_vertex_batches_for_binning = pipeline->vpm_cfg_bin.Vc;
507
vcm.number_of_16_vertex_batches_for_rendering = pipeline->vpm_cfg.Vc;
508
}
509
}
510
511
/* As defined on the GL_SHADER_STATE_ATTRIBUTE_RECORD */
512
static uint8_t
513
get_attr_type(const struct util_format_description *desc)
514
{
515
uint32_t r_size = desc->channel[0].size;
516
uint8_t attr_type = ATTRIBUTE_FLOAT;
517
518
switch (desc->channel[0].type) {
519
case UTIL_FORMAT_TYPE_FLOAT:
520
if (r_size == 32) {
521
attr_type = ATTRIBUTE_FLOAT;
522
} else {
523
assert(r_size == 16);
524
attr_type = ATTRIBUTE_HALF_FLOAT;
525
}
526
break;
527
528
case UTIL_FORMAT_TYPE_SIGNED:
529
case UTIL_FORMAT_TYPE_UNSIGNED:
530
switch (r_size) {
531
case 32:
532
attr_type = ATTRIBUTE_INT;
533
break;
534
case 16:
535
attr_type = ATTRIBUTE_SHORT;
536
break;
537
case 10:
538
attr_type = ATTRIBUTE_INT2_10_10_10;
539
break;
540
case 8:
541
attr_type = ATTRIBUTE_BYTE;
542
break;
543
default:
544
fprintf(stderr,
545
"format %s unsupported\n",
546
desc->name);
547
attr_type = ATTRIBUTE_BYTE;
548
abort();
549
}
550
break;
551
552
default:
553
fprintf(stderr,
554
"format %s unsupported\n",
555
desc->name);
556
abort();
557
}
558
559
return attr_type;
560
}
561
562
static void
563
pack_shader_state_attribute_record(struct v3dv_pipeline *pipeline,
564
uint32_t index,
565
const VkVertexInputAttributeDescription *vi_desc)
566
{
567
const uint32_t packet_length =
568
cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD);
569
570
const struct util_format_description *desc =
571
vk_format_description(vi_desc->format);
572
573
uint32_t binding = vi_desc->binding;
574
575
v3dvx_pack(&pipeline->vertex_attrs[index * packet_length],
576
GL_SHADER_STATE_ATTRIBUTE_RECORD, attr) {
577
578
/* vec_size == 0 means 4 */
579
attr.vec_size = desc->nr_channels & 3;
580
attr.signed_int_type = (desc->channel[0].type ==
581
UTIL_FORMAT_TYPE_SIGNED);
582
attr.normalized_int_type = desc->channel[0].normalized;
583
attr.read_as_int_uint = desc->channel[0].pure_integer;
584
585
attr.instance_divisor = MIN2(pipeline->vb[binding].instance_divisor,
586
0xffff);
587
attr.stride = pipeline->vb[binding].stride;
588
attr.type = get_attr_type(desc);
589
}
590
}
591
592
void
593
v3dX(pipeline_pack_compile_state)(struct v3dv_pipeline *pipeline,
594
const VkPipelineVertexInputStateCreateInfo *vi_info)
595
{
596
pack_shader_state_record(pipeline);
597
pack_vcm_cache_size(pipeline);
598
599
pipeline->vb_count = vi_info->vertexBindingDescriptionCount;
600
for (uint32_t i = 0; i < vi_info->vertexBindingDescriptionCount; i++) {
601
const VkVertexInputBindingDescription *desc =
602
&vi_info->pVertexBindingDescriptions[i];
603
604
pipeline->vb[desc->binding].stride = desc->stride;
605
pipeline->vb[desc->binding].instance_divisor = desc->inputRate;
606
}
607
608
pipeline->va_count = 0;
609
struct v3d_vs_prog_data *prog_data_vs =
610
pipeline->shared_data->variants[BROADCOM_SHADER_VERTEX]->prog_data.vs;
611
612
for (uint32_t i = 0; i < vi_info->vertexAttributeDescriptionCount; i++) {
613
const VkVertexInputAttributeDescription *desc =
614
&vi_info->pVertexAttributeDescriptions[i];
615
uint32_t location = desc->location + VERT_ATTRIB_GENERIC0;
616
617
/* We use a custom driver_location_map instead of
618
* nir_find_variable_with_location because if we were able to get the
619
* shader variant from the cache, we would not have the nir shader
620
* available.
621
*/
622
uint32_t driver_location =
623
prog_data_vs->driver_location_map[location];
624
625
if (driver_location != -1) {
626
assert(driver_location < MAX_VERTEX_ATTRIBS);
627
pipeline->va[driver_location].offset = desc->offset;
628
pipeline->va[driver_location].binding = desc->binding;
629
pipeline->va[driver_location].vk_format = desc->format;
630
631
pack_shader_state_attribute_record(pipeline, driver_location, desc);
632
633
pipeline->va_count++;
634
}
635
}
636
}
637
638