Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2011 Marek Olšák |
||
4 | * All Rights Reserved. |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the |
||
8 | * "Software"), to deal in the Software without restriction, including |
||
9 | * without limitation the rights to use, copy, modify, merge, publish, |
||
10 | * distribute, sub license, and/or sell copies of the Software, and to |
||
11 | * permit persons to whom the Software is furnished to do so, subject to |
||
12 | * the following conditions: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice (including the |
||
15 | * next paragraph) shall be included in all copies or substantial portions |
||
16 | * of the Software. |
||
17 | * |
||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
||
21 | * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR |
||
22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||
23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||
24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | * |
||
26 | **************************************************************************/ |
||
27 | |||
28 | /* |
||
29 | * Authors: |
||
30 | * Marek Olšák |
||
31 | */ |
||
32 | |||
33 | #include "main/glheader.h" |
||
34 | #include "main/macros.h" |
||
35 | #include "pipe/p_context.h" |
||
36 | #include "pipe/p_screen.h" |
||
37 | #include "st_context.h" |
||
38 | #include "st_cb_syncobj.h" |
||
39 | |||
40 | struct st_sync_object { |
||
41 | struct gl_sync_object b; |
||
42 | |||
43 | struct pipe_fence_handle *fence; |
||
44 | }; |
||
45 | |||
46 | |||
47 | static struct gl_sync_object * st_new_sync_object(struct gl_context *ctx, |
||
48 | GLenum type) |
||
49 | { |
||
50 | if (type == GL_SYNC_FENCE) |
||
51 | return (struct gl_sync_object*)CALLOC_STRUCT(st_sync_object); |
||
52 | else |
||
53 | return NULL; |
||
54 | } |
||
55 | |||
56 | static void st_delete_sync_object(struct gl_context *ctx, |
||
57 | struct gl_sync_object *obj) |
||
58 | { |
||
59 | struct pipe_screen *screen = st_context(ctx)->pipe->screen; |
||
60 | struct st_sync_object *so = (struct st_sync_object*)obj; |
||
61 | |||
62 | screen->fence_reference(screen, &so->fence, NULL); |
||
63 | free(so->b.Label); |
||
64 | free(so); |
||
65 | } |
||
66 | |||
67 | static void st_fence_sync(struct gl_context *ctx, struct gl_sync_object *obj, |
||
68 | GLenum condition, GLbitfield flags) |
||
69 | { |
||
70 | struct pipe_context *pipe = st_context(ctx)->pipe; |
||
71 | struct st_sync_object *so = (struct st_sync_object*)obj; |
||
72 | |||
73 | assert(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0); |
||
74 | assert(so->fence == NULL); |
||
75 | |||
76 | pipe->flush(pipe, &so->fence, 0); |
||
77 | } |
||
78 | |||
79 | static void st_check_sync(struct gl_context *ctx, struct gl_sync_object *obj) |
||
80 | { |
||
81 | struct pipe_screen *screen = st_context(ctx)->pipe->screen; |
||
82 | struct st_sync_object *so = (struct st_sync_object*)obj; |
||
83 | |||
84 | if (so->fence && screen->fence_signalled(screen, so->fence)) { |
||
85 | screen->fence_reference(screen, &so->fence, NULL); |
||
86 | so->b.StatusFlag = GL_TRUE; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | static void st_client_wait_sync(struct gl_context *ctx, |
||
91 | struct gl_sync_object *obj, |
||
92 | GLbitfield flags, GLuint64 timeout) |
||
93 | { |
||
94 | struct pipe_screen *screen = st_context(ctx)->pipe->screen; |
||
95 | struct st_sync_object *so = (struct st_sync_object*)obj; |
||
96 | |||
97 | /* We don't care about GL_SYNC_FLUSH_COMMANDS_BIT, because flush is |
||
98 | * already called when creating a fence. */ |
||
99 | |||
100 | if (so->fence && |
||
101 | screen->fence_finish(screen, so->fence, timeout)) { |
||
102 | screen->fence_reference(screen, &so->fence, NULL); |
||
103 | so->b.StatusFlag = GL_TRUE; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | static void st_server_wait_sync(struct gl_context *ctx, |
||
108 | struct gl_sync_object *obj, |
||
109 | GLbitfield flags, GLuint64 timeout) |
||
110 | { |
||
111 | /* NO-OP. |
||
112 | * Neither Gallium nor DRM interfaces support blocking on the GPU. */ |
||
113 | } |
||
114 | |||
115 | void st_init_syncobj_functions(struct dd_function_table *functions) |
||
116 | { |
||
117 | functions->NewSyncObject = st_new_sync_object; |
||
118 | functions->FenceSync = st_fence_sync; |
||
119 | functions->DeleteSyncObject = st_delete_sync_object; |
||
120 | functions->CheckSync = st_check_sync; |
||
121 | functions->ClientWaitSync = st_client_wait_sync; |
||
122 | functions->ServerWaitSync = st_server_wait_sync; |
||
123 | } |