2 * Copyright © 2013 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
21 * DEALINGS IN THE SOFTWARE.
24 #include "brw_context.h"
25 #include "brw_state.h"
26 #include "brw_defines.h"
27 #include "intel_batchbuffer.h"
30 gen8_upload_gs_state(struct brw_context
*brw
)
32 struct gl_context
*ctx
= &brw
->ctx
;
33 const struct brw_stage_state
*stage_state
= &brw
->gs
.base
;
34 /* BRW_NEW_GEOMETRY_PROGRAM */
35 bool active
= brw
->geometry_program
;
36 /* BRW_NEW_GS_PROG_DATA */
37 const struct brw_vue_prog_data
*prog_data
= &brw
->gs
.prog_data
->base
;
40 int urb_entry_write_offset
= 1;
41 uint32_t urb_entry_output_length
=
42 ((prog_data
->vue_map
.num_slots
+ 1) / 2 - urb_entry_write_offset
);
44 if (urb_entry_output_length
== 0)
45 urb_entry_output_length
= 1;
48 OUT_BATCH(_3DSTATE_GS
<< 16 | (10 - 2));
49 OUT_BATCH(stage_state
->prog_offset
);
51 OUT_BATCH(brw
->geometry_program
->VerticesIn
|
52 ((ALIGN(stage_state
->sampler_count
, 4)/4) <<
53 GEN6_GS_SAMPLER_COUNT_SHIFT
) |
54 ((prog_data
->base
.binding_table
.size_bytes
/ 4) <<
55 GEN6_GS_BINDING_TABLE_ENTRY_COUNT_SHIFT
));
57 if (brw
->gs
.prog_data
->base
.base
.total_scratch
) {
58 OUT_RELOC64(stage_state
->scratch_bo
,
59 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
60 ffs(brw
->gs
.prog_data
->base
.base
.total_scratch
) - 11);
67 OUT_BATCH(((brw
->gs
.prog_data
->output_vertex_size_hwords
* 2 - 1) <<
68 GEN7_GS_OUTPUT_VERTEX_SIZE_SHIFT
) |
69 (brw
->gs
.prog_data
->output_topology
<<
70 GEN7_GS_OUTPUT_TOPOLOGY_SHIFT
) |
71 (prog_data
->urb_read_length
<<
72 GEN6_GS_URB_READ_LENGTH_SHIFT
) |
73 (0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT
) |
74 (prog_data
->base
.dispatch_grf_start_reg
<<
75 GEN6_GS_DISPATCH_START_GRF_SHIFT
));
77 uint32_t dw7
= (brw
->gs
.prog_data
->control_data_header_size_hwords
<<
78 GEN7_GS_CONTROL_DATA_HEADER_SIZE_SHIFT
) |
79 SET_FIELD(prog_data
->dispatch_mode
,
80 GEN7_GS_DISPATCH_MODE
) |
81 ((brw
->gs
.prog_data
->invocations
- 1) <<
82 GEN7_GS_INSTANCE_CONTROL_SHIFT
) |
83 GEN6_GS_STATISTICS_ENABLE
|
84 (brw
->gs
.prog_data
->include_primitive_id
?
85 GEN7_GS_INCLUDE_PRIMITIVE_ID
: 0) |
86 GEN7_GS_REORDER_TRAILING
|
88 uint32_t dw8
= brw
->gs
.prog_data
->control_data_format
<<
89 HSW_GS_CONTROL_DATA_FORMAT_SHIFT
;
92 dw7
|= (brw
->max_gs_threads
/ 2 - 1) << HSW_GS_MAX_THREADS_SHIFT
;
94 dw8
|= brw
->max_gs_threads
- 1;
102 /* DW9 / _NEW_TRANSFORM */
103 OUT_BATCH((ctx
->Transform
.ClipPlanesEnabled
<<
104 GEN8_GS_USER_CLIP_DISTANCE_SHIFT
) |
105 (urb_entry_output_length
<< GEN8_GS_URB_OUTPUT_LENGTH_SHIFT
) |
106 (urb_entry_write_offset
<<
107 GEN8_GS_URB_ENTRY_OUTPUT_OFFSET_SHIFT
));
111 OUT_BATCH(_3DSTATE_GS
<< 16 | (10 - 2));
112 OUT_BATCH(0); /* prog_bo */
115 OUT_BATCH(0); /* scratch space base offset */
118 OUT_BATCH(GEN6_GS_STATISTICS_ENABLE
);
125 const struct brw_tracked_state gen8_gs_state
= {
127 .mesa
= _NEW_TRANSFORM
,
128 .brw
= BRW_NEW_BATCH
|
130 BRW_NEW_GEOMETRY_PROGRAM
|
131 BRW_NEW_GS_PROG_DATA
,
133 .emit
= gen8_upload_gs_state
,