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
;
38 static const struct intel_renderstate_rodata
*
39 render_state_get_rodata(const struct drm_i915_gem_request
*req
)
41 switch (INTEL_GEN(req
->i915
)) {
43 return &gen6_null_state
;
45 return &gen7_null_state
;
47 return &gen8_null_state
;
49 return &gen9_null_state
;
56 * Macro to add commands to auxiliary batch.
57 * This macro only checks for page overflow before inserting the commands,
58 * this is sufficient as the null state generator makes the final batch
59 * with two passes to build command and state separately. At this point
60 * the size of both are known and it compacts them by relocating the state
61 * right after the commands taking care of aligment so we should sufficient
62 * space below them for adding new commands.
64 #define OUT_BATCH(batch, i, val) \
66 if (WARN_ON((i) >= PAGE_SIZE / sizeof(u32))) { \
70 (batch)[(i)++] = (val); \
73 static int render_state_setup(struct render_state
*so
)
75 struct drm_device
*dev
= so
->vma
->vm
->dev
;
76 const struct intel_renderstate_rodata
*rodata
= so
->rodata
;
77 const bool has_64bit_reloc
= INTEL_GEN(dev
) >= 8;
78 unsigned int i
= 0, reloc_index
= 0;
83 ret
= i915_gem_object_set_to_cpu_domain(so
->vma
->obj
, true);
87 page
= i915_gem_object_get_dirty_page(so
->vma
->obj
, 0);
90 while (i
< rodata
->batch_items
) {
91 u32 s
= rodata
->batch
[i
];
93 if (i
* 4 == rodata
->reloc
[reloc_index
]) {
94 u64 r
= s
+ so
->vma
->node
.start
;
96 if (has_64bit_reloc
) {
97 if (i
+ 1 >= rodata
->batch_items
||
98 rodata
->batch
[i
+ 1] != 0) {
104 s
= upper_32_bits(r
);
113 while (i
% CACHELINE_DWORDS
)
114 OUT_BATCH(d
, i
, MI_NOOP
);
116 so
->aux_batch_offset
= i
* sizeof(u32
);
118 if (HAS_POOLED_EU(dev
)) {
120 * We always program 3x6 pool config but depending upon which
121 * subslice is disabled HW drops down to appropriate config
124 * In the below table 2x6 config always refers to
125 * fused-down version, native 2x6 is not available and can
128 * SNo subslices config eu pool configuration
129 * -----------------------------------------------------------
130 * 1 3 subslices enabled (3x6) - 0x00777000 (9+9)
131 * 2 ss0 disabled (2x6) - 0x00777000 (3+9)
132 * 3 ss1 disabled (2x6) - 0x00770000 (6+6)
133 * 4 ss2 disabled (2x6) - 0x00007000 (9+3)
135 u32 eu_pool_config
= 0x00777000;
137 OUT_BATCH(d
, i
, GEN9_MEDIA_POOL_STATE
);
138 OUT_BATCH(d
, i
, GEN9_MEDIA_POOL_ENABLE
);
139 OUT_BATCH(d
, i
, eu_pool_config
);
145 OUT_BATCH(d
, i
, MI_BATCH_BUFFER_END
);
146 so
->aux_batch_size
= (i
* sizeof(u32
)) - so
->aux_batch_offset
;
149 * Since we are sending length, we need to strictly conform to
150 * all requirements. For Gen2 this must be a multiple of 8.
152 so
->aux_batch_size
= ALIGN(so
->aux_batch_size
, 8);
156 ret
= i915_gem_object_set_to_gtt_domain(so
->vma
->obj
, false);
160 if (rodata
->reloc
[reloc_index
] != -1) {
161 DRM_ERROR("only %d relocs resolved\n", reloc_index
);
174 int i915_gem_render_state_init(struct drm_i915_gem_request
*req
)
176 struct render_state so
;
177 struct drm_i915_gem_object
*obj
;
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 obj
= i915_gem_object_create(&req
->i915
->drm
, 4096);
194 so
.vma
= i915_vma_create(obj
, &req
->i915
->ggtt
.base
, NULL
);
195 if (IS_ERR(so
.vma
)) {
196 ret
= PTR_ERR(so
.vma
);
200 ret
= i915_vma_pin(so
.vma
, 0, 0, PIN_GLOBAL
);
204 ret
= render_state_setup(&so
);
208 ret
= req
->engine
->emit_bb_start(req
, so
.vma
->node
.start
,
209 so
.rodata
->batch_items
* 4,
210 I915_DISPATCH_SECURE
);
214 if (so
.aux_batch_size
> 8) {
215 ret
= req
->engine
->emit_bb_start(req
,
216 (so
.vma
->node
.start
+
217 so
.aux_batch_offset
),
219 I915_DISPATCH_SECURE
);
224 i915_vma_move_to_active(so
.vma
, req
, 0);
226 i915_vma_unpin(so
.vma
);
228 i915_gem_object_put(obj
);
This page took 0.035531 seconds and 5 git commands to generate.