state->last_floats_per_vertex = 0;
state->last_vertex_offset = 0;
- if (sna->render.vbo != NULL &&
- !kgem_bo_is_mappable(&sna->kgem, sna->render.vbo)) {
+ if (sna->render.vbo && !kgem_bo_can_map(&sna->kgem, sna->render.vbo)) {
DBG(("%s: discarding vbo as next access will stall: %d\n",
__FUNCTION__, sna->render.vbo->presumed_offset));
discard_vbo(sna);
sna->render_state.gen4.drawrect_limit = -1;
sna->render_state.gen4.surface_table = -1;
- if (sna->render.vbo &&
- !kgem_bo_is_mappable(&sna->kgem, sna->render.vbo)) {
+ if (sna->render.vbo && !kgem_bo_can_map(&sna->kgem, sna->render.vbo)) {
DBG(("%s: discarding unmappable vbo\n", __FUNCTION__));
discard_vbo(sna);
}
sna->render_state.gen5.drawrect_limit = -1;
sna->render_state.gen5.surface_table = -1;
- if (sna->render.vbo &&
- !kgem_bo_is_mappable(&sna->kgem, sna->render.vbo)) {
+ if (sna->render.vbo && !kgem_bo_can_map(&sna->kgem, sna->render.vbo)) {
DBG(("%s: discarding unmappable vbo\n", __FUNCTION__));
discard_vbo(sna);
}
sna->render_state.gen6.drawrect_limit = -1;
sna->render_state.gen6.surface_table = -1;
- assert(sna->render.vbo == NULL ||
- kgem_bo_is_mappable(&sna->kgem, sna->render.vbo));
+ if (sna->render.vbo && !kgem_bo_can_map(&sna->kgem, sna->render.vbo)) {
+ DBG(("%s: discarding unmappable vbo\n", __FUNCTION__));
+ discard_vbo(sna);
+ }
sna->render.vertex_offset = 0;
sna->render.nvertex_reloc = 0;
sna->render_state.gen7.drawrect_limit = -1;
sna->render_state.gen7.surface_table = -1;
- if (sna->render.vbo &&
- !kgem_bo_is_mappable(&sna->kgem, sna->render.vbo)) {
+ if (sna->render.vbo && !kgem_bo_can_map(&sna->kgem, sna->render.vbo)) {
DBG(("%s: discarding unmappable vbo\n", __FUNCTION__));
discard_vbo(sna);
}
assert(bo->flush == false);
list_move(&bo->list, &kgem->inactive[bucket(bo)]);
if (bo->map__gtt) {
- if (!__kgem_bo_is_mappable(kgem, bo)) {
+ if (!kgem_bo_can_map(kgem, bo)) {
munmap(MAP(bo->map__gtt), bytes(bo));
bo->map__gtt = NULL;
}
CREATE_EXACT | CREATE_INACTIVE | CREATE_GTT_MAP);
if (old == NULL) {
old = search_linear_cache(kgem, alloc, CREATE_INACTIVE);
- if (old && !__kgem_bo_is_mappable(kgem, old)) {
+ if (old && !kgem_bo_can_map(kgem, old)) {
_kgem_bo_destroy(kgem, old);
old = NULL;
}
if (old) {
DBG(("%s: reusing handle=%d for buffer\n",
__FUNCTION__, old->handle));
- assert(__kgem_bo_is_mappable(kgem, old));
+ assert(kgem_bo_can_map(kgem, old));
assert(!old->snoop);
assert(old->rq == NULL);
return kgem_bo_blt_pitch_is_ok(kgem, bo);
}
-static inline bool __kgem_bo_is_mappable(struct kgem *kgem,
- struct kgem_bo *bo)
-{
- if (bo->domain == DOMAIN_GTT)
- return true;
-
- if (kgem->gen < 040 && bo->tiling &&
- bo->presumed_offset & (kgem_bo_fenced_size(kgem, bo) - 1))
- return false;
-
- if (kgem->gen == 021 && bo->tiling == I915_TILING_Y)
- return false;
-
- if (!bo->tiling && (kgem->has_llc || bo->domain == DOMAIN_CPU))
- return true;
-
- if (!bo->presumed_offset)
- return __kgem_bo_num_pages(bo) <= kgem->aperture_mappable / 4;
-
- return bo->presumed_offset / PAGE_SIZE + __kgem_bo_num_pages(bo) <= kgem->aperture_mappable;
-}
-
-static inline bool kgem_bo_is_mappable(struct kgem *kgem,
- struct kgem_bo *bo)
-{
- DBG(("%s: domain=%d, offset: %d size: %d\n",
- __FUNCTION__, bo->domain, bo->presumed_offset, kgem_bo_size(bo)));
- assert(bo->refcnt);
- return __kgem_bo_is_mappable(kgem, bo);
-}
-
-static inline bool kgem_bo_mapped(struct kgem *kgem, struct kgem_bo *bo)
-{
- DBG(("%s: map=%p:%p, tiling=%d, domain=%d\n",
- __FUNCTION__, bo->map__gtt, bo->map__cpu, bo->tiling, bo->domain));
- assert(bo->refcnt);
-
- if (bo->tiling == I915_TILING_NONE && (bo->domain == DOMAIN_CPU || kgem->has_llc))
- return bo->map__cpu != NULL;
-
- return bo->map__gtt != NULL;
-}
-
-static inline bool kgem_bo_can_map(struct kgem *kgem, struct kgem_bo *bo)
-{
- if (kgem_bo_mapped(kgem, bo))
- return true;
-
- if (!bo->tiling && (kgem->has_llc || bo->domain == DOMAIN_CPU))
- return true;
-
- if (kgem->gen == 021 && bo->tiling == I915_TILING_Y)
- return false;
-
- return __kgem_bo_num_pages(bo) <= kgem->aperture_mappable / 4;
-}
-
-static inline bool kgem_bo_can_map__cpu(struct kgem *kgem,
- struct kgem_bo *bo,
- bool write)
-{
- if (bo->purged || (bo->scanout && write))
- return false;
-
- if (kgem->has_llc)
- return true;
-
- if (bo->domain != DOMAIN_CPU)
- return false;
-
- return !write || bo->exec == NULL;
-}
-
static inline bool kgem_bo_is_snoop(struct kgem_bo *bo)
{
assert(bo->refcnt);
} while ((bo = bo->proxy));
}
+static inline bool kgem_bo_mapped(struct kgem *kgem, struct kgem_bo *bo)
+{
+ DBG(("%s: map=%p:%p, tiling=%d, domain=%d\n",
+ __FUNCTION__, bo->map__gtt, bo->map__cpu, bo->tiling, bo->domain));
+
+ if (bo->tiling == I915_TILING_NONE && (bo->domain == DOMAIN_CPU || kgem->has_llc))
+ return bo->map__cpu != NULL;
+
+ return bo->map__gtt != NULL;
+}
+
+static inline bool kgem_bo_can_map(struct kgem *kgem, struct kgem_bo *bo)
+{
+ DBG(("%s: map=%p:%p, tiling=%d, domain=%d, offset=%d\n",
+ __FUNCTION__, bo->map__gtt, bo->map__cpu, bo->tiling, bo->domain, bo->presumed_offset));
+
+ if (!bo->tiling && (kgem->has_llc || bo->domain == DOMAIN_CPU))
+ return true;
+
+ if (bo->map__gtt != NULL)
+ return true;
+
+ if (kgem->gen == 021 && bo->tiling == I915_TILING_Y)
+ return false;
+
+ if (!bo->presumed_offset)
+ return __kgem_bo_num_pages(bo) <= kgem->aperture_mappable / 4;
+
+ return bo->presumed_offset / PAGE_SIZE + __kgem_bo_num_pages(bo) <= kgem->aperture_mappable;
+}
+
+static inline bool kgem_bo_can_map__cpu(struct kgem *kgem,
+ struct kgem_bo *bo,
+ bool write)
+{
+ if (bo->purged || (bo->scanout && write))
+ return false;
+
+ if (kgem->has_llc)
+ return true;
+
+ if (bo->domain != DOMAIN_CPU)
+ return false;
+
+ return !write || bo->exec == NULL;
+}
+
#define KGEM_BUFFER_WRITE 0x1
#define KGEM_BUFFER_INPLACE 0x2
#define KGEM_BUFFER_LAST 0x4
{
struct sna *sna = to_sna_from_pixmap(pixmap);
struct sna_pixmap *priv = sna_pixmap(pixmap);
- unsigned create;
if (wedged(sna))
- goto done;
+ goto out;
if ((priv->create & KGEM_CAN_CREATE_GTT) == 0)
- goto done;
+ goto out;
assert_pixmap_damage(pixmap);
if (can_replace && priv->gpu_bo &&
- (!kgem_bo_is_mappable(&sna->kgem, priv->gpu_bo) ||
+ (!kgem_bo_can_map(&sna->kgem, priv->gpu_bo) ||
__kgem_bo_is_busy(&sna->kgem, priv->gpu_bo))) {
if (priv->pinned)
- goto done;
+ return false;
DBG(("%s: discard busy GPU bo\n", __FUNCTION__));
sna_pixmap_free_gpu(sna, priv);
}
- if (priv->gpu_bo)
- return kgem_bo_is_mappable(&sna->kgem, priv->gpu_bo);
+ if (priv->gpu_bo == NULL) {
+ unsigned create;
- assert_pixmap_damage(pixmap);
+ assert_pixmap_damage(pixmap);
+ assert(priv->gpu_damage == NULL);
- assert(priv->gpu_damage == NULL);
- assert(priv->gpu_bo == NULL);
+ create = CREATE_GTT_MAP | CREATE_INACTIVE;
+ if (pixmap->usage_hint == SNA_CREATE_FB)
+ create |= CREATE_SCANOUT;
- create = CREATE_GTT_MAP | CREATE_INACTIVE;
- if (pixmap->usage_hint == SNA_CREATE_FB)
- create |= CREATE_SCANOUT;
+ priv->gpu_bo =
+ kgem_create_2d(&sna->kgem,
+ pixmap->drawable.width,
+ pixmap->drawable.height,
+ pixmap->drawable.bitsPerPixel,
+ sna_pixmap_choose_tiling(pixmap, DEFAULT_TILING),
+ create);
+ }
- priv->gpu_bo =
- kgem_create_2d(&sna->kgem,
- pixmap->drawable.width,
- pixmap->drawable.height,
- pixmap->drawable.bitsPerPixel,
- sna_pixmap_choose_tiling(pixmap, DEFAULT_TILING),
- create);
+out:
+ if (priv->gpu_bo == NULL)
+ return false;
-done:
- return priv->gpu_bo && kgem_bo_is_mappable(&sna->kgem, priv->gpu_bo);
+ return (kgem_bo_can_map(&sna->kgem, priv->gpu_bo) &&
+ !kgem_bo_is_busy(priv->gpu_bo));
}
static inline bool use_cpu_bo_for_download(struct sna *sna,
/* Is it worth detiling? */
assert(box[0].y1 < box[nbox-1].y2);
- if (kgem_bo_is_mappable(&sna->kgem, priv->gpu_bo) &&
+ if (kgem_bo_can_map(&sna->kgem, priv->gpu_bo) &&
(box[nbox-1].y2 - box[0].y1 - 1) * priv->gpu_bo->pitch < 4096) {
DBG(("%s: no, tiny transfer (height=%d, pitch=%d) expect to read inplace\n",
__FUNCTION__, box[nbox-1].y2-box[0].y1, priv->gpu_bo->pitch));
if (box[n].y2 > extents.y2)
extents.y2 = box[n].y2;
}
- if (kgem_bo_is_mappable(kgem, src_bo)) {
+ if (kgem_bo_can_map(kgem, src_bo)) {
/* Is it worth detiling? */
if ((extents.y2 - extents.y1 - 1) * src_bo->pitch < 4096)
goto fallback;
goto done;
}
- if (kgem_bo_is_mappable(&sna->kgem, bo) &&
+ if (kgem_bo_can_map(&sna->kgem, bo) &&
(dst = kgem_bo_map(&sna->kgem, bo)) != NULL &&
sigtrap_get() == 0) {
memcpy_blt(src, dst, pixmap->drawable.bitsPerPixel,
}
}
- if (kgem_bo_is_mappable(&sna->kgem, bo) &&
+ if (kgem_bo_can_map(&sna->kgem, bo) &&
(dst = kgem_bo_map(&sna->kgem, bo)) != NULL &&
sigtrap_get() == 0) {
memcpy_xor(src, dst, pixmap->drawable.bitsPerPixel,