2 * Copyright © 2014 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 * Mika Kuoppala <mika.kuoppala@intel.com>
29 #include "intel_renderstate.h"
32 const struct intel_renderstate_rodata
*rodata
;
33 struct drm_i915_gem_object
*obj
;
39 static const struct intel_renderstate_rodata
*
40 render_state_get_rodata(const struct drm_i915_gem_request
*req
)
42 switch (INTEL_GEN(req
->i915
)) {
44 return &gen6_null_state
;
46 return &gen7_null_state
;
48 return &gen8_null_state
;
50 return &gen9_null_state
;
57 * Macro to add commands to auxiliary batch.
58 * This macro only checks for page overflow before inserting the commands,
59 * this is sufficient as the null state generator makes the final batch
60 * with two passes to build command and state separately. At this point
61 * the size of both are known and it compacts them by relocating the state
62 * right after the commands taking care of aligment so we should sufficient
63 * space below them for adding new commands.
65 #define OUT_BATCH(batch, i, val) \
67 if (WARN_ON((i) >= PAGE_SIZE / sizeof(u32))) { \
71 (batch)[(i)++] = (val); \
74 static int render_state_setup(struct render_state
*so
)
76 struct drm_device
*dev
= so
->obj
->base
.dev
;
77 const struct intel_renderstate_rodata
*rodata
= so
->rodata
;
78 const bool has_64bit_reloc
= INTEL_GEN(dev
) >= 8;
79 unsigned int i
= 0, reloc_index
= 0;
84 ret
= i915_gem_object_set_to_cpu_domain(so
->obj
, true);
88 page
= i915_gem_object_get_dirty_page(so
->obj
, 0);
91 while (i
< rodata
->batch_items
) {
92 u32 s
= rodata
->batch
[i
];
94 if (i
* 4 == rodata
->reloc
[reloc_index
]) {
95 u64 r
= s
+ so
->ggtt_offset
;
97 if (has_64bit_reloc
) {
98 if (i
+ 1 >= rodata
->batch_items
||
99 rodata
->batch
[i
+ 1] != 0) {
105 s
= upper_32_bits(r
);
114 while (i
% CACHELINE_DWORDS
)
115 OUT_BATCH(d
, i
, MI_NOOP
);
117 so
->aux_batch_offset
= i
* sizeof(u32
);
119 if (HAS_POOLED_EU(dev
)) {
121 * We always program 3x6 pool config but depending upon which
122 * subslice is disabled HW drops down to appropriate config
125 * In the below table 2x6 config always refers to
126 * fused-down version, native 2x6 is not available and can
129 * SNo subslices config eu pool configuration
130 * -----------------------------------------------------------
131 * 1 3 subslices enabled (3x6) - 0x00777000 (9+9)
132 * 2 ss0 disabled (2x6) - 0x00777000 (3+9)
133 * 3 ss1 disabled (2x6) - 0x00770000 (6+6)
134 * 4 ss2 disabled (2x6) - 0x00007000 (9+3)
136 u32 eu_pool_config
= 0x00777000;
138 OUT_BATCH(d
, i
, GEN9_MEDIA_POOL_STATE
);
139 OUT_BATCH(d
, i
, GEN9_MEDIA_POOL_ENABLE
);
140 OUT_BATCH(d
, i
, eu_pool_config
);
146 OUT_BATCH(d
, i
, MI_BATCH_BUFFER_END
);
147 so
->aux_batch_size
= (i
* sizeof(u32
)) - so
->aux_batch_offset
;
150 * Since we are sending length, we need to strictly conform to
151 * all requirements. For Gen2 this must be a multiple of 8.
153 so
->aux_batch_size
= ALIGN(so
->aux_batch_size
, 8);
157 ret
= i915_gem_object_set_to_gtt_domain(so
->obj
, false);
161 if (rodata
->reloc
[reloc_index
] != -1) {
162 DRM_ERROR("only %d relocs resolved\n", reloc_index
);
175 int i915_gem_render_state_init(struct drm_i915_gem_request
*req
)
177 struct render_state so
;
180 if (WARN_ON(req
->engine
->id
!= RCS
))
183 so
.rodata
= render_state_get_rodata(req
);
187 if (so
.rodata
->batch_items
* 4 > 4096)
190 so
.obj
= i915_gem_object_create(&req
->i915
->drm
, 4096);
192 return PTR_ERR(so
.obj
);
194 ret
= i915_gem_object_ggtt_pin(so
.obj
, NULL
, 0, 0, 0);
198 so
.ggtt_offset
= i915_gem_obj_ggtt_offset(so
.obj
);
200 ret
= render_state_setup(&so
);
204 ret
= req
->engine
->emit_bb_start(req
, so
.ggtt_offset
,
205 so
.rodata
->batch_items
* 4,
206 I915_DISPATCH_SECURE
);
210 if (so
.aux_batch_size
> 8) {
211 ret
= req
->engine
->emit_bb_start(req
,
213 so
.aux_batch_offset
),
215 I915_DISPATCH_SECURE
);
220 i915_vma_move_to_active(i915_gem_obj_to_ggtt(so
.obj
), req
, 0);
222 i915_gem_object_ggtt_unpin(so
.obj
);
224 i915_gem_object_put(so
.obj
);
This page took 0.053817 seconds and 5 git commands to generate.