glhd_context.c revision d3ad6fa579d89d8c3ee27882d5baf8f8d2ecb3ea
1/************************************************************************** 2 * 3 * Copyright 2009 VMware, Inc. 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 VMWARE 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#include "pipe/p_context.h" 30#include "util/u_memory.h" 31#include "util/u_inlines.h" 32 33#include "glhd_context.h" 34#include "glhd_objects.h" 35 36 37static void 38galahad_destroy(struct pipe_context *_pipe) 39{ 40 struct galahad_context *glhd_pipe = galahad_context(_pipe); 41 struct pipe_context *pipe = glhd_pipe->pipe; 42 43 pipe->destroy(pipe); 44 45 FREE(glhd_pipe); 46} 47 48static void 49galahad_draw_arrays(struct pipe_context *_pipe, 50 unsigned prim, 51 unsigned start, 52 unsigned count) 53{ 54 struct galahad_context *glhd_pipe = galahad_context(_pipe); 55 struct pipe_context *pipe = glhd_pipe->pipe; 56 57 pipe->draw_arrays(pipe, 58 prim, 59 start, 60 count); 61} 62 63static void 64galahad_draw_elements(struct pipe_context *_pipe, 65 struct pipe_resource *_indexResource, 66 unsigned indexSize, 67 int indexBias, 68 unsigned prim, 69 unsigned start, 70 unsigned count) 71{ 72 struct galahad_context *glhd_pipe = galahad_context(_pipe); 73 struct galahad_resource *glhd_resource = galahad_resource(_indexResource); 74 struct pipe_context *pipe = glhd_pipe->pipe; 75 struct pipe_resource *indexResource = glhd_resource->resource; 76 77 pipe->draw_elements(pipe, 78 indexResource, 79 indexSize, 80 indexBias, 81 prim, 82 start, 83 count); 84} 85 86static void 87galahad_draw_range_elements(struct pipe_context *_pipe, 88 struct pipe_resource *_indexResource, 89 unsigned indexSize, 90 int indexBias, 91 unsigned minIndex, 92 unsigned maxIndex, 93 unsigned mode, 94 unsigned start, 95 unsigned count) 96{ 97 struct galahad_context *glhd_pipe = galahad_context(_pipe); 98 struct galahad_resource *glhd_resource = galahad_resource(_indexResource); 99 struct pipe_context *pipe = glhd_pipe->pipe; 100 struct pipe_resource *indexResource = glhd_resource->resource; 101 102 pipe->draw_range_elements(pipe, 103 indexResource, 104 indexSize, 105 indexBias, 106 minIndex, 107 maxIndex, 108 mode, 109 start, 110 count); 111} 112 113static struct pipe_query * 114galahad_create_query(struct pipe_context *_pipe, 115 unsigned query_type) 116{ 117 struct galahad_context *glhd_pipe = galahad_context(_pipe); 118 struct pipe_context *pipe = glhd_pipe->pipe; 119 120 return pipe->create_query(pipe, 121 query_type); 122} 123 124static void 125galahad_destroy_query(struct pipe_context *_pipe, 126 struct pipe_query *query) 127{ 128 struct galahad_context *glhd_pipe = galahad_context(_pipe); 129 struct pipe_context *pipe = glhd_pipe->pipe; 130 131 pipe->destroy_query(pipe, 132 query); 133} 134 135static void 136galahad_begin_query(struct pipe_context *_pipe, 137 struct pipe_query *query) 138{ 139 struct galahad_context *glhd_pipe = galahad_context(_pipe); 140 struct pipe_context *pipe = glhd_pipe->pipe; 141 142 pipe->begin_query(pipe, 143 query); 144} 145 146static void 147galahad_end_query(struct pipe_context *_pipe, 148 struct pipe_query *query) 149{ 150 struct galahad_context *glhd_pipe = galahad_context(_pipe); 151 struct pipe_context *pipe = glhd_pipe->pipe; 152 153 pipe->end_query(pipe, 154 query); 155} 156 157static boolean 158galahad_get_query_result(struct pipe_context *_pipe, 159 struct pipe_query *query, 160 boolean wait, 161 void *result) 162{ 163 struct galahad_context *glhd_pipe = galahad_context(_pipe); 164 struct pipe_context *pipe = glhd_pipe->pipe; 165 166 return pipe->get_query_result(pipe, 167 query, 168 wait, 169 result); 170} 171 172static void * 173galahad_create_blend_state(struct pipe_context *_pipe, 174 const struct pipe_blend_state *blend) 175{ 176 struct galahad_context *glhd_pipe = galahad_context(_pipe); 177 struct pipe_context *pipe = glhd_pipe->pipe; 178 179 return pipe->create_blend_state(pipe, 180 blend); 181} 182 183static void 184galahad_bind_blend_state(struct pipe_context *_pipe, 185 void *blend) 186{ 187 struct galahad_context *glhd_pipe = galahad_context(_pipe); 188 struct pipe_context *pipe = glhd_pipe->pipe; 189 190 pipe->bind_blend_state(pipe, 191 blend); 192} 193 194static void 195galahad_delete_blend_state(struct pipe_context *_pipe, 196 void *blend) 197{ 198 struct galahad_context *glhd_pipe = galahad_context(_pipe); 199 struct pipe_context *pipe = glhd_pipe->pipe; 200 201 pipe->delete_blend_state(pipe, 202 blend); 203} 204 205static void * 206galahad_create_sampler_state(struct pipe_context *_pipe, 207 const struct pipe_sampler_state *sampler) 208{ 209 struct galahad_context *glhd_pipe = galahad_context(_pipe); 210 struct pipe_context *pipe = glhd_pipe->pipe; 211 212 return pipe->create_sampler_state(pipe, 213 sampler); 214} 215 216static void 217galahad_bind_fragment_sampler_states(struct pipe_context *_pipe, 218 unsigned num_samplers, 219 void **samplers) 220{ 221 struct galahad_context *glhd_pipe = galahad_context(_pipe); 222 struct pipe_context *pipe = glhd_pipe->pipe; 223 224 pipe->bind_fragment_sampler_states(pipe, 225 num_samplers, 226 samplers); 227} 228 229static void 230galahad_bind_vertex_sampler_states(struct pipe_context *_pipe, 231 unsigned num_samplers, 232 void **samplers) 233{ 234 struct galahad_context *glhd_pipe = galahad_context(_pipe); 235 struct pipe_context *pipe = glhd_pipe->pipe; 236 237 pipe->bind_vertex_sampler_states(pipe, 238 num_samplers, 239 samplers); 240} 241 242static void 243galahad_delete_sampler_state(struct pipe_context *_pipe, 244 void *sampler) 245{ 246 struct galahad_context *glhd_pipe = galahad_context(_pipe); 247 struct pipe_context *pipe = glhd_pipe->pipe; 248 249 pipe->delete_sampler_state(pipe, 250 sampler); 251} 252 253static void * 254galahad_create_rasterizer_state(struct pipe_context *_pipe, 255 const struct pipe_rasterizer_state *rasterizer) 256{ 257 struct galahad_context *glhd_pipe = galahad_context(_pipe); 258 struct pipe_context *pipe = glhd_pipe->pipe; 259 260 return pipe->create_rasterizer_state(pipe, 261 rasterizer); 262} 263 264static void 265galahad_bind_rasterizer_state(struct pipe_context *_pipe, 266 void *rasterizer) 267{ 268 struct galahad_context *glhd_pipe = galahad_context(_pipe); 269 struct pipe_context *pipe = glhd_pipe->pipe; 270 271 pipe->bind_rasterizer_state(pipe, 272 rasterizer); 273} 274 275static void 276galahad_delete_rasterizer_state(struct pipe_context *_pipe, 277 void *rasterizer) 278{ 279 struct galahad_context *glhd_pipe = galahad_context(_pipe); 280 struct pipe_context *pipe = glhd_pipe->pipe; 281 282 pipe->delete_rasterizer_state(pipe, 283 rasterizer); 284} 285 286static void * 287galahad_create_depth_stencil_alpha_state(struct pipe_context *_pipe, 288 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha) 289{ 290 struct galahad_context *glhd_pipe = galahad_context(_pipe); 291 struct pipe_context *pipe = glhd_pipe->pipe; 292 293 return pipe->create_depth_stencil_alpha_state(pipe, 294 depth_stencil_alpha); 295} 296 297static void 298galahad_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, 299 void *depth_stencil_alpha) 300{ 301 struct galahad_context *glhd_pipe = galahad_context(_pipe); 302 struct pipe_context *pipe = glhd_pipe->pipe; 303 304 pipe->bind_depth_stencil_alpha_state(pipe, 305 depth_stencil_alpha); 306} 307 308static void 309galahad_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, 310 void *depth_stencil_alpha) 311{ 312 struct galahad_context *glhd_pipe = galahad_context(_pipe); 313 struct pipe_context *pipe = glhd_pipe->pipe; 314 315 pipe->delete_depth_stencil_alpha_state(pipe, 316 depth_stencil_alpha); 317} 318 319static void * 320galahad_create_fs_state(struct pipe_context *_pipe, 321 const struct pipe_shader_state *fs) 322{ 323 struct galahad_context *glhd_pipe = galahad_context(_pipe); 324 struct pipe_context *pipe = glhd_pipe->pipe; 325 326 return pipe->create_fs_state(pipe, 327 fs); 328} 329 330static void 331galahad_bind_fs_state(struct pipe_context *_pipe, 332 void *fs) 333{ 334 struct galahad_context *glhd_pipe = galahad_context(_pipe); 335 struct pipe_context *pipe = glhd_pipe->pipe; 336 337 pipe->bind_fs_state(pipe, 338 fs); 339} 340 341static void 342galahad_delete_fs_state(struct pipe_context *_pipe, 343 void *fs) 344{ 345 struct galahad_context *glhd_pipe = galahad_context(_pipe); 346 struct pipe_context *pipe = glhd_pipe->pipe; 347 348 pipe->delete_fs_state(pipe, 349 fs); 350} 351 352static void * 353galahad_create_vs_state(struct pipe_context *_pipe, 354 const struct pipe_shader_state *vs) 355{ 356 struct galahad_context *glhd_pipe = galahad_context(_pipe); 357 struct pipe_context *pipe = glhd_pipe->pipe; 358 359 return pipe->create_vs_state(pipe, 360 vs); 361} 362 363static void 364galahad_bind_vs_state(struct pipe_context *_pipe, 365 void *vs) 366{ 367 struct galahad_context *glhd_pipe = galahad_context(_pipe); 368 struct pipe_context *pipe = glhd_pipe->pipe; 369 370 pipe->bind_vs_state(pipe, 371 vs); 372} 373 374static void 375galahad_delete_vs_state(struct pipe_context *_pipe, 376 void *vs) 377{ 378 struct galahad_context *glhd_pipe = galahad_context(_pipe); 379 struct pipe_context *pipe = glhd_pipe->pipe; 380 381 pipe->delete_vs_state(pipe, 382 vs); 383} 384 385 386static void * 387galahad_create_vertex_elements_state(struct pipe_context *_pipe, 388 unsigned num_elements, 389 const struct pipe_vertex_element *vertex_elements) 390{ 391 struct galahad_context *glhd_pipe = galahad_context(_pipe); 392 struct pipe_context *pipe = glhd_pipe->pipe; 393 394 return pipe->create_vertex_elements_state(pipe, 395 num_elements, 396 vertex_elements); 397} 398 399static void 400galahad_bind_vertex_elements_state(struct pipe_context *_pipe, 401 void *velems) 402{ 403 struct galahad_context *glhd_pipe = galahad_context(_pipe); 404 struct pipe_context *pipe = glhd_pipe->pipe; 405 406 pipe->bind_vertex_elements_state(pipe, 407 velems); 408} 409 410static void 411galahad_delete_vertex_elements_state(struct pipe_context *_pipe, 412 void *velems) 413{ 414 struct galahad_context *glhd_pipe = galahad_context(_pipe); 415 struct pipe_context *pipe = glhd_pipe->pipe; 416 417 pipe->delete_vertex_elements_state(pipe, 418 velems); 419} 420 421static void 422galahad_set_blend_color(struct pipe_context *_pipe, 423 const struct pipe_blend_color *blend_color) 424{ 425 struct galahad_context *glhd_pipe = galahad_context(_pipe); 426 struct pipe_context *pipe = glhd_pipe->pipe; 427 428 pipe->set_blend_color(pipe, 429 blend_color); 430} 431 432static void 433galahad_set_stencil_ref(struct pipe_context *_pipe, 434 const struct pipe_stencil_ref *stencil_ref) 435{ 436 struct galahad_context *glhd_pipe = galahad_context(_pipe); 437 struct pipe_context *pipe = glhd_pipe->pipe; 438 439 pipe->set_stencil_ref(pipe, 440 stencil_ref); 441} 442 443static void 444galahad_set_clip_state(struct pipe_context *_pipe, 445 const struct pipe_clip_state *clip) 446{ 447 struct galahad_context *glhd_pipe = galahad_context(_pipe); 448 struct pipe_context *pipe = glhd_pipe->pipe; 449 450 pipe->set_clip_state(pipe, 451 clip); 452} 453 454static void 455galahad_set_sample_mask(struct pipe_context *_pipe, 456 unsigned sample_mask) 457{ 458 struct galahad_context *glhd_pipe = galahad_context(_pipe); 459 struct pipe_context *pipe = glhd_pipe->pipe; 460 461 pipe->set_sample_mask(pipe, 462 sample_mask); 463} 464 465static void 466galahad_set_constant_buffer(struct pipe_context *_pipe, 467 uint shader, 468 uint index, 469 struct pipe_resource *_resource) 470{ 471 struct galahad_context *glhd_pipe = galahad_context(_pipe); 472 struct pipe_context *pipe = glhd_pipe->pipe; 473 struct pipe_resource *unwrapped_resource; 474 struct pipe_resource *resource = NULL; 475 476 /* XXX hmm? unwrap the input state */ 477 if (_resource) { 478 unwrapped_resource = galahad_resource_unwrap(_resource); 479 resource = unwrapped_resource; 480 } 481 482 pipe->set_constant_buffer(pipe, 483 shader, 484 index, 485 resource); 486} 487 488static void 489galahad_set_framebuffer_state(struct pipe_context *_pipe, 490 const struct pipe_framebuffer_state *_state) 491{ 492 struct galahad_context *glhd_pipe = galahad_context(_pipe); 493 struct pipe_context *pipe = glhd_pipe->pipe; 494 struct pipe_framebuffer_state unwrapped_state; 495 struct pipe_framebuffer_state *state = NULL; 496 unsigned i; 497 498 /* unwrap the input state */ 499 if (_state) { 500 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state)); 501 for(i = 0; i < _state->nr_cbufs; i++) 502 unwrapped_state.cbufs[i] = galahad_surface_unwrap(_state->cbufs[i]); 503 for (; i < PIPE_MAX_COLOR_BUFS; i++) 504 unwrapped_state.cbufs[i] = NULL; 505 unwrapped_state.zsbuf = galahad_surface_unwrap(_state->zsbuf); 506 state = &unwrapped_state; 507 } 508 509 pipe->set_framebuffer_state(pipe, 510 state); 511} 512 513static void 514galahad_set_polygon_stipple(struct pipe_context *_pipe, 515 const struct pipe_poly_stipple *poly_stipple) 516{ 517 struct galahad_context *glhd_pipe = galahad_context(_pipe); 518 struct pipe_context *pipe = glhd_pipe->pipe; 519 520 pipe->set_polygon_stipple(pipe, 521 poly_stipple); 522} 523 524static void 525galahad_set_scissor_state(struct pipe_context *_pipe, 526 const struct pipe_scissor_state *scissor) 527{ 528 struct galahad_context *glhd_pipe = galahad_context(_pipe); 529 struct pipe_context *pipe = glhd_pipe->pipe; 530 531 pipe->set_scissor_state(pipe, 532 scissor); 533} 534 535static void 536galahad_set_viewport_state(struct pipe_context *_pipe, 537 const struct pipe_viewport_state *viewport) 538{ 539 struct galahad_context *glhd_pipe = galahad_context(_pipe); 540 struct pipe_context *pipe = glhd_pipe->pipe; 541 542 pipe->set_viewport_state(pipe, 543 viewport); 544} 545 546static void 547galahad_set_fragment_sampler_views(struct pipe_context *_pipe, 548 unsigned num, 549 struct pipe_sampler_view **_views) 550{ 551 struct galahad_context *glhd_pipe = galahad_context(_pipe); 552 struct pipe_context *pipe = glhd_pipe->pipe; 553 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; 554 struct pipe_sampler_view **views = NULL; 555 unsigned i; 556 557 if (_views) { 558 for (i = 0; i < num; i++) 559 unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]); 560 for (; i < PIPE_MAX_SAMPLERS; i++) 561 unwrapped_views[i] = NULL; 562 563 views = unwrapped_views; 564 } 565 566 pipe->set_fragment_sampler_views(pipe, num, views); 567} 568 569static void 570galahad_set_vertex_sampler_views(struct pipe_context *_pipe, 571 unsigned num, 572 struct pipe_sampler_view **_views) 573{ 574 struct galahad_context *glhd_pipe = galahad_context(_pipe); 575 struct pipe_context *pipe = glhd_pipe->pipe; 576 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; 577 struct pipe_sampler_view **views = NULL; 578 unsigned i; 579 580 if (_views) { 581 for (i = 0; i < num; i++) 582 unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]); 583 for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++) 584 unwrapped_views[i] = NULL; 585 586 views = unwrapped_views; 587 } 588 589 pipe->set_vertex_sampler_views(pipe, num, views); 590} 591 592static void 593galahad_set_vertex_buffers(struct pipe_context *_pipe, 594 unsigned num_buffers, 595 const struct pipe_vertex_buffer *_buffers) 596{ 597 struct galahad_context *glhd_pipe = galahad_context(_pipe); 598 struct pipe_context *pipe = glhd_pipe->pipe; 599 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS]; 600 struct pipe_vertex_buffer *buffers = NULL; 601 unsigned i; 602 603 if (num_buffers) { 604 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); 605 for (i = 0; i < num_buffers; i++) 606 unwrapped_buffers[i].buffer = galahad_resource_unwrap(_buffers[i].buffer); 607 buffers = unwrapped_buffers; 608 } 609 610 pipe->set_vertex_buffers(pipe, 611 num_buffers, 612 buffers); 613} 614static void 615galahad_resource_copy_region(struct pipe_context *_pipe, 616 struct pipe_resource *_dst, 617 struct pipe_subresource subdst, 618 unsigned dstx, 619 unsigned dsty, 620 unsigned dstz, 621 struct pipe_resource *_src, 622 struct pipe_subresource subsrc, 623 unsigned srcx, 624 unsigned srcy, 625 unsigned srcz, 626 unsigned width, 627 unsigned height) 628{ 629 struct galahad_context *glhd_pipe = galahad_context(_pipe); 630 struct galahad_resource *glhd_resource_dst = galahad_resource(_dst); 631 struct galahad_resource *glhd_resource_src = galahad_resource(_src); 632 struct pipe_context *pipe = glhd_pipe->pipe; 633 struct pipe_resource *dst = glhd_resource_dst->resource; 634 struct pipe_resource *src = glhd_resource_src->resource; 635 636 pipe->resource_copy_region(pipe, 637 dst, 638 subdst, 639 dstx, 640 dsty, 641 dstz, 642 src, 643 subsrc, 644 srcx, 645 srcy, 646 srcz, 647 width, 648 height); 649} 650 651static void 652galahad_clear(struct pipe_context *_pipe, 653 unsigned buffers, 654 const float *rgba, 655 double depth, 656 unsigned stencil) 657{ 658 struct galahad_context *glhd_pipe = galahad_context(_pipe); 659 struct pipe_context *pipe = glhd_pipe->pipe; 660 661 pipe->clear(pipe, 662 buffers, 663 rgba, 664 depth, 665 stencil); 666} 667 668static void 669galahad_clear_render_target(struct pipe_context *_pipe, 670 struct pipe_surface *_dst, 671 const float *rgba, 672 unsigned dstx, unsigned dsty, 673 unsigned width, unsigned height) 674{ 675 struct galahad_context *glhd_pipe = galahad_context(_pipe); 676 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst); 677 struct pipe_context *pipe = glhd_pipe->pipe; 678 struct pipe_surface *dst = glhd_surface_dst->surface; 679 680 pipe->clear_render_target(pipe, 681 dst, 682 rgba, 683 dstx, 684 dsty, 685 width, 686 height); 687} 688static void 689galahad_clear_depth_stencil(struct pipe_context *_pipe, 690 struct pipe_surface *_dst, 691 unsigned clear_flags, 692 double depth, 693 unsigned stencil, 694 unsigned dstx, unsigned dsty, 695 unsigned width, unsigned height) 696{ 697 struct galahad_context *glhd_pipe = galahad_context(_pipe); 698 struct galahad_surface *glhd_surface_dst = galahad_surface(_dst); 699 struct pipe_context *pipe = glhd_pipe->pipe; 700 struct pipe_surface *dst = glhd_surface_dst->surface; 701 702 pipe->clear_depth_stencil(pipe, 703 dst, 704 clear_flags, 705 depth, 706 stencil, 707 dstx, 708 dsty, 709 width, 710 height); 711 712} 713 714static void 715galahad_flush(struct pipe_context *_pipe, 716 unsigned flags, 717 struct pipe_fence_handle **fence) 718{ 719 struct galahad_context *glhd_pipe = galahad_context(_pipe); 720 struct pipe_context *pipe = glhd_pipe->pipe; 721 722 pipe->flush(pipe, 723 flags, 724 fence); 725} 726 727static unsigned int 728galahad_is_resource_referenced(struct pipe_context *_pipe, 729 struct pipe_resource *_resource, 730 unsigned face, 731 unsigned level) 732{ 733 struct galahad_context *glhd_pipe = galahad_context(_pipe); 734 struct galahad_resource *glhd_resource = galahad_resource(_resource); 735 struct pipe_context *pipe = glhd_pipe->pipe; 736 struct pipe_resource *resource = glhd_resource->resource; 737 738 return pipe->is_resource_referenced(pipe, 739 resource, 740 face, 741 level); 742} 743 744static struct pipe_sampler_view * 745galahad_context_create_sampler_view(struct pipe_context *_pipe, 746 struct pipe_resource *_resource, 747 const struct pipe_sampler_view *templ) 748{ 749 struct galahad_context *glhd_context = galahad_context(_pipe); 750 struct galahad_resource *glhd_resource = galahad_resource(_resource); 751 struct pipe_context *pipe = glhd_context->pipe; 752 struct pipe_resource *resource = glhd_resource->resource; 753 struct pipe_sampler_view *result; 754 755 result = pipe->create_sampler_view(pipe, 756 resource, 757 templ); 758 759 if (result) 760 return galahad_sampler_view_create(glhd_context, glhd_resource, result); 761 return NULL; 762} 763 764static void 765galahad_context_sampler_view_destroy(struct pipe_context *_pipe, 766 struct pipe_sampler_view *_view) 767{ 768 galahad_sampler_view_destroy(galahad_context(_pipe), 769 galahad_sampler_view(_view)); 770} 771 772static struct pipe_transfer * 773galahad_context_get_transfer(struct pipe_context *_context, 774 struct pipe_resource *_resource, 775 struct pipe_subresource sr, 776 unsigned usage, 777 const struct pipe_box *box) 778{ 779 struct galahad_context *glhd_context = galahad_context(_context); 780 struct galahad_resource *glhd_resource = galahad_resource(_resource); 781 struct pipe_context *context = glhd_context->pipe; 782 struct pipe_resource *resource = glhd_resource->resource; 783 struct pipe_transfer *result; 784 785 result = context->get_transfer(context, 786 resource, 787 sr, 788 usage, 789 box); 790 791 if (result) 792 return galahad_transfer_create(glhd_context, glhd_resource, result); 793 return NULL; 794} 795 796static void 797galahad_context_transfer_destroy(struct pipe_context *_pipe, 798 struct pipe_transfer *_transfer) 799{ 800 galahad_transfer_destroy(galahad_context(_pipe), 801 galahad_transfer(_transfer)); 802} 803 804static void * 805galahad_context_transfer_map(struct pipe_context *_context, 806 struct pipe_transfer *_transfer) 807{ 808 struct galahad_context *glhd_context = galahad_context(_context); 809 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); 810 struct pipe_context *context = glhd_context->pipe; 811 struct pipe_transfer *transfer = glhd_transfer->transfer; 812 813 return context->transfer_map(context, 814 transfer); 815} 816 817 818 819static void 820galahad_context_transfer_flush_region(struct pipe_context *_context, 821 struct pipe_transfer *_transfer, 822 const struct pipe_box *box) 823{ 824 struct galahad_context *glhd_context = galahad_context(_context); 825 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); 826 struct pipe_context *context = glhd_context->pipe; 827 struct pipe_transfer *transfer = glhd_transfer->transfer; 828 829 context->transfer_flush_region(context, 830 transfer, 831 box); 832} 833 834 835static void 836galahad_context_transfer_unmap(struct pipe_context *_context, 837 struct pipe_transfer *_transfer) 838{ 839 struct galahad_context *glhd_context = galahad_context(_context); 840 struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); 841 struct pipe_context *context = glhd_context->pipe; 842 struct pipe_transfer *transfer = glhd_transfer->transfer; 843 844 context->transfer_unmap(context, 845 transfer); 846} 847 848 849static void 850galahad_context_transfer_inline_write(struct pipe_context *_context, 851 struct pipe_resource *_resource, 852 struct pipe_subresource sr, 853 unsigned usage, 854 const struct pipe_box *box, 855 const void *data, 856 unsigned stride, 857 unsigned slice_stride) 858{ 859 struct galahad_context *glhd_context = galahad_context(_context); 860 struct galahad_resource *glhd_resource = galahad_resource(_resource); 861 struct pipe_context *context = glhd_context->pipe; 862 struct pipe_resource *resource = glhd_resource->resource; 863 864 context->transfer_inline_write(context, 865 resource, 866 sr, 867 usage, 868 box, 869 data, 870 stride, 871 slice_stride); 872} 873 874 875struct pipe_context * 876galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) 877{ 878 struct galahad_context *glhd_pipe; 879 (void)galahad_screen(_screen); 880 881 glhd_pipe = CALLOC_STRUCT(galahad_context); 882 if (!glhd_pipe) { 883 return NULL; 884 } 885 886 glhd_pipe->base.winsys = NULL; 887 glhd_pipe->base.screen = _screen; 888 glhd_pipe->base.priv = pipe->priv; /* expose wrapped data */ 889 glhd_pipe->base.draw = NULL; 890 891 glhd_pipe->base.destroy = galahad_destroy; 892 glhd_pipe->base.draw_arrays = galahad_draw_arrays; 893 glhd_pipe->base.draw_elements = galahad_draw_elements; 894 glhd_pipe->base.draw_range_elements = galahad_draw_range_elements; 895 glhd_pipe->base.create_query = galahad_create_query; 896 glhd_pipe->base.destroy_query = galahad_destroy_query; 897 glhd_pipe->base.begin_query = galahad_begin_query; 898 glhd_pipe->base.end_query = galahad_end_query; 899 glhd_pipe->base.get_query_result = galahad_get_query_result; 900 glhd_pipe->base.create_blend_state = galahad_create_blend_state; 901 glhd_pipe->base.bind_blend_state = galahad_bind_blend_state; 902 glhd_pipe->base.delete_blend_state = galahad_delete_blend_state; 903 glhd_pipe->base.create_sampler_state = galahad_create_sampler_state; 904 glhd_pipe->base.bind_fragment_sampler_states = galahad_bind_fragment_sampler_states; 905 glhd_pipe->base.bind_vertex_sampler_states = galahad_bind_vertex_sampler_states; 906 glhd_pipe->base.delete_sampler_state = galahad_delete_sampler_state; 907 glhd_pipe->base.create_rasterizer_state = galahad_create_rasterizer_state; 908 glhd_pipe->base.bind_rasterizer_state = galahad_bind_rasterizer_state; 909 glhd_pipe->base.delete_rasterizer_state = galahad_delete_rasterizer_state; 910 glhd_pipe->base.create_depth_stencil_alpha_state = galahad_create_depth_stencil_alpha_state; 911 glhd_pipe->base.bind_depth_stencil_alpha_state = galahad_bind_depth_stencil_alpha_state; 912 glhd_pipe->base.delete_depth_stencil_alpha_state = galahad_delete_depth_stencil_alpha_state; 913 glhd_pipe->base.create_fs_state = galahad_create_fs_state; 914 glhd_pipe->base.bind_fs_state = galahad_bind_fs_state; 915 glhd_pipe->base.delete_fs_state = galahad_delete_fs_state; 916 glhd_pipe->base.create_vs_state = galahad_create_vs_state; 917 glhd_pipe->base.bind_vs_state = galahad_bind_vs_state; 918 glhd_pipe->base.delete_vs_state = galahad_delete_vs_state; 919 glhd_pipe->base.create_vertex_elements_state = galahad_create_vertex_elements_state; 920 glhd_pipe->base.bind_vertex_elements_state = galahad_bind_vertex_elements_state; 921 glhd_pipe->base.delete_vertex_elements_state = galahad_delete_vertex_elements_state; 922 glhd_pipe->base.set_blend_color = galahad_set_blend_color; 923 glhd_pipe->base.set_stencil_ref = galahad_set_stencil_ref; 924 glhd_pipe->base.set_clip_state = galahad_set_clip_state; 925 glhd_pipe->base.set_sample_mask = galahad_set_sample_mask; 926 glhd_pipe->base.set_constant_buffer = galahad_set_constant_buffer; 927 glhd_pipe->base.set_framebuffer_state = galahad_set_framebuffer_state; 928 glhd_pipe->base.set_polygon_stipple = galahad_set_polygon_stipple; 929 glhd_pipe->base.set_scissor_state = galahad_set_scissor_state; 930 glhd_pipe->base.set_viewport_state = galahad_set_viewport_state; 931 glhd_pipe->base.set_fragment_sampler_views = galahad_set_fragment_sampler_views; 932 glhd_pipe->base.set_vertex_sampler_views = galahad_set_vertex_sampler_views; 933 glhd_pipe->base.set_vertex_buffers = galahad_set_vertex_buffers; 934 glhd_pipe->base.resource_copy_region = galahad_resource_copy_region; 935 glhd_pipe->base.clear = galahad_clear; 936 glhd_pipe->base.clear_render_target = galahad_clear_render_target; 937 glhd_pipe->base.clear_depth_stencil = galahad_clear_depth_stencil; 938 glhd_pipe->base.flush = galahad_flush; 939 glhd_pipe->base.is_resource_referenced = galahad_is_resource_referenced; 940 glhd_pipe->base.create_sampler_view = galahad_context_create_sampler_view; 941 glhd_pipe->base.sampler_view_destroy = galahad_context_sampler_view_destroy; 942 glhd_pipe->base.get_transfer = galahad_context_get_transfer; 943 glhd_pipe->base.transfer_destroy = galahad_context_transfer_destroy; 944 glhd_pipe->base.transfer_map = galahad_context_transfer_map; 945 glhd_pipe->base.transfer_unmap = galahad_context_transfer_unmap; 946 glhd_pipe->base.transfer_flush_region = galahad_context_transfer_flush_region; 947 glhd_pipe->base.transfer_inline_write = galahad_context_transfer_inline_write; 948 949 glhd_pipe->pipe = pipe; 950 951 return &glhd_pipe->base; 952} 953