1 /****************************************************************************
2 * Copyright (C) 2015 Intel Corporation. All Rights Reserved.
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
22 ***************************************************************************/
24 #include "pipe/p_screen.h"
25 #include "util/u_memory.h"
26 #include "os/os_time.h"
28 #include "swr_context.h"
29 #include "swr_screen.h"
30 #include "swr_fence.h"
32 #if defined(PIPE_CC_MSVC) // portable thread yield
33 #define sched_yield SwitchToThread
36 * Fence callback, called by back-end thread on completion of all rendering up
40 swr_sync_cb(UINT64 userData
, UINT64 userData2
, UINT64 userData3
)
42 struct swr_fence
*fence
= (struct swr_fence
*)userData
;
44 fence
->read
= fence
->write
;
48 * Submit an existing fence.
51 swr_fence_submit(struct swr_context
*ctx
, struct pipe_fence_handle
*fh
)
53 struct swr_fence
*fence
= swr_fence(fh
);
56 SwrSync(ctx
->swrContext
, swr_sync_cb
, (UINT64
)fence
, 0, 0);
60 * Create a new fence object.
62 struct pipe_fence_handle
*
65 static int fence_id
= 0;
66 struct swr_fence
*fence
= CALLOC_STRUCT(swr_fence
);
70 memset(fence
, 0, sizeof(*fence
));
71 pipe_reference_init(&fence
->reference
, 1);
72 fence
->id
= fence_id
++;
74 return (struct pipe_fence_handle
*)fence
;
77 /** Destroy a fence. Called when refcount hits zero. */
79 swr_fence_destroy(struct swr_fence
*fence
)
85 * Set ptr = fence, with reference counting
88 swr_fence_reference(struct pipe_screen
*screen
,
89 struct pipe_fence_handle
**ptr
,
90 struct pipe_fence_handle
*f
)
92 struct swr_fence
*fence
= swr_fence(f
);
93 struct swr_fence
*old
;
96 old
= swr_fence(*ptr
);
102 if (pipe_reference(&old
->reference
, &fence
->reference
))
103 swr_fence_destroy(old
);
107 * Wait for the fence to finish.
110 swr_fence_finish(struct pipe_screen
*screen
,
111 struct pipe_fence_handle
*fence_handle
,
114 struct swr_fence
*fence
= swr_fence(fence_handle
);
116 while (!swr_is_fence_done(fence
))
124 swr_get_timestamp(struct pipe_screen
*screen
)
126 return os_time_get_nano();
131 swr_fence_init(struct pipe_screen
*p_screen
)
133 p_screen
->fence_reference
= swr_fence_reference
;
134 p_screen
->fence_finish
= swr_fence_finish
;
136 p_screen
->get_timestamp
= swr_get_timestamp
;
139 * Create persistant "flush" fence, submitted when swr_flush is called.
141 struct swr_screen
*screen
= swr_screen(p_screen
);
142 screen
->flush_fence
= swr_fence_create();