rbug_context.c revision cab2fed135bc1edf7b65ddca3236020638427061
1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/************************************************************************** 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Copyright 2010 VMware, Inc. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * All Rights Reserved. 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Permission is hereby granted, free of charge, to any person obtaining a 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * copy of this software and associated documentation files (the 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * "Software"), to deal in the Software without restriction, including 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * without limitation the rights to use, copy, modify, merge, publish, 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * distribute, sub license, and/or sell copies of the Software, and to 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * permit persons to whom the Software is furnished to do so, subject to 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * the following conditions: 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * The above copyright notice and this permission notice (including the 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * next paragraph) shall be included in all copies or substantial portions 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * of the Software. 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) **************************************************************************/ 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "pipe/p_context.h" 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "util/u_memory.h" 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "util/u_inlines.h" 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "util/u_simple_list.h" 33424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "rbug/rbug_context.h" 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "rbug_context.h" 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "rbug_objects.h" 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)static void 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)rbug_destroy(struct pipe_context *_pipe) 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles){ 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) struct rbug_context *rb_pipe = rbug_context(_pipe); 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) struct pipe_context *pipe = rb_pipe->pipe; 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) remove_from_list(&rb_pipe->list); 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pipe_mutex_lock(rb_pipe->call_mutex); 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pipe->destroy(pipe); 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rb_pipe->pipe = NULL; 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pipe_mutex_unlock(rb_pipe->call_mutex); 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) FREE(rb_pipe); 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)static void 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag) 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles){ 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_blocker & flag) { 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rb_pipe->draw_blocked |= flag; 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } else if ((rb_pipe->draw_rule.blocker & flag) && 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) { 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int k; 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) boolean block = FALSE; 65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__, 66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (void *) rb_pipe->draw_rule.fs, (void *) rb_pipe->curr.fs, 67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (void *) rb_pipe->draw_rule.vs, (void *) rb_pipe->curr.vs, 68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (void *) rb_pipe->draw_rule.surf, 0, 69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) (void *) rb_pipe->draw_rule.texture, 0); 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.fs && 71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rb_pipe->draw_rule.fs == rb_pipe->curr.fs) 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) block = TRUE; 73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.vs && 74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rb_pipe->draw_rule.vs == rb_pipe->curr.vs) 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) block = TRUE; 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.surf && 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf) 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) block = TRUE; 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.surf) 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (k = 0; k < rb_pipe->curr.nr_cbufs; k++) 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k]) 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) block = TRUE; 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.texture) { 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (k = 0; k < rb_pipe->curr.num_fs_views; k++) 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.texture == rb_pipe->curr.fs_texs[k]) 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) block = TRUE; 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) for (k = 0; k < rb_pipe->curr.num_vs_views; k++) { 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_rule.texture == rb_pipe->curr.vs_texs[k]) { 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) block = TRUE; 90424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 91424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 92424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 93424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (block) 95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE); 96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (rb_pipe->draw_blocked) 99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rbug_notify_draw_blocked(rb_pipe); 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) /* wait for rbug to clear the blocked flag */ 102f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) while (rb_pipe->draw_blocked & flag) { 103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rb_pipe->draw_blocked |= flag; 104f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex); 105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)static void 110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info) 111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles){ 112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) struct rbug_context *rb_pipe = rbug_context(_pipe); 113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) struct pipe_context *pipe = rb_pipe->pipe; 1147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch pipe_mutex_lock(rb_pipe->draw_mutex); 1167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE); 117a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 1187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch pipe_mutex_lock(rb_pipe->call_mutex); 1197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!(rb_pipe->curr.fs && rb_pipe->curr.fs->disabled) && 1207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch !(rb_pipe->curr.gs && rb_pipe->curr.gs->disabled) && 121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) !(rb_pipe->curr.vs && rb_pipe->curr.vs->disabled)) 122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pipe->draw_vbo(pipe, info); 123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pipe_mutex_unlock(rb_pipe->call_mutex); 124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER); 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) pipe_mutex_unlock(rb_pipe->draw_mutex); 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 128 129static struct pipe_query * 130rbug_create_query(struct pipe_context *_pipe, 131 unsigned query_type) 132{ 133 struct rbug_context *rb_pipe = rbug_context(_pipe); 134 struct pipe_context *pipe = rb_pipe->pipe; 135 136 pipe_mutex_lock(rb_pipe->call_mutex); 137 return pipe->create_query(pipe, 138 query_type); 139 pipe_mutex_unlock(rb_pipe->call_mutex); 140} 141 142static void 143rbug_destroy_query(struct pipe_context *_pipe, 144 struct pipe_query *query) 145{ 146 struct rbug_context *rb_pipe = rbug_context(_pipe); 147 struct pipe_context *pipe = rb_pipe->pipe; 148 149 pipe_mutex_lock(rb_pipe->call_mutex); 150 pipe->destroy_query(pipe, 151 query); 152 pipe_mutex_unlock(rb_pipe->call_mutex); 153} 154 155static void 156rbug_begin_query(struct pipe_context *_pipe, 157 struct pipe_query *query) 158{ 159 struct rbug_context *rb_pipe = rbug_context(_pipe); 160 struct pipe_context *pipe = rb_pipe->pipe; 161 162 pipe_mutex_lock(rb_pipe->call_mutex); 163 pipe->begin_query(pipe, 164 query); 165 pipe_mutex_unlock(rb_pipe->call_mutex); 166} 167 168static void 169rbug_end_query(struct pipe_context *_pipe, 170 struct pipe_query *query) 171{ 172 struct rbug_context *rb_pipe = rbug_context(_pipe); 173 struct pipe_context *pipe = rb_pipe->pipe; 174 175 pipe_mutex_lock(rb_pipe->call_mutex); 176 pipe->end_query(pipe, 177 query); 178 pipe_mutex_unlock(rb_pipe->call_mutex); 179} 180 181static boolean 182rbug_get_query_result(struct pipe_context *_pipe, 183 struct pipe_query *query, 184 boolean wait, 185 union pipe_query_result *result) 186{ 187 struct rbug_context *rb_pipe = rbug_context(_pipe); 188 struct pipe_context *pipe = rb_pipe->pipe; 189 boolean ret; 190 191 pipe_mutex_lock(rb_pipe->call_mutex); 192 ret = pipe->get_query_result(pipe, 193 query, 194 wait, 195 result); 196 pipe_mutex_unlock(rb_pipe->call_mutex); 197 198 return ret; 199} 200 201static void * 202rbug_create_blend_state(struct pipe_context *_pipe, 203 const struct pipe_blend_state *blend) 204{ 205 struct rbug_context *rb_pipe = rbug_context(_pipe); 206 struct pipe_context *pipe = rb_pipe->pipe; 207 void *ret; 208 209 pipe_mutex_lock(rb_pipe->call_mutex); 210 ret = pipe->create_blend_state(pipe, 211 blend); 212 pipe_mutex_unlock(rb_pipe->call_mutex); 213 214 return ret; 215} 216 217static void 218rbug_bind_blend_state(struct pipe_context *_pipe, 219 void *blend) 220{ 221 struct rbug_context *rb_pipe = rbug_context(_pipe); 222 struct pipe_context *pipe = rb_pipe->pipe; 223 224 pipe_mutex_lock(rb_pipe->call_mutex); 225 pipe->bind_blend_state(pipe, 226 blend); 227 pipe_mutex_unlock(rb_pipe->call_mutex); 228} 229 230static void 231rbug_delete_blend_state(struct pipe_context *_pipe, 232 void *blend) 233{ 234 struct rbug_context *rb_pipe = rbug_context(_pipe); 235 struct pipe_context *pipe = rb_pipe->pipe; 236 237 pipe_mutex_lock(rb_pipe->call_mutex); 238 pipe->delete_blend_state(pipe, 239 blend); 240 pipe_mutex_unlock(rb_pipe->call_mutex); 241} 242 243static void * 244rbug_create_sampler_state(struct pipe_context *_pipe, 245 const struct pipe_sampler_state *sampler) 246{ 247 struct rbug_context *rb_pipe = rbug_context(_pipe); 248 struct pipe_context *pipe = rb_pipe->pipe; 249 void *ret; 250 251 pipe_mutex_lock(rb_pipe->call_mutex); 252 ret = pipe->create_sampler_state(pipe, 253 sampler); 254 pipe_mutex_unlock(rb_pipe->call_mutex); 255 256 return ret; 257} 258 259static void 260rbug_bind_fragment_sampler_states(struct pipe_context *_pipe, 261 unsigned num_samplers, 262 void **samplers) 263{ 264 struct rbug_context *rb_pipe = rbug_context(_pipe); 265 struct pipe_context *pipe = rb_pipe->pipe; 266 267 pipe_mutex_lock(rb_pipe->call_mutex); 268 pipe->bind_fragment_sampler_states(pipe, 269 num_samplers, 270 samplers); 271 pipe_mutex_unlock(rb_pipe->call_mutex); 272} 273 274static void 275rbug_bind_vertex_sampler_states(struct pipe_context *_pipe, 276 unsigned num_samplers, 277 void **samplers) 278{ 279 struct rbug_context *rb_pipe = rbug_context(_pipe); 280 struct pipe_context *pipe = rb_pipe->pipe; 281 282 pipe_mutex_lock(rb_pipe->call_mutex); 283 pipe->bind_vertex_sampler_states(pipe, 284 num_samplers, 285 samplers); 286 pipe_mutex_unlock(rb_pipe->call_mutex); 287} 288 289static void 290rbug_delete_sampler_state(struct pipe_context *_pipe, 291 void *sampler) 292{ 293 struct rbug_context *rb_pipe = rbug_context(_pipe); 294 struct pipe_context *pipe = rb_pipe->pipe; 295 296 pipe_mutex_lock(rb_pipe->call_mutex); 297 pipe->delete_sampler_state(pipe, 298 sampler); 299 pipe_mutex_unlock(rb_pipe->call_mutex); 300} 301 302static void * 303rbug_create_rasterizer_state(struct pipe_context *_pipe, 304 const struct pipe_rasterizer_state *rasterizer) 305{ 306 struct rbug_context *rb_pipe = rbug_context(_pipe); 307 struct pipe_context *pipe = rb_pipe->pipe; 308 void *ret; 309 310 pipe_mutex_lock(rb_pipe->call_mutex); 311 ret = pipe->create_rasterizer_state(pipe, 312 rasterizer); 313 pipe_mutex_unlock(rb_pipe->call_mutex); 314 315 return ret; 316} 317 318static void 319rbug_bind_rasterizer_state(struct pipe_context *_pipe, 320 void *rasterizer) 321{ 322 struct rbug_context *rb_pipe = rbug_context(_pipe); 323 struct pipe_context *pipe = rb_pipe->pipe; 324 325 pipe_mutex_lock(rb_pipe->call_mutex); 326 pipe->bind_rasterizer_state(pipe, 327 rasterizer); 328 pipe_mutex_unlock(rb_pipe->call_mutex); 329} 330 331static void 332rbug_delete_rasterizer_state(struct pipe_context *_pipe, 333 void *rasterizer) 334{ 335 struct rbug_context *rb_pipe = rbug_context(_pipe); 336 struct pipe_context *pipe = rb_pipe->pipe; 337 338 pipe_mutex_lock(rb_pipe->call_mutex); 339 pipe->delete_rasterizer_state(pipe, 340 rasterizer); 341 pipe_mutex_unlock(rb_pipe->call_mutex); 342} 343 344static void * 345rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe, 346 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha) 347{ 348 struct rbug_context *rb_pipe = rbug_context(_pipe); 349 struct pipe_context *pipe = rb_pipe->pipe; 350 void *ret; 351 352 pipe_mutex_lock(rb_pipe->call_mutex); 353 ret = pipe->create_depth_stencil_alpha_state(pipe, 354 depth_stencil_alpha); 355 pipe_mutex_unlock(rb_pipe->call_mutex); 356 357 return ret; 358} 359 360static void 361rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, 362 void *depth_stencil_alpha) 363{ 364 struct rbug_context *rb_pipe = rbug_context(_pipe); 365 struct pipe_context *pipe = rb_pipe->pipe; 366 367 pipe_mutex_lock(rb_pipe->call_mutex); 368 pipe->bind_depth_stencil_alpha_state(pipe, 369 depth_stencil_alpha); 370 pipe_mutex_unlock(rb_pipe->call_mutex); 371} 372 373static void 374rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, 375 void *depth_stencil_alpha) 376{ 377 struct rbug_context *rb_pipe = rbug_context(_pipe); 378 struct pipe_context *pipe = rb_pipe->pipe; 379 380 pipe_mutex_lock(rb_pipe->call_mutex); 381 pipe->delete_depth_stencil_alpha_state(pipe, 382 depth_stencil_alpha); 383 pipe_mutex_unlock(rb_pipe->call_mutex); 384} 385 386static void * 387rbug_create_fs_state(struct pipe_context *_pipe, 388 const struct pipe_shader_state *state) 389{ 390 struct rbug_context *rb_pipe = rbug_context(_pipe); 391 struct pipe_context *pipe = rb_pipe->pipe; 392 void *result; 393 394 pipe_mutex_lock(rb_pipe->call_mutex); 395 result = pipe->create_fs_state(pipe, state); 396 pipe_mutex_unlock(rb_pipe->call_mutex); 397 398 if (!result) 399 return NULL; 400 401 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT); 402} 403 404static void 405rbug_bind_fs_state(struct pipe_context *_pipe, 406 void *_fs) 407{ 408 struct rbug_context *rb_pipe = rbug_context(_pipe); 409 struct pipe_context *pipe = rb_pipe->pipe; 410 void *fs; 411 412 pipe_mutex_lock(rb_pipe->call_mutex); 413 414 fs = rbug_shader_unwrap(_fs); 415 rb_pipe->curr.fs = rbug_shader(_fs); 416 pipe->bind_fs_state(pipe, 417 fs); 418 419 pipe_mutex_unlock(rb_pipe->call_mutex); 420} 421 422static void 423rbug_delete_fs_state(struct pipe_context *_pipe, 424 void *_fs) 425{ 426 struct rbug_context *rb_pipe = rbug_context(_pipe); 427 struct rbug_shader *rb_shader = rbug_shader(_fs); 428 429 pipe_mutex_lock(rb_pipe->call_mutex); 430 rbug_shader_destroy(rb_pipe, rb_shader); 431 pipe_mutex_unlock(rb_pipe->call_mutex); 432} 433 434static void * 435rbug_create_vs_state(struct pipe_context *_pipe, 436 const struct pipe_shader_state *state) 437{ 438 struct rbug_context *rb_pipe = rbug_context(_pipe); 439 struct pipe_context *pipe = rb_pipe->pipe; 440 void *result; 441 442 pipe_mutex_lock(rb_pipe->call_mutex); 443 result = pipe->create_vs_state(pipe, state); 444 pipe_mutex_unlock(rb_pipe->call_mutex); 445 446 if (!result) 447 return NULL; 448 449 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX); 450} 451 452static void 453rbug_bind_vs_state(struct pipe_context *_pipe, 454 void *_vs) 455{ 456 struct rbug_context *rb_pipe = rbug_context(_pipe); 457 struct pipe_context *pipe = rb_pipe->pipe; 458 void *vs; 459 460 pipe_mutex_lock(rb_pipe->call_mutex); 461 462 vs = rbug_shader_unwrap(_vs); 463 rb_pipe->curr.vs = rbug_shader(_vs); 464 pipe->bind_vs_state(pipe, 465 vs); 466 467 pipe_mutex_unlock(rb_pipe->call_mutex); 468} 469 470static void 471rbug_delete_vs_state(struct pipe_context *_pipe, 472 void *_vs) 473{ 474 struct rbug_context *rb_pipe = rbug_context(_pipe); 475 struct rbug_shader *rb_shader = rbug_shader(_vs); 476 477 pipe_mutex_unlock(rb_pipe->call_mutex); 478 rbug_shader_destroy(rb_pipe, rb_shader); 479 pipe_mutex_unlock(rb_pipe->call_mutex); 480} 481 482static void * 483rbug_create_gs_state(struct pipe_context *_pipe, 484 const struct pipe_shader_state *state) 485{ 486 struct rbug_context *rb_pipe = rbug_context(_pipe); 487 struct pipe_context *pipe = rb_pipe->pipe; 488 void *result; 489 490 pipe_mutex_lock(rb_pipe->call_mutex); 491 result = pipe->create_gs_state(pipe, state); 492 pipe_mutex_unlock(rb_pipe->call_mutex); 493 494 if (!result) 495 return NULL; 496 497 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM); 498} 499 500static void 501rbug_bind_gs_state(struct pipe_context *_pipe, 502 void *_gs) 503{ 504 struct rbug_context *rb_pipe = rbug_context(_pipe); 505 struct pipe_context *pipe = rb_pipe->pipe; 506 void *gs; 507 508 pipe_mutex_lock(rb_pipe->call_mutex); 509 510 gs = rbug_shader_unwrap(_gs); 511 rb_pipe->curr.gs = rbug_shader(_gs); 512 pipe->bind_gs_state(pipe, 513 gs); 514 515 pipe_mutex_unlock(rb_pipe->call_mutex); 516} 517 518static void 519rbug_delete_gs_state(struct pipe_context *_pipe, 520 void *_gs) 521{ 522 struct rbug_context *rb_pipe = rbug_context(_pipe); 523 struct rbug_shader *rb_shader = rbug_shader(_gs); 524 525 pipe_mutex_lock(rb_pipe->call_mutex); 526 rbug_shader_destroy(rb_pipe, rb_shader); 527 pipe_mutex_unlock(rb_pipe->call_mutex); 528} 529 530static void * 531rbug_create_vertex_elements_state(struct pipe_context *_pipe, 532 unsigned num_elements, 533 const struct pipe_vertex_element *vertex_elements) 534{ 535 struct rbug_context *rb_pipe = rbug_context(_pipe); 536 struct pipe_context *pipe = rb_pipe->pipe; 537 void *ret; 538 539 pipe_mutex_lock(rb_pipe->call_mutex); 540 ret = pipe->create_vertex_elements_state(pipe, 541 num_elements, 542 vertex_elements); 543 pipe_mutex_unlock(rb_pipe->call_mutex); 544 545 return ret; 546} 547 548static void 549rbug_bind_vertex_elements_state(struct pipe_context *_pipe, 550 void *velems) 551{ 552 struct rbug_context *rb_pipe = rbug_context(_pipe); 553 struct pipe_context *pipe = rb_pipe->pipe; 554 555 pipe_mutex_lock(rb_pipe->call_mutex); 556 pipe->bind_vertex_elements_state(pipe, 557 velems); 558 pipe_mutex_unlock(rb_pipe->call_mutex); 559} 560 561static void 562rbug_delete_vertex_elements_state(struct pipe_context *_pipe, 563 void *velems) 564{ 565 struct rbug_context *rb_pipe = rbug_context(_pipe); 566 struct pipe_context *pipe = rb_pipe->pipe; 567 568 pipe_mutex_lock(rb_pipe->call_mutex); 569 pipe->delete_vertex_elements_state(pipe, 570 velems); 571 pipe_mutex_unlock(rb_pipe->call_mutex); 572} 573 574static void 575rbug_set_blend_color(struct pipe_context *_pipe, 576 const struct pipe_blend_color *blend_color) 577{ 578 struct rbug_context *rb_pipe = rbug_context(_pipe); 579 struct pipe_context *pipe = rb_pipe->pipe; 580 581 pipe_mutex_lock(rb_pipe->call_mutex); 582 pipe->set_blend_color(pipe, 583 blend_color); 584 pipe_mutex_unlock(rb_pipe->call_mutex); 585} 586 587static void 588rbug_set_stencil_ref(struct pipe_context *_pipe, 589 const struct pipe_stencil_ref *stencil_ref) 590{ 591 struct rbug_context *rb_pipe = rbug_context(_pipe); 592 struct pipe_context *pipe = rb_pipe->pipe; 593 594 pipe_mutex_lock(rb_pipe->call_mutex); 595 pipe->set_stencil_ref(pipe, 596 stencil_ref); 597 pipe_mutex_unlock(rb_pipe->call_mutex); 598} 599 600static void 601rbug_set_clip_state(struct pipe_context *_pipe, 602 const struct pipe_clip_state *clip) 603{ 604 struct rbug_context *rb_pipe = rbug_context(_pipe); 605 struct pipe_context *pipe = rb_pipe->pipe; 606 607 pipe_mutex_lock(rb_pipe->call_mutex); 608 pipe->set_clip_state(pipe, 609 clip); 610 pipe_mutex_unlock(rb_pipe->call_mutex); 611} 612 613static void 614rbug_set_constant_buffer(struct pipe_context *_pipe, 615 uint shader, 616 uint index, 617 struct pipe_constant_buffer *_cb) 618{ 619 struct rbug_context *rb_pipe = rbug_context(_pipe); 620 struct pipe_context *pipe = rb_pipe->pipe; 621 struct pipe_constant_buffer cb; 622 623 /* XXX hmm? unwrap the input state */ 624 if (_cb) { 625 cb = *_cb; 626 cb.buffer = rbug_resource_unwrap(_cb->buffer); 627 } 628 629 pipe_mutex_lock(rb_pipe->call_mutex); 630 pipe->set_constant_buffer(pipe, 631 shader, 632 index, 633 _cb ? &cb : NULL); 634 pipe_mutex_unlock(rb_pipe->call_mutex); 635} 636 637static void 638rbug_set_framebuffer_state(struct pipe_context *_pipe, 639 const struct pipe_framebuffer_state *_state) 640{ 641 struct rbug_context *rb_pipe = rbug_context(_pipe); 642 struct pipe_context *pipe = rb_pipe->pipe; 643 struct pipe_framebuffer_state unwrapped_state; 644 struct pipe_framebuffer_state *state = NULL; 645 unsigned i; 646 647 /* must protect curr status */ 648 pipe_mutex_lock(rb_pipe->call_mutex); 649 650 rb_pipe->curr.nr_cbufs = 0; 651 memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs)); 652 rb_pipe->curr.zsbuf = NULL; 653 654 /* unwrap the input state */ 655 if (_state) { 656 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state)); 657 658 rb_pipe->curr.nr_cbufs = _state->nr_cbufs; 659 for(i = 0; i < _state->nr_cbufs; i++) { 660 unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]); 661 if (_state->cbufs[i]) 662 rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture); 663 } 664 unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf); 665 if (_state->zsbuf) 666 rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture); 667 state = &unwrapped_state; 668 } 669 670 pipe->set_framebuffer_state(pipe, 671 state); 672 673 pipe_mutex_unlock(rb_pipe->call_mutex); 674} 675 676static void 677rbug_set_polygon_stipple(struct pipe_context *_pipe, 678 const struct pipe_poly_stipple *poly_stipple) 679{ 680 struct rbug_context *rb_pipe = rbug_context(_pipe); 681 struct pipe_context *pipe = rb_pipe->pipe; 682 683 pipe_mutex_lock(rb_pipe->call_mutex); 684 pipe->set_polygon_stipple(pipe, 685 poly_stipple); 686 pipe_mutex_unlock(rb_pipe->call_mutex); 687} 688 689static void 690rbug_set_scissor_state(struct pipe_context *_pipe, 691 const struct pipe_scissor_state *scissor) 692{ 693 struct rbug_context *rb_pipe = rbug_context(_pipe); 694 struct pipe_context *pipe = rb_pipe->pipe; 695 696 pipe_mutex_lock(rb_pipe->call_mutex); 697 pipe->set_scissor_state(pipe, 698 scissor); 699 pipe_mutex_unlock(rb_pipe->call_mutex); 700} 701 702static void 703rbug_set_viewport_state(struct pipe_context *_pipe, 704 const struct pipe_viewport_state *viewport) 705{ 706 struct rbug_context *rb_pipe = rbug_context(_pipe); 707 struct pipe_context *pipe = rb_pipe->pipe; 708 709 pipe_mutex_lock(rb_pipe->call_mutex); 710 pipe->set_viewport_state(pipe, 711 viewport); 712 pipe_mutex_unlock(rb_pipe->call_mutex); 713} 714 715static void 716rbug_set_fragment_sampler_views(struct pipe_context *_pipe, 717 unsigned num, 718 struct pipe_sampler_view **_views) 719{ 720 struct rbug_context *rb_pipe = rbug_context(_pipe); 721 struct pipe_context *pipe = rb_pipe->pipe; 722 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; 723 struct pipe_sampler_view **views = NULL; 724 unsigned i; 725 726 /* must protect curr status */ 727 pipe_mutex_lock(rb_pipe->call_mutex); 728 729 rb_pipe->curr.num_fs_views = 0; 730 memset(rb_pipe->curr.fs_views, 0, sizeof(rb_pipe->curr.fs_views)); 731 memset(rb_pipe->curr.fs_texs, 0, sizeof(rb_pipe->curr.fs_texs)); 732 memset(unwrapped_views, 0, sizeof(unwrapped_views)); 733 734 if (_views) { 735 rb_pipe->curr.num_fs_views = num; 736 for (i = 0; i < num; i++) { 737 rb_pipe->curr.fs_views[i] = rbug_sampler_view(_views[i]); 738 rb_pipe->curr.fs_texs[i] = rbug_resource(_views[i] ? _views[i]->texture : NULL); 739 unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]); 740 } 741 views = unwrapped_views; 742 } 743 744 pipe->set_fragment_sampler_views(pipe, num, views); 745 746 pipe_mutex_unlock(rb_pipe->call_mutex); 747} 748 749static void 750rbug_set_vertex_sampler_views(struct pipe_context *_pipe, 751 unsigned num, 752 struct pipe_sampler_view **_views) 753{ 754 struct rbug_context *rb_pipe = rbug_context(_pipe); 755 struct pipe_context *pipe = rb_pipe->pipe; 756 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; 757 struct pipe_sampler_view **views = NULL; 758 unsigned i; 759 760 /* must protect curr status */ 761 pipe_mutex_lock(rb_pipe->call_mutex); 762 763 rb_pipe->curr.num_vs_views = 0; 764 memset(rb_pipe->curr.vs_views, 0, sizeof(rb_pipe->curr.vs_views)); 765 memset(rb_pipe->curr.vs_texs, 0, sizeof(rb_pipe->curr.vs_texs)); 766 memset(unwrapped_views, 0, sizeof(unwrapped_views)); 767 768 if (_views) { 769 rb_pipe->curr.num_vs_views = num; 770 for (i = 0; i < num; i++) { 771 rb_pipe->curr.vs_views[i] = rbug_sampler_view(_views[i]); 772 rb_pipe->curr.vs_texs[i] = rbug_resource(_views[i]->texture); 773 unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]); 774 } 775 views = unwrapped_views; 776 } 777 778 pipe->set_vertex_sampler_views(pipe, num, views); 779 780 pipe_mutex_unlock(rb_pipe->call_mutex); 781} 782 783static void 784rbug_set_vertex_buffers(struct pipe_context *_pipe, 785 unsigned num_buffers, 786 const struct pipe_vertex_buffer *_buffers) 787{ 788 struct rbug_context *rb_pipe = rbug_context(_pipe); 789 struct pipe_context *pipe = rb_pipe->pipe; 790 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS]; 791 struct pipe_vertex_buffer *buffers = NULL; 792 unsigned i; 793 794 pipe_mutex_lock(rb_pipe->call_mutex); 795 796 if (num_buffers) { 797 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); 798 for (i = 0; i < num_buffers; i++) 799 unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer); 800 buffers = unwrapped_buffers; 801 } 802 803 pipe->set_vertex_buffers(pipe, 804 num_buffers, 805 buffers); 806 807 pipe_mutex_unlock(rb_pipe->call_mutex); 808} 809 810static void 811rbug_set_index_buffer(struct pipe_context *_pipe, 812 const struct pipe_index_buffer *_ib) 813{ 814 struct rbug_context *rb_pipe = rbug_context(_pipe); 815 struct pipe_context *pipe = rb_pipe->pipe; 816 struct pipe_index_buffer unwrapped_ib, *ib = NULL; 817 818 if (_ib) { 819 unwrapped_ib = *_ib; 820 unwrapped_ib.buffer = rbug_resource_unwrap(_ib->buffer); 821 ib = &unwrapped_ib; 822 } 823 824 pipe_mutex_lock(rb_pipe->call_mutex); 825 pipe->set_index_buffer(pipe, ib); 826 pipe_mutex_unlock(rb_pipe->call_mutex); 827} 828 829static void 830rbug_set_sample_mask(struct pipe_context *_pipe, 831 unsigned sample_mask) 832{ 833 struct rbug_context *rb_pipe = rbug_context(_pipe); 834 struct pipe_context *pipe = rb_pipe->pipe; 835 836 pipe_mutex_lock(rb_pipe->call_mutex); 837 pipe->set_sample_mask(pipe, sample_mask); 838 pipe_mutex_unlock(rb_pipe->call_mutex); 839} 840 841static void 842rbug_resource_copy_region(struct pipe_context *_pipe, 843 struct pipe_resource *_dst, 844 unsigned dst_level, 845 unsigned dstx, 846 unsigned dsty, 847 unsigned dstz, 848 struct pipe_resource *_src, 849 unsigned src_level, 850 const struct pipe_box *src_box) 851{ 852 struct rbug_context *rb_pipe = rbug_context(_pipe); 853 struct rbug_resource *rb_resource_dst = rbug_resource(_dst); 854 struct rbug_resource *rb_resource_src = rbug_resource(_src); 855 struct pipe_context *pipe = rb_pipe->pipe; 856 struct pipe_resource *dst = rb_resource_dst->resource; 857 struct pipe_resource *src = rb_resource_src->resource; 858 859 pipe_mutex_lock(rb_pipe->call_mutex); 860 pipe->resource_copy_region(pipe, 861 dst, 862 dst_level, 863 dstx, 864 dsty, 865 dstz, 866 src, 867 src_level, 868 src_box); 869 pipe_mutex_unlock(rb_pipe->call_mutex); 870} 871 872static void 873rbug_clear(struct pipe_context *_pipe, 874 unsigned buffers, 875 const union pipe_color_union *color, 876 double depth, 877 unsigned stencil) 878{ 879 struct rbug_context *rb_pipe = rbug_context(_pipe); 880 struct pipe_context *pipe = rb_pipe->pipe; 881 882 pipe_mutex_lock(rb_pipe->call_mutex); 883 pipe->clear(pipe, 884 buffers, 885 color, 886 depth, 887 stencil); 888 pipe_mutex_unlock(rb_pipe->call_mutex); 889} 890 891static void 892rbug_clear_render_target(struct pipe_context *_pipe, 893 struct pipe_surface *_dst, 894 const union pipe_color_union *color, 895 unsigned dstx, unsigned dsty, 896 unsigned width, unsigned height) 897{ 898 struct rbug_context *rb_pipe = rbug_context(_pipe); 899 struct rbug_surface *rb_surface_dst = rbug_surface(_dst); 900 struct pipe_context *pipe = rb_pipe->pipe; 901 struct pipe_surface *dst = rb_surface_dst->surface; 902 903 pipe_mutex_lock(rb_pipe->call_mutex); 904 pipe->clear_render_target(pipe, 905 dst, 906 color, 907 dstx, 908 dsty, 909 width, 910 height); 911 pipe_mutex_unlock(rb_pipe->call_mutex); 912} 913 914static void 915rbug_clear_depth_stencil(struct pipe_context *_pipe, 916 struct pipe_surface *_dst, 917 unsigned clear_flags, 918 double depth, 919 unsigned stencil, 920 unsigned dstx, unsigned dsty, 921 unsigned width, unsigned height) 922{ 923 struct rbug_context *rb_pipe = rbug_context(_pipe); 924 struct rbug_surface *rb_surface_dst = rbug_surface(_dst); 925 struct pipe_context *pipe = rb_pipe->pipe; 926 struct pipe_surface *dst = rb_surface_dst->surface; 927 928 pipe_mutex_lock(rb_pipe->call_mutex); 929 pipe->clear_depth_stencil(pipe, 930 dst, 931 clear_flags, 932 depth, 933 stencil, 934 dstx, 935 dsty, 936 width, 937 height); 938 pipe_mutex_unlock(rb_pipe->call_mutex); 939} 940 941static void 942rbug_flush(struct pipe_context *_pipe, 943 struct pipe_fence_handle **fence) 944{ 945 struct rbug_context *rb_pipe = rbug_context(_pipe); 946 struct pipe_context *pipe = rb_pipe->pipe; 947 948 pipe_mutex_lock(rb_pipe->call_mutex); 949 pipe->flush(pipe, 950 fence); 951 pipe_mutex_unlock(rb_pipe->call_mutex); 952} 953 954static struct pipe_sampler_view * 955rbug_context_create_sampler_view(struct pipe_context *_pipe, 956 struct pipe_resource *_resource, 957 const struct pipe_sampler_view *templ) 958{ 959 struct rbug_context *rb_pipe = rbug_context(_pipe); 960 struct rbug_resource *rb_resource = rbug_resource(_resource); 961 struct pipe_context *pipe = rb_pipe->pipe; 962 struct pipe_resource *resource = rb_resource->resource; 963 struct pipe_sampler_view *result; 964 965 pipe_mutex_lock(rb_pipe->call_mutex); 966 result = pipe->create_sampler_view(pipe, 967 resource, 968 templ); 969 pipe_mutex_unlock(rb_pipe->call_mutex); 970 971 if (result) 972 return rbug_sampler_view_create(rb_pipe, rb_resource, result); 973 return NULL; 974} 975 976static void 977rbug_context_sampler_view_destroy(struct pipe_context *_pipe, 978 struct pipe_sampler_view *_view) 979{ 980 rbug_sampler_view_destroy(rbug_context(_pipe), 981 rbug_sampler_view(_view)); 982} 983 984static struct pipe_surface * 985rbug_context_create_surface(struct pipe_context *_pipe, 986 struct pipe_resource *_resource, 987 const struct pipe_surface *surf_tmpl) 988{ 989 struct rbug_context *rb_pipe = rbug_context(_pipe); 990 struct rbug_resource *rb_resource = rbug_resource(_resource); 991 struct pipe_context *pipe = rb_pipe->pipe; 992 struct pipe_resource *resource = rb_resource->resource; 993 struct pipe_surface *result; 994 995 pipe_mutex_lock(rb_pipe->call_mutex); 996 result = pipe->create_surface(pipe, 997 resource, 998 surf_tmpl); 999 pipe_mutex_unlock(rb_pipe->call_mutex); 1000 1001 if (result) 1002 return rbug_surface_create(rb_pipe, rb_resource, result); 1003 return NULL; 1004} 1005 1006static void 1007rbug_context_surface_destroy(struct pipe_context *_pipe, 1008 struct pipe_surface *_surface) 1009{ 1010 struct rbug_context *rb_pipe = rbug_context(_pipe); 1011 struct rbug_surface *rb_surface = rbug_surface(_surface); 1012 1013 pipe_mutex_lock(rb_pipe->call_mutex); 1014 rbug_surface_destroy(rb_pipe, 1015 rb_surface); 1016 pipe_mutex_unlock(rb_pipe->call_mutex); 1017} 1018 1019 1020 1021static struct pipe_transfer * 1022rbug_context_get_transfer(struct pipe_context *_context, 1023 struct pipe_resource *_resource, 1024 unsigned level, 1025 unsigned usage, 1026 const struct pipe_box *box) 1027{ 1028 struct rbug_context *rb_pipe = rbug_context(_context); 1029 struct rbug_resource *rb_resource = rbug_resource(_resource); 1030 struct pipe_context *context = rb_pipe->pipe; 1031 struct pipe_resource *resource = rb_resource->resource; 1032 struct pipe_transfer *result; 1033 1034 pipe_mutex_lock(rb_pipe->call_mutex); 1035 result = context->get_transfer(context, 1036 resource, 1037 level, 1038 usage, 1039 box); 1040 pipe_mutex_unlock(rb_pipe->call_mutex); 1041 1042 if (result) 1043 return rbug_transfer_create(rb_pipe, rb_resource, result); 1044 return NULL; 1045} 1046 1047static void 1048rbug_context_transfer_destroy(struct pipe_context *_pipe, 1049 struct pipe_transfer *_transfer) 1050{ 1051 struct rbug_context *rb_pipe = rbug_context(_pipe); 1052 struct rbug_transfer *rb_transfer =rbug_transfer(_transfer); 1053 1054 pipe_mutex_lock(rb_pipe->call_mutex); 1055 rbug_transfer_destroy(rb_pipe, 1056 rb_transfer); 1057 pipe_mutex_unlock(rb_pipe->call_mutex); 1058} 1059 1060static void * 1061rbug_context_transfer_map(struct pipe_context *_context, 1062 struct pipe_transfer *_transfer) 1063{ 1064 struct rbug_context *rb_pipe = rbug_context(_context); 1065 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); 1066 struct pipe_context *context = rb_pipe->pipe; 1067 struct pipe_transfer *transfer = rb_transfer->transfer; 1068 void *ret; 1069 1070 pipe_mutex_lock(rb_pipe->call_mutex); 1071 ret = context->transfer_map(context, 1072 transfer); 1073 pipe_mutex_unlock(rb_pipe->call_mutex); 1074 1075 return ret; 1076} 1077 1078 1079 1080static void 1081rbug_context_transfer_flush_region(struct pipe_context *_context, 1082 struct pipe_transfer *_transfer, 1083 const struct pipe_box *box) 1084{ 1085 struct rbug_context *rb_pipe = rbug_context(_context); 1086 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); 1087 struct pipe_context *context = rb_pipe->pipe; 1088 struct pipe_transfer *transfer = rb_transfer->transfer; 1089 1090 pipe_mutex_lock(rb_pipe->call_mutex); 1091 context->transfer_flush_region(context, 1092 transfer, 1093 box); 1094 pipe_mutex_unlock(rb_pipe->call_mutex); 1095} 1096 1097 1098static void 1099rbug_context_transfer_unmap(struct pipe_context *_context, 1100 struct pipe_transfer *_transfer) 1101{ 1102 struct rbug_context *rb_pipe = rbug_context(_context); 1103 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); 1104 struct pipe_context *context = rb_pipe->pipe; 1105 struct pipe_transfer *transfer = rb_transfer->transfer; 1106 1107 pipe_mutex_lock(rb_pipe->call_mutex); 1108 context->transfer_unmap(context, 1109 transfer); 1110 pipe_mutex_unlock(rb_pipe->call_mutex); 1111} 1112 1113 1114static void 1115rbug_context_transfer_inline_write(struct pipe_context *_context, 1116 struct pipe_resource *_resource, 1117 unsigned level, 1118 unsigned usage, 1119 const struct pipe_box *box, 1120 const void *data, 1121 unsigned stride, 1122 unsigned layer_stride) 1123{ 1124 struct rbug_context *rb_pipe = rbug_context(_context); 1125 struct rbug_resource *rb_resource = rbug_resource(_resource); 1126 struct pipe_context *context = rb_pipe->pipe; 1127 struct pipe_resource *resource = rb_resource->resource; 1128 1129 pipe_mutex_lock(rb_pipe->call_mutex); 1130 context->transfer_inline_write(context, 1131 resource, 1132 level, 1133 usage, 1134 box, 1135 data, 1136 stride, 1137 layer_stride); 1138 pipe_mutex_unlock(rb_pipe->call_mutex); 1139} 1140 1141 1142struct pipe_context * 1143rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) 1144{ 1145 struct rbug_context *rb_pipe; 1146 struct rbug_screen *rb_screen = rbug_screen(_screen); 1147 1148 if (!rb_screen) 1149 return NULL; 1150 1151 rb_pipe = CALLOC_STRUCT(rbug_context); 1152 if (!rb_pipe) 1153 return NULL; 1154 1155 pipe_mutex_init(rb_pipe->draw_mutex); 1156 pipe_condvar_init(rb_pipe->draw_cond); 1157 pipe_mutex_init(rb_pipe->call_mutex); 1158 pipe_mutex_init(rb_pipe->list_mutex); 1159 make_empty_list(&rb_pipe->shaders); 1160 1161 rb_pipe->base.screen = _screen; 1162 rb_pipe->base.priv = pipe->priv; /* expose wrapped data */ 1163 rb_pipe->base.draw = NULL; 1164 1165 rb_pipe->base.destroy = rbug_destroy; 1166 rb_pipe->base.draw_vbo = rbug_draw_vbo; 1167 rb_pipe->base.create_query = rbug_create_query; 1168 rb_pipe->base.destroy_query = rbug_destroy_query; 1169 rb_pipe->base.begin_query = rbug_begin_query; 1170 rb_pipe->base.end_query = rbug_end_query; 1171 rb_pipe->base.get_query_result = rbug_get_query_result; 1172 rb_pipe->base.create_blend_state = rbug_create_blend_state; 1173 rb_pipe->base.bind_blend_state = rbug_bind_blend_state; 1174 rb_pipe->base.delete_blend_state = rbug_delete_blend_state; 1175 rb_pipe->base.create_sampler_state = rbug_create_sampler_state; 1176 rb_pipe->base.bind_fragment_sampler_states = rbug_bind_fragment_sampler_states; 1177 rb_pipe->base.bind_vertex_sampler_states = rbug_bind_vertex_sampler_states; 1178 rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state; 1179 rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state; 1180 rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state; 1181 rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state; 1182 rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state; 1183 rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state; 1184 rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state; 1185 rb_pipe->base.create_fs_state = rbug_create_fs_state; 1186 rb_pipe->base.bind_fs_state = rbug_bind_fs_state; 1187 rb_pipe->base.delete_fs_state = rbug_delete_fs_state; 1188 rb_pipe->base.create_vs_state = rbug_create_vs_state; 1189 rb_pipe->base.bind_vs_state = rbug_bind_vs_state; 1190 rb_pipe->base.delete_vs_state = rbug_delete_vs_state; 1191 rb_pipe->base.create_gs_state = rbug_create_gs_state; 1192 rb_pipe->base.bind_gs_state = rbug_bind_gs_state; 1193 rb_pipe->base.delete_gs_state = rbug_delete_gs_state; 1194 rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state; 1195 rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state; 1196 rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state; 1197 rb_pipe->base.set_blend_color = rbug_set_blend_color; 1198 rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref; 1199 rb_pipe->base.set_clip_state = rbug_set_clip_state; 1200 rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer; 1201 rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state; 1202 rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple; 1203 rb_pipe->base.set_scissor_state = rbug_set_scissor_state; 1204 rb_pipe->base.set_viewport_state = rbug_set_viewport_state; 1205 rb_pipe->base.set_fragment_sampler_views = rbug_set_fragment_sampler_views; 1206 rb_pipe->base.set_vertex_sampler_views = rbug_set_vertex_sampler_views; 1207 rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers; 1208 rb_pipe->base.set_index_buffer = rbug_set_index_buffer; 1209 rb_pipe->base.set_sample_mask = rbug_set_sample_mask; 1210 rb_pipe->base.resource_copy_region = rbug_resource_copy_region; 1211 rb_pipe->base.clear = rbug_clear; 1212 rb_pipe->base.clear_render_target = rbug_clear_render_target; 1213 rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil; 1214 rb_pipe->base.flush = rbug_flush; 1215 rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view; 1216 rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy; 1217 rb_pipe->base.create_surface = rbug_context_create_surface; 1218 rb_pipe->base.surface_destroy = rbug_context_surface_destroy; 1219 rb_pipe->base.get_transfer = rbug_context_get_transfer; 1220 rb_pipe->base.transfer_destroy = rbug_context_transfer_destroy; 1221 rb_pipe->base.transfer_map = rbug_context_transfer_map; 1222 rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap; 1223 rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region; 1224 rb_pipe->base.transfer_inline_write = rbug_context_transfer_inline_write; 1225 1226 rb_pipe->pipe = pipe; 1227 1228 rbug_screen_add_to_list(rb_screen, contexts, rb_pipe); 1229 1230 if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE)) { 1231 rb_pipe->draw_blocked = RBUG_BLOCK_BEFORE; 1232 } 1233 1234 return &rb_pipe->base; 1235} 1236