ilo: add ilo_fence.h to core
Implement pipe_fence_handle on top of ilo_fence.
This commit is contained in:
@@ -4,6 +4,7 @@ C_SOURCES := \
|
|||||||
core/ilo_debug.h \
|
core/ilo_debug.h \
|
||||||
core/ilo_dev.c \
|
core/ilo_dev.c \
|
||||||
core/ilo_dev.h \
|
core/ilo_dev.h \
|
||||||
|
core/ilo_fence.h \
|
||||||
core/intel_winsys.h \
|
core/intel_winsys.h \
|
||||||
ilo_blit.c \
|
ilo_blit.c \
|
||||||
ilo_blit.h \
|
ilo_blit.h \
|
||||||
|
73
src/gallium/drivers/ilo/core/ilo_fence.h
Normal file
73
src/gallium/drivers/ilo/core/ilo_fence.h
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Mesa 3-D graphics library
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012-2013 LunarG, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Chia-I Wu <olv@lunarg.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ILO_FENCE_H
|
||||||
|
#define ILO_FENCE_H
|
||||||
|
|
||||||
|
#include "intel_winsys.h"
|
||||||
|
|
||||||
|
#include "ilo_core.h"
|
||||||
|
#include "ilo_dev.h"
|
||||||
|
|
||||||
|
struct ilo_fence {
|
||||||
|
struct intel_bo *seq_bo;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ilo_fence_init(struct ilo_fence *fence, const struct ilo_dev *dev)
|
||||||
|
{
|
||||||
|
/* no-op */
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ilo_fence_cleanup(struct ilo_fence *fence)
|
||||||
|
{
|
||||||
|
intel_bo_unref(fence->seq_bo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the sequence bo for waiting. The fence is considered signaled when
|
||||||
|
* there is no sequence bo.
|
||||||
|
*/
|
||||||
|
static inline void
|
||||||
|
ilo_fence_set_seq_bo(struct ilo_fence *fence, struct intel_bo *seq_bo)
|
||||||
|
{
|
||||||
|
intel_bo_unref(fence->seq_bo);
|
||||||
|
fence->seq_bo = intel_bo_ref(seq_bo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for the fence to be signaled or until \p timeout nanoseconds has
|
||||||
|
* passed. It will wait indefinitely when \p timeout is negative.
|
||||||
|
*/
|
||||||
|
static inline bool
|
||||||
|
ilo_fence_wait(struct ilo_fence *fence, int64_t timeout)
|
||||||
|
{
|
||||||
|
return (!fence->seq_bo || intel_bo_wait(fence->seq_bo, timeout) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ILO_FENCE_H */
|
@@ -62,8 +62,7 @@ ilo_flush(struct pipe_context *pipe,
|
|||||||
(flags & PIPE_FLUSH_END_OF_FRAME) ? "frame end" : "user request");
|
(flags & PIPE_FLUSH_END_OF_FRAME) ? "frame end" : "user request");
|
||||||
|
|
||||||
if (f) {
|
if (f) {
|
||||||
*f = (struct pipe_fence_handle *)
|
*f = ilo_screen_fence_create(pipe->screen, ilo->cp->last_submitted_bo);
|
||||||
ilo_fence_create(pipe->screen, ilo->cp->last_submitted_bo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "vl/vl_decoder.h"
|
#include "vl/vl_decoder.h"
|
||||||
#include "vl/vl_video_buffer.h"
|
#include "vl/vl_video_buffer.h"
|
||||||
#include "genhw/genhw.h" /* for GEN6_REG_TIMESTAMP */
|
#include "genhw/genhw.h" /* for GEN6_REG_TIMESTAMP */
|
||||||
|
#include "core/ilo_fence.h"
|
||||||
#include "core/intel_winsys.h"
|
#include "core/intel_winsys.h"
|
||||||
|
|
||||||
#include "ilo_context.h"
|
#include "ilo_context.h"
|
||||||
@@ -40,9 +41,10 @@
|
|||||||
#include "ilo_public.h"
|
#include "ilo_public.h"
|
||||||
#include "ilo_screen.h"
|
#include "ilo_screen.h"
|
||||||
|
|
||||||
struct ilo_fence {
|
struct pipe_fence_handle {
|
||||||
struct pipe_reference reference;
|
struct pipe_reference reference;
|
||||||
struct intel_bo *bo;
|
|
||||||
|
struct ilo_fence fence;
|
||||||
};
|
};
|
||||||
|
|
||||||
static float
|
static float
|
||||||
@@ -579,81 +581,67 @@ ilo_get_timestamp(struct pipe_screen *screen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ilo_fence_reference(struct pipe_screen *screen,
|
ilo_screen_fence_reference(struct pipe_screen *screen,
|
||||||
struct pipe_fence_handle **p,
|
struct pipe_fence_handle **ptr,
|
||||||
struct pipe_fence_handle *f)
|
struct pipe_fence_handle *fence)
|
||||||
{
|
{
|
||||||
struct ilo_fence *fence = ilo_fence(f);
|
struct pipe_fence_handle *old;
|
||||||
struct ilo_fence *old;
|
|
||||||
|
|
||||||
if (likely(p)) {
|
if (likely(ptr)) {
|
||||||
old = ilo_fence(*p);
|
old = *ptr;
|
||||||
*p = f;
|
*ptr = fence;
|
||||||
} else {
|
} else {
|
||||||
old = NULL;
|
old = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC_ASSERT(&((struct ilo_fence *) NULL)->reference == NULL);
|
STATIC_ASSERT(&((struct pipe_fence_handle *) NULL)->reference == NULL);
|
||||||
if (pipe_reference(&old->reference, &fence->reference)) {
|
if (pipe_reference(&old->reference, &fence->reference)) {
|
||||||
intel_bo_unref(old->bo);
|
ilo_fence_cleanup(&old->fence);
|
||||||
FREE(old);
|
FREE(old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean
|
static boolean
|
||||||
ilo_fence_signalled(struct pipe_screen *screen,
|
ilo_screen_fence_finish(struct pipe_screen *screen,
|
||||||
struct pipe_fence_handle *f)
|
struct pipe_fence_handle *fence,
|
||||||
|
uint64_t timeout)
|
||||||
{
|
{
|
||||||
struct ilo_fence *fence = ilo_fence(f);
|
const int64_t wait_timeout = (timeout > INT64_MAX) ? -1 : timeout;
|
||||||
|
bool signaled;
|
||||||
|
|
||||||
/* mark signalled if the bo is idle */
|
signaled = ilo_fence_wait(&fence->fence, wait_timeout);
|
||||||
if (fence->bo && !intel_bo_is_busy(fence->bo)) {
|
/* XXX not thread safe */
|
||||||
intel_bo_unref(fence->bo);
|
if (signaled)
|
||||||
fence->bo = NULL;
|
ilo_fence_set_seq_bo(&fence->fence, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
return (fence->bo == NULL);
|
return signaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean
|
static boolean
|
||||||
ilo_fence_finish(struct pipe_screen *screen,
|
ilo_screen_fence_signalled(struct pipe_screen *screen,
|
||||||
struct pipe_fence_handle *f,
|
struct pipe_fence_handle *fence)
|
||||||
uint64_t timeout)
|
|
||||||
{
|
{
|
||||||
struct ilo_fence *fence = ilo_fence(f);
|
return ilo_screen_fence_finish(screen, fence, 0);
|
||||||
const int64_t wait_timeout = (timeout > INT64_MAX) ? -1 : timeout;
|
|
||||||
|
|
||||||
/* already signalled */
|
|
||||||
if (!fence->bo)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
/* wait and see if it returns error */
|
|
||||||
if (intel_bo_wait(fence->bo, wait_timeout))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* mark signalled */
|
|
||||||
intel_bo_unref(fence->bo);
|
|
||||||
fence->bo = NULL;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a fence for \p bo. When \p bo is not NULL, it must be submitted
|
* Create a fence for \p bo. When \p bo is not NULL, it must be submitted
|
||||||
* before waited on or checked.
|
* before waited on or checked.
|
||||||
*/
|
*/
|
||||||
struct ilo_fence *
|
struct pipe_fence_handle *
|
||||||
ilo_fence_create(struct pipe_screen *screen, struct intel_bo *bo)
|
ilo_screen_fence_create(struct pipe_screen *screen, struct intel_bo *bo)
|
||||||
{
|
{
|
||||||
struct ilo_fence *fence;
|
struct ilo_screen *is = ilo_screen(screen);
|
||||||
|
struct pipe_fence_handle *fence;
|
||||||
|
|
||||||
fence = CALLOC_STRUCT(ilo_fence);
|
fence = CALLOC_STRUCT(pipe_fence_handle);
|
||||||
if (!fence)
|
if (!fence)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pipe_reference_init(&fence->reference, 1);
|
pipe_reference_init(&fence->reference, 1);
|
||||||
|
|
||||||
fence->bo = intel_bo_ref(bo);
|
ilo_fence_init(&fence->fence, &is->dev);
|
||||||
|
ilo_fence_set_seq_bo(&fence->fence, bo);
|
||||||
|
|
||||||
return fence;
|
return fence;
|
||||||
}
|
}
|
||||||
@@ -700,9 +688,9 @@ ilo_screen_create(struct intel_winsys *ws)
|
|||||||
|
|
||||||
is->base.flush_frontbuffer = NULL;
|
is->base.flush_frontbuffer = NULL;
|
||||||
|
|
||||||
is->base.fence_reference = ilo_fence_reference;
|
is->base.fence_reference = ilo_screen_fence_reference;
|
||||||
is->base.fence_signalled = ilo_fence_signalled;
|
is->base.fence_signalled = ilo_screen_fence_signalled;
|
||||||
is->base.fence_finish = ilo_fence_finish;
|
is->base.fence_finish = ilo_screen_fence_finish;
|
||||||
|
|
||||||
is->base.get_driver_query_info = NULL;
|
is->base.get_driver_query_info = NULL;
|
||||||
|
|
||||||
|
@@ -48,13 +48,7 @@ ilo_screen(struct pipe_screen *screen)
|
|||||||
return (struct ilo_screen *) screen;
|
return (struct ilo_screen *) screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct ilo_fence *
|
struct pipe_fence_handle *
|
||||||
ilo_fence(struct pipe_fence_handle *fence)
|
ilo_screen_fence_create(struct pipe_screen *screen, struct intel_bo *bo);
|
||||||
{
|
|
||||||
return (struct ilo_fence *) fence;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ilo_fence *
|
|
||||||
ilo_fence_create(struct pipe_screen *screen, struct intel_bo *bo);
|
|
||||||
|
|
||||||
#endif /* ILO_SCREEN_H */
|
#endif /* ILO_SCREEN_H */
|
||||||
|
Reference in New Issue
Block a user