1/********************************************************** 2 * Copyright 2008-2013 VMware, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 **********************************************************/ 25 26/** 27 * @file svga_cmd_vgpu10.c 28 * 29 * Command construction utility for the vgpu10 SVGA3D protocol. 30 * 31 * \author Mingcheng Chen 32 * \author Brian Paul 33 */ 34 35 36#include "svga_winsys.h" 37#include "svga_resource_buffer.h" 38#include "svga_resource_texture.h" 39#include "svga_surface.h" 40#include "svga_cmd.h" 41 42 43/** 44 * Emit a surface relocation for RenderTargetViewId 45 */ 46static void 47view_relocation(struct svga_winsys_context *swc, // IN 48 struct pipe_surface *surface, // IN 49 SVGA3dRenderTargetViewId *id, // OUT 50 unsigned flags) 51{ 52 if (surface) { 53 struct svga_surface *s = svga_surface(surface); 54 assert(s->handle); 55 swc->surface_relocation(swc, id, NULL, s->handle, flags); 56 } 57 else { 58 swc->surface_relocation(swc, id, NULL, NULL, flags); 59 } 60} 61 62 63/** 64 * Emit a surface relocation for a ResourceId. 65 */ 66static void 67surface_to_resourceid(struct svga_winsys_context *swc, // IN 68 struct svga_winsys_surface *surface, // IN 69 SVGA3dSurfaceId *sid, // OUT 70 unsigned flags) // IN 71{ 72 if (surface) { 73 swc->surface_relocation(swc, sid, NULL, surface, flags); 74 } 75 else { 76 swc->surface_relocation(swc, sid, NULL, NULL, flags); 77 } 78} 79 80 81#define SVGA3D_CREATE_COMMAND(CommandName, CommandCode) \ 82SVGA3dCmdDX##CommandName *cmd; \ 83{ \ 84 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_##CommandCode, \ 85 sizeof(SVGA3dCmdDX##CommandName), 0); \ 86 if (!cmd) \ 87 return PIPE_ERROR_OUT_OF_MEMORY; \ 88} 89 90#define SVGA3D_CREATE_CMD_COUNT(CommandName, CommandCode, ElementClassName) \ 91SVGA3dCmdDX##CommandName *cmd; \ 92{ \ 93 assert(count > 0); \ 94 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_##CommandCode, \ 95 sizeof(SVGA3dCmdDX##CommandName) + \ 96 count * sizeof(ElementClassName), 0); \ 97 if (!cmd) \ 98 return PIPE_ERROR_OUT_OF_MEMORY; \ 99} 100 101#define SVGA3D_COPY_BASIC(VariableName) \ 102{ \ 103 cmd->VariableName = VariableName; \ 104} 105 106#define SVGA3D_COPY_BASIC_2(VariableName1, VariableName2) \ 107{ \ 108 SVGA3D_COPY_BASIC(VariableName1); \ 109 SVGA3D_COPY_BASIC(VariableName2); \ 110} 111 112#define SVGA3D_COPY_BASIC_3(VariableName1, VariableName2, VariableName3) \ 113{ \ 114 SVGA3D_COPY_BASIC_2(VariableName1, VariableName2); \ 115 SVGA3D_COPY_BASIC(VariableName3); \ 116} 117 118#define SVGA3D_COPY_BASIC_4(VariableName1, VariableName2, VariableName3, \ 119 VariableName4) \ 120{ \ 121 SVGA3D_COPY_BASIC_2(VariableName1, VariableName2); \ 122 SVGA3D_COPY_BASIC_2(VariableName3, VariableName4); \ 123} 124 125#define SVGA3D_COPY_BASIC_5(VariableName1, VariableName2, VariableName3, \ 126 VariableName4, VariableName5) \ 127{\ 128 SVGA3D_COPY_BASIC_3(VariableName1, VariableName2, VariableName3); \ 129 SVGA3D_COPY_BASIC_2(VariableName4, VariableName5); \ 130} 131 132#define SVGA3D_COPY_BASIC_6(VariableName1, VariableName2, VariableName3, \ 133 VariableName4, VariableName5, VariableName6) \ 134{\ 135 SVGA3D_COPY_BASIC_3(VariableName1, VariableName2, VariableName3); \ 136 SVGA3D_COPY_BASIC_3(VariableName4, VariableName5, VariableName6); \ 137} 138 139#define SVGA3D_COPY_BASIC_7(VariableName1, VariableName2, VariableName3, \ 140 VariableName4, VariableName5, VariableName6, \ 141 VariableName7) \ 142{\ 143 SVGA3D_COPY_BASIC_4(VariableName1, VariableName2, VariableName3, \ 144 VariableName4); \ 145 SVGA3D_COPY_BASIC_3(VariableName5, VariableName6, VariableName7); \ 146} 147 148#define SVGA3D_COPY_BASIC_8(VariableName1, VariableName2, VariableName3, \ 149 VariableName4, VariableName5, VariableName6, \ 150 VariableName7, VariableName8) \ 151{\ 152 SVGA3D_COPY_BASIC_4(VariableName1, VariableName2, VariableName3, \ 153 VariableName4); \ 154 SVGA3D_COPY_BASIC_4(VariableName5, VariableName6, VariableName7, \ 155 VariableName8); \ 156} 157 158#define SVGA3D_COPY_BASIC_9(VariableName1, VariableName2, VariableName3, \ 159 VariableName4, VariableName5, VariableName6, \ 160 VariableName7, VariableName8, VariableName9) \ 161{\ 162 SVGA3D_COPY_BASIC_5(VariableName1, VariableName2, VariableName3, \ 163 VariableName4, VariableName5); \ 164 SVGA3D_COPY_BASIC_4(VariableName6, VariableName7, VariableName8, \ 165 VariableName9); \ 166} 167 168 169enum pipe_error 170SVGA3D_vgpu10_PredCopyRegion(struct svga_winsys_context *swc, 171 struct svga_winsys_surface *dstSurf, 172 uint32 dstSubResource, 173 struct svga_winsys_surface *srcSurf, 174 uint32 srcSubResource, 175 const SVGA3dCopyBox *box) 176{ 177 SVGA3dCmdDXPredCopyRegion *cmd = 178 SVGA3D_FIFOReserve(swc, 179 SVGA_3D_CMD_DX_PRED_COPY_REGION, 180 sizeof(SVGA3dCmdDXPredCopyRegion), 181 2); /* two relocations */ 182 if (!cmd) 183 return PIPE_ERROR_OUT_OF_MEMORY; 184 185 swc->surface_relocation(swc, &cmd->dstSid, NULL, dstSurf, SVGA_RELOC_WRITE); 186 swc->surface_relocation(swc, &cmd->srcSid, NULL, srcSurf, SVGA_RELOC_READ); 187 cmd->dstSubResource = dstSubResource; 188 cmd->srcSubResource = srcSubResource; 189 cmd->box = *box; 190 191 swc->commit(swc); 192 193 return PIPE_OK; 194} 195 196 197enum pipe_error 198SVGA3D_vgpu10_PredCopy(struct svga_winsys_context *swc, 199 struct svga_winsys_surface *dstSurf, 200 struct svga_winsys_surface *srcSurf) 201{ 202 SVGA3dCmdDXPredCopy *cmd = 203 SVGA3D_FIFOReserve(swc, 204 SVGA_3D_CMD_DX_PRED_COPY, 205 sizeof(SVGA3dCmdDXPredCopy), 206 2); /* two relocations */ 207 if (!cmd) 208 return PIPE_ERROR_OUT_OF_MEMORY; 209 210 swc->surface_relocation(swc, &cmd->dstSid, NULL, dstSurf, SVGA_RELOC_WRITE); 211 swc->surface_relocation(swc, &cmd->srcSid, NULL, srcSurf, SVGA_RELOC_READ); 212 213 swc->commit(swc); 214 215 return PIPE_OK; 216} 217 218enum pipe_error 219SVGA3D_vgpu10_SetViewports(struct svga_winsys_context *swc, 220 unsigned count, 221 const SVGA3dViewport *viewports) 222{ 223 SVGA3D_CREATE_CMD_COUNT(SetViewports, SET_VIEWPORTS, SVGA3dViewport); 224 225 cmd->pad0 = 0; 226 memcpy(cmd + 1, viewports, count * sizeof(SVGA3dViewport)); 227 228 swc->commit(swc); 229 return PIPE_OK; 230} 231 232 233enum pipe_error 234SVGA3D_vgpu10_SetShader(struct svga_winsys_context *swc, 235 SVGA3dShaderType type, 236 struct svga_winsys_gb_shader *gbshader, 237 SVGA3dShaderId shaderId) 238{ 239 SVGA3dCmdDXSetShader *cmd = SVGA3D_FIFOReserve(swc, 240 SVGA_3D_CMD_DX_SET_SHADER, 241 sizeof *cmd, 242 1); /* one relocation */ 243 if (!cmd) 244 return PIPE_ERROR_OUT_OF_MEMORY; 245 246 swc->shader_relocation(swc, &cmd->shaderId, NULL, NULL, gbshader, 0); 247 248 cmd->type = type; 249 cmd->shaderId = shaderId; 250 swc->commit(swc); 251 252 return PIPE_OK; 253} 254 255 256enum pipe_error 257SVGA3D_vgpu10_SetShaderResources(struct svga_winsys_context *swc, 258 SVGA3dShaderType type, 259 uint32 startView, 260 unsigned count, 261 const SVGA3dShaderResourceViewId ids[], 262 struct svga_winsys_surface **views) 263{ 264 SVGA3dCmdDXSetShaderResources *cmd; 265 SVGA3dShaderResourceViewId *cmd_ids; 266 unsigned i; 267 268 cmd = SVGA3D_FIFOReserve(swc, 269 SVGA_3D_CMD_DX_SET_SHADER_RESOURCES, 270 sizeof(SVGA3dCmdDXSetShaderResources) + 271 count * sizeof(SVGA3dShaderResourceViewId), 272 count); /* 'count' relocations */ 273 if (!cmd) 274 return PIPE_ERROR_OUT_OF_MEMORY; 275 276 277 cmd->type = type; 278 cmd->startView = startView; 279 280 cmd_ids = (SVGA3dShaderResourceViewId *) (cmd + 1); 281 for (i = 0; i < count; i++) { 282 swc->surface_relocation(swc, cmd_ids + i, NULL, views[i], 283 SVGA_RELOC_READ); 284 cmd_ids[i] = ids[i]; 285 } 286 287 swc->commit(swc); 288 return PIPE_OK; 289} 290 291 292enum pipe_error 293SVGA3D_vgpu10_SetSamplers(struct svga_winsys_context *swc, 294 unsigned count, 295 uint32 startSampler, 296 SVGA3dShaderType type, 297 const SVGA3dSamplerId *samplerIds) 298{ 299 SVGA3D_CREATE_CMD_COUNT(SetSamplers, SET_SAMPLERS, SVGA3dSamplerId); 300 301 SVGA3D_COPY_BASIC_2(startSampler, type); 302 memcpy(cmd + 1, samplerIds, count * sizeof(SVGA3dSamplerId)); 303 304 swc->commit(swc); 305 return PIPE_OK; 306} 307 308 309enum pipe_error 310SVGA3D_vgpu10_ClearRenderTargetView(struct svga_winsys_context *swc, 311 struct pipe_surface *color_surf, 312 const float *rgba) 313{ 314 SVGA3dCmdDXClearRenderTargetView *cmd; 315 struct svga_surface *ss = svga_surface(color_surf); 316 317 cmd = SVGA3D_FIFOReserve(swc, 318 SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW, 319 sizeof(SVGA3dCmdDXClearRenderTargetView), 320 1); /* one relocation */ 321 if (!cmd) 322 return PIPE_ERROR_OUT_OF_MEMORY; 323 324 325 /* NOTE: The following is pretty tricky. We need to emit a view/surface 326 * relocation and we have to provide a pointer to an ID which lies in 327 * the bounds of the command space which we just allocated. However, 328 * we then need to overwrite it with the original RenderTargetViewId. 329 */ 330 view_relocation(swc, color_surf, &cmd->renderTargetViewId, 331 SVGA_RELOC_WRITE); 332 cmd->renderTargetViewId = ss->view_id; 333 334 COPY_4V(cmd->rgba.value, rgba); 335 336 swc->commit(swc); 337 return PIPE_OK; 338} 339 340 341enum pipe_error 342SVGA3D_vgpu10_SetRenderTargets(struct svga_winsys_context *swc, 343 unsigned color_count, 344 struct pipe_surface **color_surfs, 345 struct pipe_surface *depth_stencil_surf) 346{ 347 const unsigned surf_count = color_count + 1; 348 SVGA3dCmdDXSetRenderTargets *cmd; 349 SVGA3dRenderTargetViewId *ctarget; 350 struct svga_surface *ss; 351 unsigned i; 352 353 assert(surf_count > 0); 354 355 cmd = SVGA3D_FIFOReserve(swc, 356 SVGA_3D_CMD_DX_SET_RENDERTARGETS, 357 sizeof(SVGA3dCmdDXSetRenderTargets) + 358 color_count * sizeof(SVGA3dRenderTargetViewId), 359 surf_count); /* 'surf_count' relocations */ 360 if (!cmd) 361 return PIPE_ERROR_OUT_OF_MEMORY; 362 363 /* NOTE: See earlier comment about the tricky handling of the ViewIds. 364 */ 365 366 /* Depth / Stencil buffer */ 367 if (depth_stencil_surf) { 368 ss = svga_surface(depth_stencil_surf); 369 view_relocation(swc, depth_stencil_surf, &cmd->depthStencilViewId, 370 SVGA_RELOC_WRITE); 371 cmd->depthStencilViewId = ss->view_id; 372 } 373 else { 374 /* no depth/stencil buffer - still need a relocation */ 375 view_relocation(swc, NULL, &cmd->depthStencilViewId, 376 SVGA_RELOC_WRITE); 377 cmd->depthStencilViewId = SVGA3D_INVALID_ID; 378 } 379 380 /* Color buffers */ 381 ctarget = (SVGA3dRenderTargetViewId *) &cmd[1]; 382 for (i = 0; i < color_count; i++) { 383 if (color_surfs[i]) { 384 ss = svga_surface(color_surfs[i]); 385 view_relocation(swc, color_surfs[i], ctarget + i, SVGA_RELOC_WRITE); 386 ctarget[i] = ss->view_id; 387 } 388 else { 389 view_relocation(swc, NULL, ctarget + i, SVGA_RELOC_WRITE); 390 ctarget[i] = SVGA3D_INVALID_ID; 391 } 392 } 393 394 swc->commit(swc); 395 return PIPE_OK; 396} 397 398 399enum pipe_error 400SVGA3D_vgpu10_SetBlendState(struct svga_winsys_context *swc, 401 SVGA3dBlendStateId blendId, 402 const float *blendFactor, 403 uint32 sampleMask) 404{ 405 SVGA3D_CREATE_COMMAND(SetBlendState, SET_BLEND_STATE); 406 407 SVGA3D_COPY_BASIC_2(blendId, sampleMask); 408 memcpy(cmd->blendFactor, blendFactor, sizeof(float) * 4); 409 410 swc->commit(swc); 411 return PIPE_OK; 412} 413 414enum pipe_error 415SVGA3D_vgpu10_SetDepthStencilState(struct svga_winsys_context *swc, 416 SVGA3dDepthStencilStateId depthStencilId, 417 uint32 stencilRef) 418{ 419 SVGA3D_CREATE_COMMAND(SetDepthStencilState, SET_DEPTHSTENCIL_STATE); 420 421 SVGA3D_COPY_BASIC_2(depthStencilId, stencilRef); 422 423 swc->commit(swc); 424 return PIPE_OK; 425} 426 427enum pipe_error 428SVGA3D_vgpu10_SetRasterizerState(struct svga_winsys_context *swc, 429 SVGA3dRasterizerStateId rasterizerId) 430{ 431 SVGA3D_CREATE_COMMAND(SetRasterizerState, SET_RASTERIZER_STATE); 432 433 cmd->rasterizerId = rasterizerId; 434 435 swc->commit(swc); 436 return PIPE_OK; 437} 438 439enum pipe_error 440SVGA3D_vgpu10_SetPredication(struct svga_winsys_context *swc, 441 SVGA3dQueryId queryId, 442 uint32 predicateValue) 443{ 444 SVGA3dCmdDXSetPredication *cmd; 445 446 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_SET_PREDICATION, 447 sizeof *cmd, 0); 448 449 if (!cmd) 450 return PIPE_ERROR_OUT_OF_MEMORY; 451 452 cmd->queryId = queryId; 453 cmd->predicateValue = predicateValue; 454 swc->commit(swc); 455 return PIPE_OK; 456} 457 458enum pipe_error 459SVGA3D_vgpu10_SetSOTargets(struct svga_winsys_context *swc, 460 unsigned count, 461 const SVGA3dSoTarget *targets, 462 struct svga_winsys_surface **surfaces) 463{ 464 SVGA3dCmdDXSetSOTargets *cmd; 465 SVGA3dSoTarget *sot; 466 unsigned i; 467 468 cmd = SVGA3D_FIFOReserve(swc, 469 SVGA_3D_CMD_DX_SET_SOTARGETS, 470 sizeof(SVGA3dCmdDXSetSOTargets) + 471 count * sizeof(SVGA3dSoTarget), 472 count); 473 474 if (!cmd) 475 return PIPE_ERROR_OUT_OF_MEMORY; 476 477 cmd->pad0 = 0; 478 sot = (SVGA3dSoTarget *)(cmd + 1); 479 for (i = 0; i < count; i++, sot++) { 480 if (surfaces[i]) { 481 sot->offset = targets[i].offset; 482 sot->sizeInBytes = targets[i].sizeInBytes; 483 swc->surface_relocation(swc, &sot->sid, NULL, surfaces[i], 484 SVGA_RELOC_WRITE); 485 } 486 else { 487 sot->offset = 0; 488 sot->sizeInBytes = ~0u; 489 swc->surface_relocation(swc, &sot->sid, NULL, NULL, 490 SVGA_RELOC_WRITE); 491 } 492 } 493 swc->commit(swc); 494 return PIPE_OK; 495} 496 497enum pipe_error 498SVGA3D_vgpu10_SetScissorRects(struct svga_winsys_context *swc, 499 unsigned count, 500 const SVGASignedRect *rects) 501{ 502 SVGA3dCmdDXSetScissorRects *cmd; 503 504 assert(count > 0); 505 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_SET_SCISSORRECTS, 506 sizeof(SVGA3dCmdDXSetScissorRects) + 507 count * sizeof(SVGASignedRect), 508 0); 509 if (!cmd) 510 return PIPE_ERROR_OUT_OF_MEMORY; 511 512 cmd->pad0 = 0; 513 memcpy(cmd + 1, rects, count * sizeof(SVGASignedRect)); 514 515 swc->commit(swc); 516 return PIPE_OK; 517} 518 519enum pipe_error 520SVGA3D_vgpu10_SetStreamOutput(struct svga_winsys_context *swc, 521 SVGA3dStreamOutputId soid) 522{ 523 SVGA3D_CREATE_COMMAND(SetStreamOutput, SET_STREAMOUTPUT); 524 525 cmd->soid = soid; 526 527 swc->commit(swc); 528 return PIPE_OK; 529} 530 531enum pipe_error 532SVGA3D_vgpu10_Draw(struct svga_winsys_context *swc, 533 uint32 vertexCount, 534 uint32 startVertexLocation) 535{ 536 SVGA3D_CREATE_COMMAND(Draw, DRAW); 537 538 SVGA3D_COPY_BASIC_2(vertexCount, startVertexLocation); 539 540 swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH; 541 swc->commit(swc); 542 swc->num_draw_commands++; 543 return PIPE_OK; 544} 545 546enum pipe_error 547SVGA3D_vgpu10_DrawIndexed(struct svga_winsys_context *swc, 548 uint32 indexCount, 549 uint32 startIndexLocation, 550 int32 baseVertexLocation) 551{ 552 SVGA3D_CREATE_COMMAND(DrawIndexed, DRAW_INDEXED); 553 554 SVGA3D_COPY_BASIC_3(indexCount, startIndexLocation, 555 baseVertexLocation); 556 557 swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH; 558 swc->commit(swc); 559 swc->num_draw_commands++; 560 return PIPE_OK; 561} 562 563enum pipe_error 564SVGA3D_vgpu10_DrawInstanced(struct svga_winsys_context *swc, 565 uint32 vertexCountPerInstance, 566 uint32 instanceCount, 567 uint32 startVertexLocation, 568 uint32 startInstanceLocation) 569{ 570 SVGA3D_CREATE_COMMAND(DrawInstanced, DRAW_INSTANCED); 571 572 SVGA3D_COPY_BASIC_4(vertexCountPerInstance, instanceCount, 573 startVertexLocation, startInstanceLocation); 574 575 swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH; 576 swc->commit(swc); 577 swc->num_draw_commands++; 578 return PIPE_OK; 579} 580 581enum pipe_error 582SVGA3D_vgpu10_DrawIndexedInstanced(struct svga_winsys_context *swc, 583 uint32 indexCountPerInstance, 584 uint32 instanceCount, 585 uint32 startIndexLocation, 586 int32 baseVertexLocation, 587 uint32 startInstanceLocation) 588{ 589 SVGA3D_CREATE_COMMAND(DrawIndexedInstanced, DRAW_INDEXED_INSTANCED); 590 591 SVGA3D_COPY_BASIC_5(indexCountPerInstance, instanceCount, 592 startIndexLocation, baseVertexLocation, 593 startInstanceLocation); 594 595 596 swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH; 597 swc->commit(swc); 598 swc->num_draw_commands++; 599 return PIPE_OK; 600} 601 602enum pipe_error 603SVGA3D_vgpu10_DrawAuto(struct svga_winsys_context *swc) 604{ 605 SVGA3D_CREATE_COMMAND(DrawAuto, DRAW_AUTO); 606 607 cmd->pad0 = 0; 608 swc->hints |= SVGA_HINT_FLAG_CAN_PRE_FLUSH; 609 swc->commit(swc); 610 swc->num_draw_commands++; 611 return PIPE_OK; 612} 613 614enum pipe_error 615SVGA3D_vgpu10_DefineQuery(struct svga_winsys_context *swc, 616 SVGA3dQueryId queryId, 617 SVGA3dQueryType type, 618 SVGA3dDXQueryFlags flags) 619{ 620 SVGA3D_CREATE_COMMAND(DefineQuery, DEFINE_QUERY); 621 622 SVGA3D_COPY_BASIC_3(queryId, type, flags); 623 624 swc->commit(swc); 625 return PIPE_OK; 626} 627 628enum pipe_error 629SVGA3D_vgpu10_DestroyQuery(struct svga_winsys_context *swc, 630 SVGA3dQueryId queryId) 631{ 632 SVGA3D_CREATE_COMMAND(DestroyQuery, DESTROY_QUERY); 633 634 cmd->queryId = queryId; 635 636 swc->commit(swc); 637 return PIPE_OK; 638} 639 640enum pipe_error 641SVGA3D_vgpu10_BindQuery(struct svga_winsys_context *swc, 642 struct svga_winsys_gb_query *gbQuery, 643 SVGA3dQueryId queryId) 644{ 645 SVGA3dCmdDXBindQuery *cmd = SVGA3D_FIFOReserve(swc, 646 SVGA_3D_CMD_DX_BIND_QUERY, 647 sizeof *cmd, 648 1); 649 if (!cmd) 650 return PIPE_ERROR_OUT_OF_MEMORY; 651 652 cmd->queryId = queryId; 653 swc->query_relocation(swc, &cmd->mobid, gbQuery); 654 655 swc->commit(swc); 656 return PIPE_OK; 657} 658 659enum pipe_error 660SVGA3D_vgpu10_SetQueryOffset(struct svga_winsys_context *swc, 661 SVGA3dQueryId queryId, 662 uint32 mobOffset) 663{ 664 SVGA3D_CREATE_COMMAND(SetQueryOffset, SET_QUERY_OFFSET); 665 SVGA3D_COPY_BASIC_2(queryId, mobOffset); 666 swc->commit(swc); 667 return PIPE_OK; 668} 669 670enum pipe_error 671SVGA3D_vgpu10_BeginQuery(struct svga_winsys_context *swc, 672 SVGA3dQueryId queryId) 673{ 674 SVGA3D_CREATE_COMMAND(BeginQuery, BEGIN_QUERY); 675 cmd->queryId = queryId; 676 swc->commit(swc); 677 return PIPE_OK; 678} 679 680enum pipe_error 681SVGA3D_vgpu10_EndQuery(struct svga_winsys_context *swc, 682 SVGA3dQueryId queryId) 683{ 684 SVGA3D_CREATE_COMMAND(EndQuery, END_QUERY); 685 cmd->queryId = queryId; 686 swc->commit(swc); 687 return PIPE_OK; 688} 689 690 691enum pipe_error 692SVGA3D_vgpu10_ClearDepthStencilView(struct svga_winsys_context *swc, 693 struct pipe_surface *ds_surf, 694 uint16 flags, 695 uint16 stencil, 696 float depth) 697{ 698 SVGA3dCmdDXClearDepthStencilView *cmd; 699 struct svga_surface *ss = svga_surface(ds_surf); 700 701 cmd = SVGA3D_FIFOReserve(swc, 702 SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW, 703 sizeof(SVGA3dCmdDXClearDepthStencilView), 704 1); /* one relocation */ 705 if (!cmd) 706 return PIPE_ERROR_OUT_OF_MEMORY; 707 708 /* NOTE: The following is pretty tricky. We need to emit a view/surface 709 * relocation and we have to provide a pointer to an ID which lies in 710 * the bounds of the command space which we just allocated. However, 711 * we then need to overwrite it with the original DepthStencilViewId. 712 */ 713 view_relocation(swc, ds_surf, &cmd->depthStencilViewId, 714 SVGA_RELOC_WRITE); 715 cmd->depthStencilViewId = ss->view_id; 716 cmd->flags = flags; 717 cmd->stencil = stencil; 718 cmd->depth = depth; 719 720 swc->commit(swc); 721 return PIPE_OK; 722} 723 724enum pipe_error 725SVGA3D_vgpu10_DefineShaderResourceView(struct svga_winsys_context *swc, 726 SVGA3dShaderResourceViewId shaderResourceViewId, 727 struct svga_winsys_surface *surface, 728 SVGA3dSurfaceFormat format, 729 SVGA3dResourceType resourceDimension, 730 const SVGA3dShaderResourceViewDesc *desc) 731{ 732 SVGA3dCmdDXDefineShaderResourceView *cmd; 733 734 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW, 735 sizeof(SVGA3dCmdDXDefineShaderResourceView), 736 1); /* one relocation */ 737 if (!cmd) 738 return PIPE_ERROR_OUT_OF_MEMORY; 739 740 SVGA3D_COPY_BASIC_3(shaderResourceViewId, format, resourceDimension); 741 742 swc->surface_relocation(swc, &cmd->sid, NULL, surface, 743 SVGA_RELOC_READ); 744 745 cmd->desc = *desc; 746 747 swc->commit(swc); 748 return PIPE_OK; 749} 750 751enum pipe_error 752SVGA3D_vgpu10_DestroyShaderResourceView(struct svga_winsys_context *swc, 753 SVGA3dShaderResourceViewId shaderResourceViewId) 754{ 755 SVGA3D_CREATE_COMMAND(DestroyShaderResourceView, 756 DESTROY_SHADERRESOURCE_VIEW); 757 758 cmd->shaderResourceViewId = shaderResourceViewId; 759 760 swc->commit(swc); 761 return PIPE_OK; 762} 763 764 765enum pipe_error 766SVGA3D_vgpu10_DefineRenderTargetView(struct svga_winsys_context *swc, 767 SVGA3dRenderTargetViewId renderTargetViewId, 768 struct svga_winsys_surface *surface, 769 SVGA3dSurfaceFormat format, 770 SVGA3dResourceType resourceDimension, 771 const SVGA3dRenderTargetViewDesc *desc) 772{ 773 SVGA3dCmdDXDefineRenderTargetView *cmd; 774 775 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW, 776 sizeof(SVGA3dCmdDXDefineRenderTargetView), 777 1); /* one relocation */ 778 if (!cmd) 779 return PIPE_ERROR_OUT_OF_MEMORY; 780 781 SVGA3D_COPY_BASIC_3(renderTargetViewId, format, resourceDimension); 782 cmd->desc = *desc; 783 784 surface_to_resourceid(swc, surface, 785 &cmd->sid, 786 SVGA_RELOC_READ | SVGA_RELOC_WRITE); 787 788 swc->commit(swc); 789 return PIPE_OK; 790} 791 792enum pipe_error 793SVGA3D_vgpu10_DestroyRenderTargetView(struct svga_winsys_context *swc, 794 SVGA3dRenderTargetViewId renderTargetViewId) 795{ 796 SVGA3D_CREATE_COMMAND(DestroyRenderTargetView, DESTROY_RENDERTARGET_VIEW); 797 798 cmd->renderTargetViewId = renderTargetViewId; 799 800 swc->commit(swc); 801 return PIPE_OK; 802} 803 804 805enum pipe_error 806SVGA3D_vgpu10_DefineDepthStencilView(struct svga_winsys_context *swc, 807 SVGA3dDepthStencilViewId depthStencilViewId, 808 struct svga_winsys_surface *surface, 809 SVGA3dSurfaceFormat format, 810 SVGA3dResourceType resourceDimension, 811 const SVGA3dRenderTargetViewDesc *desc) 812{ 813 SVGA3dCmdDXDefineDepthStencilView *cmd; 814 815 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW, 816 sizeof(SVGA3dCmdDXDefineDepthStencilView), 817 1); /* one relocation */ 818 if (!cmd) 819 return PIPE_ERROR_OUT_OF_MEMORY; 820 821 SVGA3D_COPY_BASIC_3(depthStencilViewId, format, resourceDimension); 822 cmd->mipSlice = desc->tex.mipSlice; 823 cmd->firstArraySlice = desc->tex.firstArraySlice; 824 cmd->arraySize = desc->tex.arraySize; 825 cmd->flags = 0; 826 cmd->pad0 = 0; 827 cmd->pad1 = 0; 828 829 surface_to_resourceid(swc, surface, 830 &cmd->sid, 831 SVGA_RELOC_READ | SVGA_RELOC_WRITE); 832 833 swc->commit(swc); 834 return PIPE_OK; 835} 836 837enum pipe_error 838SVGA3D_vgpu10_DestroyDepthStencilView(struct svga_winsys_context *swc, 839 SVGA3dDepthStencilViewId depthStencilViewId) 840{ 841 SVGA3D_CREATE_COMMAND(DestroyDepthStencilView, DESTROY_DEPTHSTENCIL_VIEW); 842 843 cmd->depthStencilViewId = depthStencilViewId; 844 845 swc->commit(swc); 846 return PIPE_OK; 847} 848 849enum pipe_error 850SVGA3D_vgpu10_DefineElementLayout(struct svga_winsys_context *swc, 851 unsigned count, 852 SVGA3dElementLayoutId elementLayoutId, 853 const SVGA3dInputElementDesc *elements) 854{ 855 SVGA3dCmdDXDefineElementLayout *cmd; 856 unsigned i; 857 858 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT, 859 sizeof(SVGA3dCmdDXDefineElementLayout) + 860 count * sizeof(SVGA3dInputElementDesc), 0); 861 if (!cmd) 862 return PIPE_ERROR_OUT_OF_MEMORY; 863 864 /* check that all offsets are multiples of four */ 865 for (i = 0; i < count; i++) { 866 assert(elements[i].alignedByteOffset % 4 == 0); 867 } 868 (void) i; /* silence unused var in release build */ 869 870 cmd->elementLayoutId = elementLayoutId; 871 memcpy(cmd + 1, elements, count * sizeof(SVGA3dInputElementDesc)); 872 873 swc->commit(swc); 874 return PIPE_OK; 875} 876 877enum pipe_error 878SVGA3D_vgpu10_DestroyElementLayout(struct svga_winsys_context *swc, 879 SVGA3dElementLayoutId elementLayoutId) 880{ 881 SVGA3D_CREATE_COMMAND(DestroyElementLayout, DESTROY_ELEMENTLAYOUT); 882 883 cmd->elementLayoutId = elementLayoutId; 884 885 swc->commit(swc); 886 return PIPE_OK; 887} 888 889enum pipe_error 890SVGA3D_vgpu10_DefineBlendState(struct svga_winsys_context *swc, 891 SVGA3dBlendStateId blendId, 892 uint8 alphaToCoverageEnable, 893 uint8 independentBlendEnable, 894 const SVGA3dDXBlendStatePerRT *perRT) 895{ 896 SVGA3D_CREATE_COMMAND(DefineBlendState, DEFINE_BLEND_STATE); 897 898 cmd->blendId = blendId; 899 cmd->alphaToCoverageEnable = alphaToCoverageEnable; 900 cmd->independentBlendEnable = independentBlendEnable; 901 memcpy(cmd->perRT, perRT, sizeof(cmd->perRT)); 902 cmd->pad0 = 0; 903 904 swc->commit(swc); 905 return PIPE_OK; 906} 907 908enum pipe_error 909SVGA3D_vgpu10_DestroyBlendState(struct svga_winsys_context *swc, 910 SVGA3dBlendStateId blendId) 911{ 912 SVGA3D_CREATE_COMMAND(DestroyBlendState, DESTROY_BLEND_STATE); 913 914 cmd->blendId = blendId; 915 916 swc->commit(swc); 917 return PIPE_OK; 918} 919 920enum pipe_error 921SVGA3D_vgpu10_DefineDepthStencilState(struct svga_winsys_context *swc, 922 SVGA3dDepthStencilStateId depthStencilId, 923 uint8 depthEnable, 924 SVGA3dDepthWriteMask depthWriteMask, 925 SVGA3dComparisonFunc depthFunc, 926 uint8 stencilEnable, 927 uint8 frontEnable, 928 uint8 backEnable, 929 uint8 stencilReadMask, 930 uint8 stencilWriteMask, 931 uint8 frontStencilFailOp, 932 uint8 frontStencilDepthFailOp, 933 uint8 frontStencilPassOp, 934 SVGA3dComparisonFunc frontStencilFunc, 935 uint8 backStencilFailOp, 936 uint8 backStencilDepthFailOp, 937 uint8 backStencilPassOp, 938 SVGA3dComparisonFunc backStencilFunc) 939{ 940 SVGA3D_CREATE_COMMAND(DefineDepthStencilState, DEFINE_DEPTHSTENCIL_STATE); 941 942 SVGA3D_COPY_BASIC_9(depthStencilId, depthEnable, 943 depthWriteMask, depthFunc, 944 stencilEnable, frontEnable, 945 backEnable, stencilReadMask, 946 stencilWriteMask); 947 SVGA3D_COPY_BASIC_8(frontStencilFailOp, frontStencilDepthFailOp, 948 frontStencilPassOp, frontStencilFunc, 949 backStencilFailOp, backStencilDepthFailOp, 950 backStencilPassOp, backStencilFunc); 951 952 swc->commit(swc); 953 return PIPE_OK; 954} 955 956enum pipe_error 957SVGA3D_vgpu10_DestroyDepthStencilState(struct svga_winsys_context *swc, 958 SVGA3dDepthStencilStateId depthStencilId) 959{ 960 SVGA3D_CREATE_COMMAND(DestroyDepthStencilState, 961 DESTROY_DEPTHSTENCIL_STATE); 962 963 cmd->depthStencilId = depthStencilId; 964 965 swc->commit(swc); 966 return PIPE_OK; 967} 968 969enum pipe_error 970SVGA3D_vgpu10_DefineRasterizerState(struct svga_winsys_context *swc, 971 SVGA3dRasterizerStateId rasterizerId, 972 uint8 fillMode, 973 SVGA3dCullMode cullMode, 974 uint8 frontCounterClockwise, 975 int32 depthBias, 976 float depthBiasClamp, 977 float slopeScaledDepthBias, 978 uint8 depthClipEnable, 979 uint8 scissorEnable, 980 uint8 multisampleEnable, 981 uint8 antialiasedLineEnable, 982 float lineWidth, 983 uint8 lineStippleEnable, 984 uint8 lineStippleFactor, 985 uint16 lineStipplePattern, 986 uint8 provokingVertexLast) 987{ 988 SVGA3D_CREATE_COMMAND(DefineRasterizerState, DEFINE_RASTERIZER_STATE); 989 990 SVGA3D_COPY_BASIC_5(rasterizerId, fillMode, 991 cullMode, frontCounterClockwise, 992 depthBias); 993 SVGA3D_COPY_BASIC_6(depthBiasClamp, slopeScaledDepthBias, 994 depthClipEnable, scissorEnable, 995 multisampleEnable, antialiasedLineEnable); 996 cmd->lineWidth = lineWidth; 997 cmd->lineStippleEnable = lineStippleEnable; 998 cmd->lineStippleFactor = lineStippleFactor; 999 cmd->lineStipplePattern = lineStipplePattern; 1000 cmd->provokingVertexLast = provokingVertexLast; 1001 1002 swc->commit(swc); 1003 return PIPE_OK; 1004} 1005 1006enum pipe_error 1007SVGA3D_vgpu10_DestroyRasterizerState(struct svga_winsys_context *swc, 1008 SVGA3dRasterizerStateId rasterizerId) 1009{ 1010 SVGA3D_CREATE_COMMAND(DestroyRasterizerState, DESTROY_RASTERIZER_STATE); 1011 1012 cmd->rasterizerId = rasterizerId; 1013 1014 swc->commit(swc); 1015 return PIPE_OK; 1016} 1017 1018enum pipe_error 1019SVGA3D_vgpu10_DefineSamplerState(struct svga_winsys_context *swc, 1020 SVGA3dSamplerId samplerId, 1021 SVGA3dFilter filter, 1022 uint8 addressU, 1023 uint8 addressV, 1024 uint8 addressW, 1025 float mipLODBias, 1026 uint8 maxAnisotropy, 1027 uint8 comparisonFunc, 1028 SVGA3dRGBAFloat borderColor, 1029 float minLOD, 1030 float maxLOD) 1031{ 1032 SVGA3D_CREATE_COMMAND(DefineSamplerState, DEFINE_SAMPLER_STATE); 1033 1034 SVGA3D_COPY_BASIC_6(samplerId, filter, 1035 addressU, addressV, 1036 addressW, mipLODBias); 1037 SVGA3D_COPY_BASIC_5(maxAnisotropy, comparisonFunc, 1038 borderColor, minLOD, 1039 maxLOD); 1040 cmd->pad0 = 0; 1041 cmd->pad1 = 0; 1042 1043 swc->commit(swc); 1044 return PIPE_OK; 1045} 1046 1047enum pipe_error 1048SVGA3D_vgpu10_DestroySamplerState(struct svga_winsys_context *swc, 1049 SVGA3dSamplerId samplerId) 1050{ 1051 SVGA3D_CREATE_COMMAND(DestroySamplerState, DESTROY_SAMPLER_STATE); 1052 1053 cmd->samplerId = samplerId; 1054 1055 swc->commit(swc); 1056 return PIPE_OK; 1057} 1058 1059 1060enum pipe_error 1061SVGA3D_vgpu10_DefineAndBindShader(struct svga_winsys_context *swc, 1062 struct svga_winsys_gb_shader *gbshader, 1063 SVGA3dShaderId shaderId, 1064 SVGA3dShaderType type, 1065 uint32 sizeInBytes) 1066{ 1067 SVGA3dCmdHeader *header; 1068 SVGA3dCmdDXDefineShader *dcmd; 1069 SVGA3dCmdDXBindShader *bcmd; 1070 unsigned totalSize = 2 * sizeof(*header) + 1071 sizeof(*dcmd) + sizeof(*bcmd); 1072 1073 /* Make sure there is room for both commands */ 1074 header = swc->reserve(swc, totalSize, 2); 1075 if (!header) 1076 return PIPE_ERROR_OUT_OF_MEMORY; 1077 1078 /* DXDefineShader command */ 1079 header->id = SVGA_3D_CMD_DX_DEFINE_SHADER; 1080 header->size = sizeof(*dcmd); 1081 dcmd = (SVGA3dCmdDXDefineShader *)(header + 1); 1082 dcmd->shaderId = shaderId; 1083 dcmd->type = type; 1084 dcmd->sizeInBytes = sizeInBytes; 1085 1086 /* DXBindShader command */ 1087 header = (SVGA3dCmdHeader *)(dcmd + 1); 1088 1089 header->id = SVGA_3D_CMD_DX_BIND_SHADER; 1090 header->size = sizeof(*bcmd); 1091 bcmd = (SVGA3dCmdDXBindShader *)(header + 1); 1092 1093 bcmd->cid = swc->cid; 1094 swc->shader_relocation(swc, NULL, &bcmd->mobid, 1095 &bcmd->offsetInBytes, gbshader, 0); 1096 1097 bcmd->shid = shaderId; 1098 1099 swc->commit(swc); 1100 return PIPE_OK; 1101} 1102 1103enum pipe_error 1104SVGA3D_vgpu10_DestroyShader(struct svga_winsys_context *swc, 1105 SVGA3dShaderId shaderId) 1106{ 1107 SVGA3D_CREATE_COMMAND(DestroyShader, DESTROY_SHADER); 1108 1109 cmd->shaderId = shaderId; 1110 1111 swc->commit(swc); 1112 return PIPE_OK; 1113} 1114 1115enum pipe_error 1116SVGA3D_vgpu10_DefineStreamOutput(struct svga_winsys_context *swc, 1117 SVGA3dStreamOutputId soid, 1118 uint32 numOutputStreamEntries, 1119 uint32 streamOutputStrideInBytes[SVGA3D_DX_MAX_SOTARGETS], 1120 const SVGA3dStreamOutputDeclarationEntry decl[SVGA3D_MAX_STREAMOUT_DECLS]) 1121{ 1122 unsigned i; 1123 SVGA3D_CREATE_COMMAND(DefineStreamOutput, DEFINE_STREAMOUTPUT); 1124 1125 cmd->soid = soid; 1126 cmd->numOutputStreamEntries = numOutputStreamEntries; 1127 1128 for (i = 0; i < ARRAY_SIZE(cmd->streamOutputStrideInBytes); i++) 1129 cmd->streamOutputStrideInBytes[i] = streamOutputStrideInBytes[i]; 1130 1131 memcpy(cmd->decl, decl, 1132 sizeof(SVGA3dStreamOutputDeclarationEntry) 1133 * SVGA3D_MAX_STREAMOUT_DECLS); 1134 1135 cmd->rasterizedStream = 0; 1136 swc->commit(swc); 1137 return PIPE_OK; 1138} 1139 1140enum pipe_error 1141SVGA3D_vgpu10_DestroyStreamOutput(struct svga_winsys_context *swc, 1142 SVGA3dStreamOutputId soid) 1143{ 1144 SVGA3D_CREATE_COMMAND(DestroyStreamOutput, DESTROY_STREAMOUTPUT); 1145 1146 cmd->soid = soid; 1147 1148 swc->commit(swc); 1149 return PIPE_OK; 1150} 1151 1152enum pipe_error 1153SVGA3D_vgpu10_SetInputLayout(struct svga_winsys_context *swc, 1154 SVGA3dElementLayoutId elementLayoutId) 1155{ 1156 SVGA3D_CREATE_COMMAND(SetInputLayout, SET_INPUT_LAYOUT); 1157 1158 cmd->elementLayoutId = elementLayoutId; 1159 1160 swc->commit(swc); 1161 return PIPE_OK; 1162} 1163 1164enum pipe_error 1165SVGA3D_vgpu10_SetVertexBuffers(struct svga_winsys_context *swc, 1166 unsigned count, 1167 uint32 startBuffer, 1168 const SVGA3dVertexBuffer *bufferInfo, 1169 struct svga_winsys_surface **surfaces) 1170{ 1171 SVGA3dCmdDXSetVertexBuffers *cmd; 1172 SVGA3dVertexBuffer *bufs; 1173 unsigned i; 1174 1175 assert(count > 0); 1176 1177 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS, 1178 sizeof(SVGA3dCmdDXSetVertexBuffers) + 1179 count * sizeof(SVGA3dVertexBuffer), 1180 count); /* 'count' relocations */ 1181 if (!cmd) 1182 return PIPE_ERROR_OUT_OF_MEMORY; 1183 1184 cmd->startBuffer = startBuffer; 1185 1186 bufs = (SVGA3dVertexBuffer *) &cmd[1]; 1187 for (i = 0; i < count; i++) { 1188 bufs[i].stride = bufferInfo[i].stride; 1189 bufs[i].offset = bufferInfo[i].offset; 1190 assert(bufs[i].stride % 4 == 0); 1191 assert(bufs[i].offset % 4 == 0); 1192 swc->surface_relocation(swc, &bufs[i].sid, NULL, surfaces[i], 1193 SVGA_RELOC_READ); 1194 } 1195 1196 swc->commit(swc); 1197 return PIPE_OK; 1198} 1199 1200enum pipe_error 1201SVGA3D_vgpu10_SetTopology(struct svga_winsys_context *swc, 1202 SVGA3dPrimitiveType topology) 1203{ 1204 SVGA3D_CREATE_COMMAND(SetTopology, SET_TOPOLOGY); 1205 1206 cmd->topology = topology; 1207 1208 swc->commit(swc); 1209 return PIPE_OK; 1210} 1211 1212enum pipe_error 1213SVGA3D_vgpu10_SetIndexBuffer(struct svga_winsys_context *swc, 1214 struct svga_winsys_surface *indexes, 1215 SVGA3dSurfaceFormat format, 1216 uint32 offset) 1217{ 1218 SVGA3dCmdDXSetIndexBuffer *cmd; 1219 1220 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_SET_INDEX_BUFFER, 1221 sizeof(SVGA3dCmdDXSetIndexBuffer), 1222 1); /* one relocations */ 1223 if (!cmd) 1224 return PIPE_ERROR_OUT_OF_MEMORY; 1225 1226 swc->surface_relocation(swc, &cmd->sid, NULL, indexes, SVGA_RELOC_READ); 1227 SVGA3D_COPY_BASIC_2(format, offset); 1228 1229 swc->commit(swc); 1230 return PIPE_OK; 1231} 1232 1233enum pipe_error 1234SVGA3D_vgpu10_SetSingleConstantBuffer(struct svga_winsys_context *swc, 1235 unsigned slot, 1236 SVGA3dShaderType type, 1237 struct svga_winsys_surface *surface, 1238 uint32 offsetInBytes, 1239 uint32 sizeInBytes) 1240{ 1241 SVGA3dCmdDXSetSingleConstantBuffer *cmd; 1242 1243 assert(offsetInBytes % 256 == 0); 1244 if (!surface) 1245 assert(sizeInBytes == 0); 1246 else 1247 assert(sizeInBytes > 0); 1248 1249 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER, 1250 sizeof(SVGA3dCmdDXSetSingleConstantBuffer), 1251 1); /* one relocation */ 1252 if (!cmd) 1253 return PIPE_ERROR_OUT_OF_MEMORY; 1254 1255 cmd->slot = slot; 1256 cmd->type = type; 1257 swc->surface_relocation(swc, &cmd->sid, NULL, surface, SVGA_RELOC_READ); 1258 cmd->offsetInBytes = offsetInBytes; 1259 cmd->sizeInBytes = sizeInBytes; 1260 1261 swc->commit(swc); 1262 1263 return PIPE_OK; 1264} 1265 1266 1267enum pipe_error 1268SVGA3D_vgpu10_ReadbackSubResource(struct svga_winsys_context *swc, 1269 struct svga_winsys_surface *surface, 1270 unsigned subResource) 1271{ 1272 SVGA3dCmdDXReadbackSubResource *cmd; 1273 1274 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_READBACK_SUBRESOURCE, 1275 sizeof(SVGA3dCmdDXReadbackSubResource), 1276 1); 1277 if (!cmd) 1278 return PIPE_ERROR_OUT_OF_MEMORY; 1279 1280 swc->surface_relocation(swc, &cmd->sid, NULL, surface, 1281 SVGA_RELOC_READ | SVGA_RELOC_INTERNAL); 1282 cmd->subResource = subResource; 1283 1284 swc->commit(swc); 1285 return PIPE_OK; 1286} 1287 1288enum pipe_error 1289SVGA3D_vgpu10_UpdateSubResource(struct svga_winsys_context *swc, 1290 struct svga_winsys_surface *surface, 1291 const SVGA3dBox *box, 1292 unsigned subResource) 1293{ 1294 SVGA3dCmdDXUpdateSubResource *cmd; 1295 1296 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE, 1297 sizeof(SVGA3dCmdDXUpdateSubResource), 1298 1); 1299 if (!cmd) 1300 return PIPE_ERROR_OUT_OF_MEMORY; 1301 1302 swc->surface_relocation(swc, &cmd->sid, NULL, surface, 1303 SVGA_RELOC_WRITE | SVGA_RELOC_INTERNAL); 1304 cmd->subResource = subResource; 1305 cmd->box = *box; 1306 1307 swc->commit(swc); 1308 return PIPE_OK; 1309} 1310 1311enum pipe_error 1312SVGA3D_vgpu10_GenMips(struct svga_winsys_context *swc, 1313 SVGA3dShaderResourceViewId shaderResourceViewId, 1314 struct svga_winsys_surface *view) 1315{ 1316 SVGA3dCmdDXGenMips *cmd; 1317 1318 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_GENMIPS, 1319 sizeof(SVGA3dCmdDXGenMips), 1); 1320 1321 if (!cmd) 1322 return PIPE_ERROR_OUT_OF_MEMORY; 1323 1324 swc->surface_relocation(swc, &cmd->shaderResourceViewId, NULL, view, 1325 SVGA_RELOC_WRITE); 1326 cmd->shaderResourceViewId = shaderResourceViewId; 1327 1328 swc->commit(swc); 1329 return PIPE_OK; 1330} 1331 1332 1333enum pipe_error 1334SVGA3D_vgpu10_BufferCopy(struct svga_winsys_context *swc, 1335 struct svga_winsys_surface *src, 1336 struct svga_winsys_surface *dst, 1337 unsigned srcx, unsigned dstx, unsigned width) 1338{ 1339 SVGA3dCmdDXBufferCopy *cmd; 1340 1341 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_BUFFER_COPY, sizeof *cmd, 2); 1342 1343 if (!cmd) 1344 return PIPE_ERROR_OUT_OF_MEMORY; 1345 1346 swc->surface_relocation(swc, &cmd->dest, NULL, dst, SVGA_RELOC_WRITE); 1347 swc->surface_relocation(swc, &cmd->src, NULL, src, SVGA_RELOC_READ); 1348 cmd->destX = dstx; 1349 cmd->srcX = srcx; 1350 cmd->width = width; 1351 1352 swc->commit(swc); 1353 return PIPE_OK; 1354} 1355 1356enum pipe_error 1357SVGA3D_vgpu10_TransferFromBuffer(struct svga_winsys_context *swc, 1358 struct svga_winsys_surface *src, 1359 unsigned srcOffset, unsigned srcPitch, 1360 unsigned srcSlicePitch, 1361 struct svga_winsys_surface *dst, 1362 unsigned dstSubResource, 1363 SVGA3dBox *dstBox) 1364{ 1365 SVGA3dCmdDXTransferFromBuffer *cmd; 1366 1367 cmd = SVGA3D_FIFOReserve(swc, SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER, 1368 sizeof(SVGA3dCmdDXTransferFromBuffer), 2); 1369 1370 if (!cmd) 1371 return PIPE_ERROR_OUT_OF_MEMORY; 1372 1373 swc->surface_relocation(swc, &cmd->srcSid, NULL, src, SVGA_RELOC_READ); 1374 swc->surface_relocation(swc, &cmd->destSid, NULL, dst, SVGA_RELOC_WRITE); 1375 cmd->srcOffset = srcOffset; 1376 cmd->srcPitch = srcPitch; 1377 cmd->srcSlicePitch = srcSlicePitch; 1378 cmd->destSubResource = dstSubResource; 1379 cmd->destBox = *dstBox; 1380 1381 swc->commit(swc); 1382 return PIPE_OK; 1383} 1384 1385enum pipe_error 1386SVGA3D_vgpu10_IntraSurfaceCopy(struct svga_winsys_context *swc, 1387 struct svga_winsys_surface *surface, 1388 unsigned level, unsigned face, 1389 const SVGA3dCopyBox *box) 1390{ 1391 SVGA3dCmdIntraSurfaceCopy *cmd = 1392 SVGA3D_FIFOReserve(swc, 1393 SVGA_3D_CMD_INTRA_SURFACE_COPY, 1394 sizeof(SVGA3dCmdIntraSurfaceCopy), 1395 1); /* one relocation */ 1396 if (!cmd) 1397 return PIPE_ERROR_OUT_OF_MEMORY; 1398 1399 swc->surface_relocation(swc, &cmd->surface.sid, NULL, surface, SVGA_RELOC_READ | SVGA_RELOC_WRITE); 1400 cmd->surface.face = face; 1401 cmd->surface.mipmap = level; 1402 cmd->box = *box; 1403 1404 swc->commit(swc); 1405 1406 return PIPE_OK; 1407} 1408 1409enum pipe_error 1410SVGA3D_vgpu10_ResolveCopy(struct svga_winsys_context *swc, 1411 unsigned dstSubResource, 1412 struct svga_winsys_surface *dst, 1413 unsigned srcSubResource, 1414 struct svga_winsys_surface *src, 1415 const SVGA3dSurfaceFormat copyFormat) 1416{ 1417 SVGA3dCmdDXResolveCopy *cmd = 1418 SVGA3D_FIFOReserve(swc, 1419 SVGA_3D_CMD_DX_RESOLVE_COPY, 1420 sizeof(SVGA3dCmdDXResolveCopy), 1421 2); /* two relocations */ 1422 if (!cmd) 1423 return PIPE_ERROR_OUT_OF_MEMORY; 1424 1425 cmd->dstSubResource = dstSubResource; 1426 swc->surface_relocation(swc, &cmd->dstSid, NULL, dst, SVGA_RELOC_WRITE); 1427 cmd->srcSubResource = srcSubResource; 1428 swc->surface_relocation(swc, &cmd->srcSid, NULL, src, SVGA_RELOC_READ); 1429 cmd->copyFormat = copyFormat; 1430 1431 swc->commit(swc); 1432 1433 return PIPE_OK; 1434} 1435