Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/*
2
 * Mesa 3-D graphics library
3
 *
4
 * Copyright (C) 2012-2013 LunarG, Inc.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included
14
 * in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
23
 *
24
 * Authors:
25
 *    Chia-I Wu 
26
 */
27
 
28
#include "util/u_upload_mgr.h"
29
 
30
#include "ilo_blit.h"
31
#include "ilo_blitter.h"
32
#include "ilo_cp.h"
33
#include "ilo_draw.h"
34
#include "ilo_gpgpu.h"
35
#include "ilo_query.h"
36
#include "ilo_render.h"
37
#include "ilo_resource.h"
38
#include "ilo_screen.h"
39
#include "ilo_shader.h"
40
#include "ilo_state.h"
41
#include "ilo_transfer.h"
42
#include "ilo_video.h"
43
#include "ilo_context.h"
44
 
45
static void
46
ilo_context_cp_submitted(struct ilo_cp *cp, void *data)
47
{
48
   struct ilo_context *ilo = ilo_context(data);
49
 
50
   /* builder buffers are reallocated */
51
   ilo_render_invalidate_builder(ilo->render);
52
}
53
 
54
static void
55
ilo_flush(struct pipe_context *pipe,
56
          struct pipe_fence_handle **f,
57
          unsigned flags)
58
{
59
   struct ilo_context *ilo = ilo_context(pipe);
60
 
61
   ilo_cp_submit(ilo->cp,
62
         (flags & PIPE_FLUSH_END_OF_FRAME) ? "frame end" : "user request");
63
 
64
   if (f) {
65
      *f = ilo_screen_fence_create(pipe->screen, ilo->cp->last_submitted_bo);
66
   }
67
}
68
 
69
static void
70
ilo_render_condition(struct pipe_context *pipe,
71
                     struct pipe_query *query,
72
                     boolean condition,
73
                     uint mode)
74
{
75
   struct ilo_context *ilo = ilo_context(pipe);
76
 
77
   /* reference count? */
78
   ilo->render_condition.query = query;
79
   ilo->render_condition.condition = condition;
80
   ilo->render_condition.mode = mode;
81
}
82
 
83
bool
84
ilo_skip_rendering(struct ilo_context *ilo)
85
{
86
   uint64_t result;
87
   bool wait;
88
 
89
   if (!ilo->render_condition.query)
90
      return false;
91
 
92
   switch (ilo->render_condition.mode) {
93
   case PIPE_RENDER_COND_WAIT:
94
   case PIPE_RENDER_COND_BY_REGION_WAIT:
95
      wait = true;
96
      break;
97
   case PIPE_RENDER_COND_NO_WAIT:
98
   case PIPE_RENDER_COND_BY_REGION_NO_WAIT:
99
   default:
100
      wait = false;
101
      break;
102
   }
103
 
104
   if (ilo->base.get_query_result(&ilo->base, ilo->render_condition.query,
105
            wait, (union pipe_query_result *) &result))
106
      return ((bool) result == ilo->render_condition.condition);
107
   else
108
      return false;
109
}
110
 
111
static void
112
ilo_context_destroy(struct pipe_context *pipe)
113
{
114
   struct ilo_context *ilo = ilo_context(pipe);
115
 
116
   ilo_state_vector_cleanup(&ilo->state_vector);
117
 
118
   if (ilo->uploader)
119
      u_upload_destroy(ilo->uploader);
120
 
121
   if (ilo->blitter)
122
      ilo_blitter_destroy(ilo->blitter);
123
   if (ilo->render)
124
      ilo_render_destroy(ilo->render);
125
   if (ilo->shader_cache)
126
      ilo_shader_cache_destroy(ilo->shader_cache);
127
   if (ilo->cp)
128
      ilo_cp_destroy(ilo->cp);
129
 
130
   util_slab_destroy(&ilo->transfer_mempool);
131
 
132
   FREE(ilo);
133
}
134
 
135
static struct pipe_context *
136
ilo_context_create(struct pipe_screen *screen, void *priv)
137
{
138
   struct ilo_screen *is = ilo_screen(screen);
139
   struct ilo_context *ilo;
140
 
141
   ilo = CALLOC_STRUCT(ilo_context);
142
   if (!ilo)
143
      return NULL;
144
 
145
   ilo->winsys = is->dev.winsys;
146
   ilo->dev = &is->dev;
147
 
148
   /*
149
    * initialize first, otherwise it may not be safe to call
150
    * ilo_context_destroy() on errors
151
    */
152
   util_slab_create(&ilo->transfer_mempool,
153
         sizeof(struct ilo_transfer), 64, UTIL_SLAB_SINGLETHREADED);
154
 
155
   ilo->shader_cache = ilo_shader_cache_create();
156
   ilo->cp = ilo_cp_create(ilo->dev, ilo->winsys, ilo->shader_cache);
157
   if (ilo->cp)
158
      ilo->render = ilo_render_create(&ilo->cp->builder);
159
 
160
   if (!ilo->cp || !ilo->shader_cache || !ilo->render) {
161
      ilo_context_destroy(&ilo->base);
162
      return NULL;
163
   }
164
 
165
   ilo_cp_set_submit_callback(ilo->cp,
166
         ilo_context_cp_submitted, (void *) ilo);
167
 
168
   ilo->base.screen = screen;
169
   ilo->base.priv = priv;
170
 
171
   ilo->base.destroy = ilo_context_destroy;
172
   ilo->base.flush = ilo_flush;
173
   ilo->base.render_condition = ilo_render_condition;
174
 
175
   ilo_init_draw_functions(ilo);
176
   ilo_init_query_functions(ilo);
177
   ilo_init_state_functions(ilo);
178
   ilo_init_blit_functions(ilo);
179
   ilo_init_transfer_functions(ilo);
180
   ilo_init_video_functions(ilo);
181
   ilo_init_gpgpu_functions(ilo);
182
 
183
   ilo_init_draw(ilo);
184
   ilo_state_vector_init(ilo->dev, &ilo->state_vector);
185
 
186
   /*
187
    * These must be called last as u_upload/u_blitter are clients of the pipe
188
    * context.
189
    */
190
   ilo->uploader = u_upload_create(&ilo->base, 1024 * 1024, 16,
191
         PIPE_BIND_CONSTANT_BUFFER | PIPE_BIND_INDEX_BUFFER);
192
   if (!ilo->uploader) {
193
      ilo_context_destroy(&ilo->base);
194
      return NULL;
195
   }
196
 
197
   ilo->blitter = ilo_blitter_create(ilo);
198
   if (!ilo->blitter) {
199
      ilo_context_destroy(&ilo->base);
200
      return NULL;
201
   }
202
 
203
   return &ilo->base;
204
}
205
 
206
/**
207
 * Initialize context-related functions.
208
 */
209
void
210
ilo_init_context_functions(struct ilo_screen *is)
211
{
212
   is->base.context_create = ilo_context_create;
213
}