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
24 static inline struct blorp_address
25 dynamic_state_address(struct blorp_batch
*batch
, uint32_t offset
)
27 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
28 struct brw_context
*brw
= batch
->driver_batch
;
30 return (struct blorp_address
) {
31 .buffer
= brw
->batch
.state
.bo
,
36 static inline struct blorp_address
37 instruction_state_address(struct blorp_batch
*batch
, uint32_t offset
)
39 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
40 struct brw_context
*brw
= batch
->driver_batch
;
42 return (struct blorp_address
) {
43 .buffer
= brw
->cache
.bo
,
48 static struct blorp_address
49 blorp_emit_vs_state(struct blorp_batch
*batch
)
51 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
52 struct brw_context
*brw
= batch
->driver_batch
;
55 blorp_emit_dynamic(batch
, GENX(VS_STATE
), vs
, 64, &offset
) {
57 vs
.URBEntryAllocationSize
= brw
->urb
.vsize
- 1;
59 vs
.NumberofURBEntries
= brw
->urb
.nr_vs_entries
>> 2;
61 vs
.NumberofURBEntries
= brw
->urb
.nr_vs_entries
;
65 return dynamic_state_address(batch
, offset
);
68 static struct blorp_address
69 blorp_emit_sf_state(struct blorp_batch
*batch
,
70 const struct blorp_params
*params
)
72 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
73 struct brw_context
*brw
= batch
->driver_batch
;
74 const struct brw_sf_prog_data
*prog_data
= params
->sf_prog_data
;
77 blorp_emit_dynamic(batch
, GENX(SF_STATE
), sf
, 64, &offset
) {
79 sf
.KernelStartPointer
=
80 instruction_state_address(batch
, params
->sf_prog_kernel
);
82 sf
.KernelStartPointer
= params
->sf_prog_kernel
;
84 sf
.GRFRegisterCount
= DIV_ROUND_UP(prog_data
->total_grf
, 16) - 1;
85 sf
.VertexURBEntryReadLength
= prog_data
->urb_read_length
;
86 sf
.VertexURBEntryReadOffset
= BRW_SF_URB_ENTRY_READ_OFFSET
;
87 sf
.DispatchGRFStartRegisterForURBData
= 3;
89 sf
.URBEntryAllocationSize
= brw
->urb
.sfsize
- 1;
90 sf
.NumberofURBEntries
= brw
->urb
.nr_sf_entries
;
93 sf
.MaximumNumberofThreads
= MIN2(48, brw
->urb
.nr_sf_entries
) - 1;
95 sf
.MaximumNumberofThreads
= MIN2(24, brw
->urb
.nr_sf_entries
) - 1;
98 sf
.ViewportTransformEnable
= false;
100 sf
.CullMode
= CULLMODE_NONE
;
103 return dynamic_state_address(batch
, offset
);
106 static struct blorp_address
107 blorp_emit_wm_state(struct blorp_batch
*batch
,
108 const struct blorp_params
*params
)
110 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
113 blorp_emit_dynamic(batch
, GENX(WM_STATE
), wm
, 64, &offset
) {
114 if (params
->src
.enabled
) {
115 /* Iron Lake can't do sampler prefetch */
116 wm
.SamplerCount
= (GEN_GEN
!= 5);
117 wm
.BindingTableEntryCount
= 2;
118 uint32_t sampler
= blorp_emit_sampler_state(batch
);
119 wm
.SamplerStatePointer
= dynamic_state_address(batch
, sampler
);
123 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
124 prog_data
->base
.dispatch_grf_start_reg
;
125 wm
.SetupURBEntryReadLength
= prog_data
->num_varying_inputs
* 2;
126 wm
.SetupURBEntryReadOffset
= 0;
128 wm
.DepthCoefficientURBReadOffset
= 1;
129 wm
.PixelShaderKillsPixel
= prog_data
->uses_kill
;
130 wm
.ThreadDispatchEnable
= true;
131 wm
.EarlyDepthTestEnable
= true;
133 wm
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
134 wm
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
137 wm
.KernelStartPointer0
=
138 instruction_state_address(batch
, params
->wm_prog_kernel
);
139 wm
.GRFRegisterCount0
= brw_wm_prog_data_reg_blocks(prog_data
, wm
, 0);
141 wm
.KernelStartPointer0
= params
->wm_prog_kernel
+
142 brw_wm_prog_data_prog_offset(prog_data
, wm
, 0);
143 wm
.KernelStartPointer1
= params
->wm_prog_kernel
+
144 brw_wm_prog_data_prog_offset(prog_data
, wm
, 1);
145 wm
.KernelStartPointer2
= params
->wm_prog_kernel
+
146 brw_wm_prog_data_prog_offset(prog_data
, wm
, 2);
147 wm
.GRFRegisterCount0
= brw_wm_prog_data_reg_blocks(prog_data
, wm
, 0);
148 wm
.GRFRegisterCount1
= brw_wm_prog_data_reg_blocks(prog_data
, wm
, 1);
149 wm
.GRFRegisterCount2
= brw_wm_prog_data_reg_blocks(prog_data
, wm
, 2);
153 wm
.MaximumNumberofThreads
=
154 batch
->blorp
->compiler
->devinfo
->max_wm_threads
- 1;
157 return dynamic_state_address(batch
, offset
);
160 static struct blorp_address
161 blorp_emit_color_calc_state(struct blorp_batch
*batch
)
163 uint32_t cc_viewport
= blorp_emit_cc_viewport(batch
);
166 blorp_emit_dynamic(batch
, GENX(COLOR_CALC_STATE
), cc
, 64, &offset
) {
167 cc
.CCViewportStatePointer
= dynamic_state_address(batch
, cc_viewport
);
170 return dynamic_state_address(batch
, offset
);
174 blorp_emit_pipeline(struct blorp_batch
*batch
,
175 const struct blorp_params
*params
)
177 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
178 struct brw_context
*brw
= batch
->driver_batch
;
180 emit_urb_config(batch
, params
);
182 blorp_emit(batch
, GENX(3DSTATE_PIPELINED_POINTERS
), pp
) {
183 pp
.PointertoVSState
= blorp_emit_vs_state(batch
);
185 pp
.ClipEnable
= false;
186 pp
.PointertoSFState
= blorp_emit_sf_state(batch
, params
);
187 pp
.PointertoWMState
= blorp_emit_wm_state(batch
, params
);
188 pp
.PointertoColorCalcState
= blorp_emit_color_calc_state(batch
);
191 brw_upload_urb_fence(brw
);
193 blorp_emit(batch
, GENX(CS_URB_STATE
), curb
);
194 blorp_emit(batch
, GENX(CONSTANT_BUFFER
), curb
);