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
.bo
,
34 .read_domains
= I915_GEM_DOMAIN_INSTRUCTION
,
38 static inline struct blorp_address
39 instruction_state_address(struct blorp_batch
*batch
, uint32_t offset
)
41 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
42 struct brw_context
*brw
= batch
->driver_batch
;
44 return (struct blorp_address
) {
45 .buffer
= brw
->cache
.bo
,
48 .read_domains
= I915_GEM_DOMAIN_INSTRUCTION
,
52 static struct blorp_address
53 blorp_emit_vs_state(struct blorp_batch
*batch
,
54 const struct blorp_params
*params
)
56 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
57 struct brw_context
*brw
= batch
->driver_batch
;
60 blorp_emit_dynamic(batch
, GENX(VS_STATE
), vs
, 64, &offset
) {
62 vs
.URBEntryAllocationSize
= brw
->urb
.vsize
- 1;
64 vs
.NumberofURBEntries
= brw
->urb
.nr_vs_entries
>> 2;
66 vs
.NumberofURBEntries
= brw
->urb
.nr_vs_entries
;
70 return dynamic_state_address(batch
, offset
);
73 static struct blorp_address
74 blorp_emit_sf_state(struct blorp_batch
*batch
,
75 const struct blorp_params
*params
)
77 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
78 struct brw_context
*brw
= batch
->driver_batch
;
79 const struct brw_sf_prog_data
*prog_data
= params
->sf_prog_data
;
82 blorp_emit_dynamic(batch
, GENX(SF_STATE
), sf
, 64, &offset
) {
84 sf
.KernelStartPointer
=
85 instruction_state_address(batch
, params
->sf_prog_kernel
);
87 sf
.KernelStartPointer
= params
->sf_prog_kernel
;
89 sf
.GRFRegisterCount
= DIV_ROUND_UP(prog_data
->total_grf
, 16) - 1;
90 sf
.VertexURBEntryReadLength
= prog_data
->urb_read_length
;
91 sf
.VertexURBEntryReadOffset
= BRW_SF_URB_ENTRY_READ_OFFSET
;
92 sf
.DispatchGRFStartRegisterForURBData
= 3;
94 sf
.URBEntryAllocationSize
= brw
->urb
.sfsize
- 1;
95 sf
.NumberofURBEntries
= brw
->urb
.nr_sf_entries
;
98 sf
.MaximumNumberofThreads
= MIN2(48, brw
->urb
.nr_sf_entries
) - 1;
100 sf
.MaximumNumberofThreads
= MIN2(24, brw
->urb
.nr_sf_entries
) - 1;
103 sf
.ViewportTransformEnable
= false;
105 sf
.CullMode
= CULLMODE_NONE
;
108 return dynamic_state_address(batch
, offset
);
111 static struct blorp_address
112 blorp_emit_wm_state(struct blorp_batch
*batch
,
113 const struct blorp_params
*params
)
115 const struct brw_wm_prog_data
*prog_data
= params
->wm_prog_data
;
118 blorp_emit_dynamic(batch
, GENX(WM_STATE
), wm
, 64, &offset
) {
119 if (params
->src
.enabled
) {
120 /* Iron Lake can't do sampler prefetch */
121 wm
.SamplerCount
= (GEN_GEN
!= 5);
122 wm
.BindingTableEntryCount
= 2;
123 uint32_t sampler
= blorp_emit_sampler_state(batch
, params
);
124 wm
.SamplerStatePointer
= dynamic_state_address(batch
, sampler
);
128 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
129 prog_data
->base
.dispatch_grf_start_reg
;
130 wm
.SetupURBEntryReadLength
= prog_data
->num_varying_inputs
* 2;
131 wm
.SetupURBEntryReadOffset
= 0;
133 wm
.DepthCoefficientURBReadOffset
= 1;
134 wm
.PixelShaderKillsPixel
= prog_data
->uses_kill
;
135 wm
.ThreadDispatchEnable
= true;
136 wm
.EarlyDepthTestEnable
= true;
138 wm
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
139 wm
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
142 wm
.KernelStartPointer0
=
143 instruction_state_address(batch
, params
->wm_prog_kernel
);
144 wm
.GRFRegisterCount0
= prog_data
->reg_blocks_0
;
146 wm
.KernelStartPointer0
= params
->wm_prog_kernel
;
147 wm
.GRFRegisterCount0
= prog_data
->reg_blocks_0
;
148 wm
.KernelStartPointer2
=
149 params
->wm_prog_kernel
+ prog_data
->prog_offset_2
;
150 wm
.GRFRegisterCount2
= prog_data
->reg_blocks_2
;
154 wm
.MaximumNumberofThreads
=
155 batch
->blorp
->compiler
->devinfo
->max_wm_threads
- 1;
158 return dynamic_state_address(batch
, offset
);
161 static struct blorp_address
162 blorp_emit_color_calc_state(struct blorp_batch
*batch
,
163 const struct blorp_params
*params
)
165 uint32_t cc_viewport
= blorp_emit_cc_viewport(batch
, params
);
168 blorp_emit_dynamic(batch
, GENX(COLOR_CALC_STATE
), cc
, 64, &offset
) {
169 cc
.CCViewportStatePointer
= dynamic_state_address(batch
, cc_viewport
);
172 return dynamic_state_address(batch
, offset
);
176 blorp_emit_pipeline(struct blorp_batch
*batch
,
177 const struct blorp_params
*params
)
179 assert(batch
->blorp
->driver_ctx
== batch
->driver_batch
);
180 struct brw_context
*brw
= batch
->driver_batch
;
182 emit_urb_config(batch
, params
);
184 blorp_emit(batch
, GENX(3DSTATE_PIPELINED_POINTERS
), pp
) {
185 pp
.PointertoVSState
= blorp_emit_vs_state(batch
, params
);
187 pp
.ClipEnable
= false;
188 pp
.PointertoSFState
= blorp_emit_sf_state(batch
, params
);
189 pp
.PointertoWMState
= blorp_emit_wm_state(batch
, params
);
190 pp
.PointertoColorCalcState
= blorp_emit_color_calc_state(batch
, params
);
193 brw_upload_urb_fence(brw
);
195 blorp_emit(batch
, GENX(CS_URB_STATE
), curb
);
196 blorp_emit(batch
, GENX(CONSTANT_BUFFER
), curb
);