Hash :
b16d69c3
Author :
Date :
2019-05-13T16:28:27
Vulkan: Add support for surface multisampling A multisample image is created for the surface if multisampling is enabled. Prior to present, this multisample image is resolved into the swapchain image. FramebufferVk::readPixelsImpl similarly has got the ability to resolve the region of interest into a temporary image prior to readback. Tests are added to render a point, line and a triangle on a 4x multisampled surface. Bug: angleproject:3204 Change-Id: I34aca502fa1918b5cbf000ff11521c350372e051 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1610188 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SecondaryCommandBuffer:
// Lightweight, CPU-Side command buffers used to hold command state until
// it has to be submitted to GPU.
//
#ifndef LIBANGLE_RENDERER_VULKAN_SECONDARYCOMMANDBUFFERVK_H_
#define LIBANGLE_RENDERER_VULKAN_SECONDARYCOMMANDBUFFERVK_H_
#include <vulkan/vulkan.h>
#include "common/PoolAlloc.h"
#include "libANGLE/renderer/vulkan/vk_wrapper.h"
namespace rx
{
namespace vk
{
namespace priv
{
enum class CommandID : uint16_t
{
// Invalid cmd used to mark end of sequence of commands
Invalid = 0,
BeginQuery,
BindComputeDescriptorSets,
BindComputePipeline,
BindGraphicsDescriptorSets,
BindGraphicsPipeline,
BindIndexBuffer,
BindVertexBuffers,
BlitImage,
ClearAttachments,
ClearColorImage,
ClearDepthStencilImage,
CopyBuffer,
CopyBufferToImage,
CopyImage,
CopyImageToBuffer,
Dispatch,
Draw,
DrawIndexed,
DrawIndexedInstanced,
DrawInstanced,
EndQuery,
ImageBarrier,
MemoryBarrier,
PipelineBarrier,
PushConstants,
ResetEvent,
ResetQueryPool,
ResolveImage,
SetEvent,
WaitEvents,
WriteTimestamp,
};
#define VERIFY_4_BYTE_ALIGNMENT(StructName) \
static_assert((sizeof(StructName) % 4) == 0, "Check StructName alignment");
// Structs to encapsulate parameters for different commands
// This makes it easy to know the size of params & to copy params
// TODO: Could optimize the size of some of these structs through bit-packing
// and customizing sizing based on limited parameter sets used by ANGLE
struct BindPipelineParams
{
VkPipeline pipeline;
};
VERIFY_4_BYTE_ALIGNMENT(BindPipelineParams)
struct BindGraphicsDescriptorSetParams
{
VkPipelineLayout layout;
uint32_t firstSet;
uint32_t descriptorSetCount;
uint32_t dynamicOffsetCount;
};
VERIFY_4_BYTE_ALIGNMENT(BindGraphicsDescriptorSetParams)
struct BindComputeDescriptorSetParams
{
VkPipelineLayout layout;
};
VERIFY_4_BYTE_ALIGNMENT(BindComputeDescriptorSetParams)
struct BindIndexBufferParams
{
VkBuffer buffer;
VkDeviceSize offset;
VkIndexType indexType;
};
VERIFY_4_BYTE_ALIGNMENT(BindIndexBufferParams)
struct BindVertexBuffersParams
{
// ANGLE always has firstBinding of 0 so not storing that currently
uint32_t bindingCount;
};
VERIFY_4_BYTE_ALIGNMENT(BindVertexBuffersParams)
struct BlitImageParams
{
VkImage srcImage;
VkImage dstImage;
VkFilter filter;
VkImageBlit region;
};
VERIFY_4_BYTE_ALIGNMENT(BlitImageParams)
struct CopyBufferParams
{
VkBuffer srcBuffer;
VkBuffer destBuffer;
uint32_t regionCount;
};
VERIFY_4_BYTE_ALIGNMENT(CopyBufferParams)
struct CopyBufferToImageParams
{
VkBuffer srcBuffer;
VkImage dstImage;
VkImageLayout dstImageLayout;
VkBufferImageCopy region;
};
VERIFY_4_BYTE_ALIGNMENT(CopyBufferToImageParams)
struct CopyImageParams
{
VkImage srcImage;
VkImageLayout srcImageLayout;
VkImage dstImage;
VkImageLayout dstImageLayout;
VkImageCopy region;
};
VERIFY_4_BYTE_ALIGNMENT(CopyImageParams)
struct CopyImageToBufferParams
{
VkImage srcImage;
VkImageLayout srcImageLayout;
VkBuffer dstBuffer;
VkBufferImageCopy region;
};
VERIFY_4_BYTE_ALIGNMENT(CopyImageToBufferParams)
struct ClearAttachmentsParams
{
uint32_t attachmentCount;
VkClearRect rect;
};
VERIFY_4_BYTE_ALIGNMENT(ClearAttachmentsParams)
struct ClearColorImageParams
{
VkImage image;
VkImageLayout imageLayout;
VkClearColorValue color;
VkImageSubresourceRange range;
};
VERIFY_4_BYTE_ALIGNMENT(ClearColorImageParams)
struct ClearDepthStencilImageParams
{
VkImage image;
VkImageLayout imageLayout;
VkClearDepthStencilValue depthStencil;
VkImageSubresourceRange range;
};
VERIFY_4_BYTE_ALIGNMENT(ClearDepthStencilImageParams)
struct PushConstantsParams
{
VkPipelineLayout layout;
VkShaderStageFlags flag;
uint32_t offset;
uint32_t size;
};
VERIFY_4_BYTE_ALIGNMENT(PushConstantsParams)
struct DrawParams
{
uint32_t vertexCount;
uint32_t firstVertex;
};
VERIFY_4_BYTE_ALIGNMENT(DrawParams)
struct DrawInstancedParams
{
uint32_t vertexCount;
uint32_t instanceCount;
uint32_t firstVertex;
};
VERIFY_4_BYTE_ALIGNMENT(DrawInstancedParams)
struct DrawIndexedParams
{
uint32_t indexCount;
};
VERIFY_4_BYTE_ALIGNMENT(DrawIndexedParams)
struct DrawIndexedInstancedParams
{
uint32_t indexCount;
uint32_t instanceCount;
};
VERIFY_4_BYTE_ALIGNMENT(DrawIndexedInstancedParams)
struct DispatchParams
{
uint32_t groupCountX;
uint32_t groupCountY;
uint32_t groupCountZ;
};
VERIFY_4_BYTE_ALIGNMENT(DispatchParams)
struct MemoryBarrierParams
{
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
VkMemoryBarrier memoryBarrier;
};
VERIFY_4_BYTE_ALIGNMENT(MemoryBarrierParams)
struct PipelineBarrierParams
{
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
VkDependencyFlags dependencyFlags;
uint32_t memoryBarrierCount;
uint32_t bufferMemoryBarrierCount;
uint32_t imageMemoryBarrierCount;
};
VERIFY_4_BYTE_ALIGNMENT(PipelineBarrierParams)
struct ImageBarrierParams
{
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
VkImageMemoryBarrier imageMemoryBarrier;
};
VERIFY_4_BYTE_ALIGNMENT(ImageBarrierParams)
struct SetEventParams
{
VkEvent event;
VkPipelineStageFlags stageMask;
};
VERIFY_4_BYTE_ALIGNMENT(SetEventParams)
struct ResetEventParams
{
VkEvent event;
VkPipelineStageFlags stageMask;
};
VERIFY_4_BYTE_ALIGNMENT(ResetEventParams)
struct WaitEventsParams
{
uint32_t eventCount;
VkPipelineStageFlags srcStageMask;
VkPipelineStageFlags dstStageMask;
uint32_t memoryBarrierCount;
uint32_t bufferMemoryBarrierCount;
uint32_t imageMemoryBarrierCount;
};
VERIFY_4_BYTE_ALIGNMENT(WaitEventsParams)
struct ResetQueryPoolParams
{
VkQueryPool queryPool;
uint32_t firstQuery;
uint32_t queryCount;
};
VERIFY_4_BYTE_ALIGNMENT(ResetQueryPoolParams)
struct ResolveImageParams
{
VkImage srcImage;
VkImage dstImage;
VkImageResolve region;
};
VERIFY_4_BYTE_ALIGNMENT(ResolveImageParams)
struct BeginQueryParams
{
VkQueryPool queryPool;
uint32_t query;
VkQueryControlFlags flags;
};
VERIFY_4_BYTE_ALIGNMENT(BeginQueryParams)
struct EndQueryParams
{
VkQueryPool queryPool;
uint32_t query;
};
VERIFY_4_BYTE_ALIGNMENT(EndQueryParams)
struct WriteTimestampParams
{
VkPipelineStageFlagBits pipelineStage;
VkQueryPool queryPool;
uint32_t query;
};
VERIFY_4_BYTE_ALIGNMENT(WriteTimestampParams)
// Header for every cmd in custom cmd buffer
struct CommandHeader
{
CommandID id;
uint16_t size;
};
static_assert(sizeof(CommandHeader) == 4, "Check CommandHeader size");
template <typename DestT, typename T>
ANGLE_INLINE DestT *Offset(T *ptr, size_t bytes)
{
return reinterpret_cast<DestT *>((reinterpret_cast<uint8_t *>(ptr) + bytes));
}
template <typename DestT, typename T>
ANGLE_INLINE const DestT *Offset(const T *ptr, size_t bytes)
{
return reinterpret_cast<const DestT *>((reinterpret_cast<const uint8_t *>(ptr) + bytes));
}
class SecondaryCommandBuffer final : angle::NonCopyable
{
public:
SecondaryCommandBuffer();
~SecondaryCommandBuffer();
static bool SupportsQueries(const VkPhysicalDeviceFeatures &features) { return true; }
// SecondaryCommandBuffer replays its commands inline when executed on the primary command
// buffer.
static constexpr bool ExecutesInline() { return true; }
// Add commands
void beginQuery(VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags);
void bindComputeDescriptorSets(const PipelineLayout &layout,
const VkDescriptorSet *descriptorSets);
void bindComputePipeline(const Pipeline &pipeline);
void bindGraphicsDescriptorSets(const PipelineLayout &layout,
uint32_t firstSet,
uint32_t descriptorSetCount,
const VkDescriptorSet *descriptorSets,
uint32_t dynamicOffsetCount,
const uint32_t *dynamicOffsets);
void bindGraphicsPipeline(const Pipeline &pipeline);
void bindIndexBuffer(const Buffer &buffer, VkDeviceSize offset, VkIndexType indexType);
void bindVertexBuffers(uint32_t firstBinding,
uint32_t bindingCount,
const VkBuffer *buffers,
const VkDeviceSize *offsets);
void blitImage(const Image &srcImage,
VkImageLayout srcImageLayout,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageBlit *regions,
VkFilter filter);
void clearAttachments(uint32_t attachmentCount,
const VkClearAttachment *attachments,
uint32_t rectCount,
const VkClearRect *rects);
void clearColorImage(const Image &image,
VkImageLayout imageLayout,
const VkClearColorValue &color,
uint32_t rangeCount,
const VkImageSubresourceRange *ranges);
void clearDepthStencilImage(const Image &image,
VkImageLayout imageLayout,
const VkClearDepthStencilValue &depthStencil,
uint32_t rangeCount,
const VkImageSubresourceRange *ranges);
void copyBuffer(const Buffer &srcBuffer,
const Buffer &destBuffer,
uint32_t regionCount,
const VkBufferCopy *regions);
void copyBufferToImage(VkBuffer srcBuffer,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkBufferImageCopy *regions);
void copyImage(const Image &srcImage,
VkImageLayout srcImageLayout,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageCopy *regions);
void copyImageToBuffer(const Image &srcImage,
VkImageLayout srcImageLayout,
VkBuffer dstBuffer,
uint32_t regionCount,
const VkBufferImageCopy *regions);
void dispatch(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
void draw(uint32_t vertexCount, uint32_t firstVertex);
void drawIndexed(uint32_t indexCount);
void drawIndexedInstanced(uint32_t indexCount, uint32_t instanceCount);
void drawInstanced(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex);
void endQuery(VkQueryPool queryPool, uint32_t query);
void imageBarrier(VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
const VkImageMemoryBarrier *imageMemoryBarrier);
void memoryBarrier(VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
const VkMemoryBarrier *memoryBarrier);
void pipelineBarrier(VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
VkDependencyFlags dependencyFlags,
uint32_t memoryBarrierCount,
const VkMemoryBarrier *memoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *bufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *imageMemoryBarriers);
void pushConstants(const PipelineLayout &layout,
VkShaderStageFlags flag,
uint32_t offset,
uint32_t size,
const void *data);
void resetEvent(VkEvent event, VkPipelineStageFlags stageMask);
void resetQueryPool(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount);
void resolveImage(const Image &srcImage,
VkImageLayout srcImageLayout,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageResolve *regions);
void setEvent(VkEvent event, VkPipelineStageFlags stageMask);
void waitEvents(uint32_t eventCount,
const VkEvent *events,
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
uint32_t memoryBarrierCount,
const VkMemoryBarrier *memoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *bufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *imageMemoryBarriers);
void writeTimestamp(VkPipelineStageFlagBits pipelineStage,
VkQueryPool queryPool,
uint32_t query);
// No-op for compatibility
VkResult end() { return VK_SUCCESS; }
// Parse the cmds in this cmd buffer into given primary cmd buffer for execution
void executeCommands(VkCommandBuffer cmdBuffer);
// Traverse the list of commands and build a summary for diagnostics.
std::string dumpCommands(const char *separator) const;
// Pool Alloc uses 16kB pages w/ 16byte header = 16368bytes. To minimize waste
// using a 16368/12 = 1364. Also better perf than 1024 due to fewer block allocations
static constexpr size_t kBlockSize = 1364;
// Make sure block size is 4-byte aligned to avoid Android errors
static_assert((kBlockSize % 4) == 0, "Check kBlockSize alignment");
// Initialize the SecondaryCommandBuffer by setting the allocator it will use
void initialize(angle::PoolAllocator *allocator)
{
ASSERT(allocator);
mAllocator = allocator;
allocateNewBlock();
// Set first command to Invalid to start
reinterpret_cast<CommandHeader *>(mCurrentWritePointer)->id = CommandID::Invalid;
}
// This will cause the SecondaryCommandBuffer to become invalid by clearing its allocator
void releaseHandle() { mAllocator = nullptr; }
// The SecondaryCommandBuffer is valid if it's been initialized
bool valid() const { return mAllocator != nullptr; }
bool empty() const { return mCommands.size() == 0 || mCommands[0]->id == CommandID::Invalid; }
private:
template <class StructType>
ANGLE_INLINE StructType *commonInit(CommandID cmdID, size_t allocationSize)
{
mCurrentBytesRemaining -= allocationSize;
CommandHeader *header = reinterpret_cast<CommandHeader *>(mCurrentWritePointer);
header->id = cmdID;
header->size = static_cast<uint16_t>(allocationSize);
ASSERT(allocationSize <= std::numeric_limits<uint16_t>::max());
mCurrentWritePointer += allocationSize;
// Set next cmd header to Invalid (0) so cmd sequence will be terminated
reinterpret_cast<CommandHeader *>(mCurrentWritePointer)->id = CommandID::Invalid;
return Offset<StructType>(header, sizeof(CommandHeader));
}
ANGLE_INLINE void allocateNewBlock()
{
ASSERT(mAllocator);
mCurrentWritePointer = mAllocator->fastAllocate(kBlockSize);
mCurrentBytesRemaining = kBlockSize;
mCommands.push_back(reinterpret_cast<CommandHeader *>(mCurrentWritePointer));
}
// Allocate and initialize memory for given commandID & variable param size, setting
// variableDataPtr to the byte following fixed cmd data where variable-sized ptr data will
// be written and returning a pointer to the start of the command's parameter data
template <class StructType>
ANGLE_INLINE StructType *initCommand(CommandID cmdID,
size_t variableSize,
uint8_t **variableDataPtr)
{
constexpr size_t fixedAllocationSize = sizeof(StructType) + sizeof(CommandHeader);
const size_t allocationSize = fixedAllocationSize + variableSize;
// Make sure we have enough room to mark follow-on header "Invalid"
if (mCurrentBytesRemaining <= (allocationSize + sizeof(CommandHeader)))
{
allocateNewBlock();
}
*variableDataPtr = Offset<uint8_t>(mCurrentWritePointer, fixedAllocationSize);
return commonInit<StructType>(cmdID, allocationSize);
}
// Initialize a command that doesn't have variable-sized ptr data
template <class StructType>
ANGLE_INLINE StructType *initCommand(CommandID cmdID)
{
constexpr size_t allocationSize = sizeof(StructType) + sizeof(CommandHeader);
// Make sure we have enough room to mark follow-on header "Invalid"
if (mCurrentBytesRemaining <= (allocationSize + sizeof(CommandHeader)))
{
allocateNewBlock();
}
return commonInit<StructType>(cmdID, allocationSize);
}
// Return a ptr to the parameter type
template <class StructType>
const StructType *getParamPtr(const CommandHeader *header) const
{
return reinterpret_cast<const StructType *>(reinterpret_cast<const uint8_t *>(header) +
sizeof(CommandHeader));
}
// Copy sizeInBytes data from paramData to writePointer & return writePointer plus sizeInBytes.
template <class PtrType>
ANGLE_INLINE uint8_t *storePointerParameter(uint8_t *writePointer,
const PtrType *paramData,
size_t sizeInBytes)
{
memcpy(writePointer, paramData, sizeInBytes);
return writePointer + sizeInBytes;
}
std::vector<CommandHeader *> mCommands;
// Allocator used by this class. If non-null then the class is valid.
angle::PoolAllocator *mAllocator;
uint8_t *mCurrentWritePointer;
size_t mCurrentBytesRemaining;
};
ANGLE_INLINE SecondaryCommandBuffer::SecondaryCommandBuffer()
: mAllocator(nullptr), mCurrentWritePointer(nullptr), mCurrentBytesRemaining(0)
{}
ANGLE_INLINE SecondaryCommandBuffer::~SecondaryCommandBuffer() {}
ANGLE_INLINE void SecondaryCommandBuffer::beginQuery(VkQueryPool queryPool,
uint32_t query,
VkQueryControlFlags flags)
{
BeginQueryParams *paramStruct = initCommand<BeginQueryParams>(CommandID::BeginQuery);
paramStruct->queryPool = queryPool;
paramStruct->query = query;
paramStruct->flags = flags;
}
ANGLE_INLINE void SecondaryCommandBuffer::bindComputePipeline(const Pipeline &pipeline)
{
BindPipelineParams *paramStruct =
initCommand<BindPipelineParams>(CommandID::BindComputePipeline);
paramStruct->pipeline = pipeline.getHandle();
}
ANGLE_INLINE void SecondaryCommandBuffer::bindGraphicsDescriptorSets(
const PipelineLayout &layout,
uint32_t firstSet,
uint32_t descriptorSetCount,
const VkDescriptorSet *descriptorSets,
uint32_t dynamicOffsetCount,
const uint32_t *dynamicOffsets)
{
size_t descSize = descriptorSetCount * sizeof(VkDescriptorSet);
size_t offsetSize = dynamicOffsetCount * sizeof(uint32_t);
uint8_t *writePtr;
BindGraphicsDescriptorSetParams *paramStruct = initCommand<BindGraphicsDescriptorSetParams>(
CommandID::BindGraphicsDescriptorSets, descSize + offsetSize, &writePtr);
// Copy params into memory
paramStruct->layout = layout.getHandle();
paramStruct->firstSet = firstSet;
paramStruct->descriptorSetCount = descriptorSetCount;
paramStruct->dynamicOffsetCount = dynamicOffsetCount;
// Copy variable sized data
writePtr = storePointerParameter(writePtr, descriptorSets, descSize);
storePointerParameter(writePtr, dynamicOffsets, offsetSize);
}
ANGLE_INLINE void SecondaryCommandBuffer::bindComputeDescriptorSets(
const PipelineLayout &layout,
const VkDescriptorSet *descriptorSets)
{
uint8_t *writePtr;
BindComputeDescriptorSetParams *paramStruct = initCommand<BindComputeDescriptorSetParams>(
CommandID::BindComputeDescriptorSets, sizeof(VkDescriptorSet), &writePtr);
// Copy params into memory
paramStruct->layout = layout.getHandle();
// Copy variable sized data
storePointerParameter(writePtr, descriptorSets, sizeof(VkDescriptorSet));
}
ANGLE_INLINE void SecondaryCommandBuffer::bindGraphicsPipeline(const Pipeline &pipeline)
{
BindPipelineParams *paramStruct =
initCommand<BindPipelineParams>(CommandID::BindGraphicsPipeline);
paramStruct->pipeline = pipeline.getHandle();
}
ANGLE_INLINE void SecondaryCommandBuffer::bindIndexBuffer(const Buffer &buffer,
VkDeviceSize offset,
VkIndexType indexType)
{
BindIndexBufferParams *paramStruct =
initCommand<BindIndexBufferParams>(CommandID::BindIndexBuffer);
paramStruct->buffer = buffer.getHandle();
paramStruct->offset = offset;
paramStruct->indexType = indexType;
}
ANGLE_INLINE void SecondaryCommandBuffer::bindVertexBuffers(uint32_t firstBinding,
uint32_t bindingCount,
const VkBuffer *buffers,
const VkDeviceSize *offsets)
{
ASSERT(firstBinding == 0);
uint8_t *writePtr;
size_t buffersSize = bindingCount * sizeof(VkBuffer);
size_t offsetsSize = bindingCount * sizeof(VkDeviceSize);
BindVertexBuffersParams *paramStruct = initCommand<BindVertexBuffersParams>(
CommandID::BindVertexBuffers, buffersSize + offsetsSize, &writePtr);
// Copy params
paramStruct->bindingCount = bindingCount;
writePtr = storePointerParameter(writePtr, buffers, buffersSize);
storePointerParameter(writePtr, offsets, offsetsSize);
}
ANGLE_INLINE void SecondaryCommandBuffer::blitImage(const Image &srcImage,
VkImageLayout srcImageLayout,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageBlit *regions,
VkFilter filter)
{
// Currently ANGLE uses limited params so verify those assumptions and update if they change
ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
ASSERT(regionCount == 1);
BlitImageParams *paramStruct = initCommand<BlitImageParams>(CommandID::BlitImage);
paramStruct->srcImage = srcImage.getHandle();
paramStruct->dstImage = dstImage.getHandle();
paramStruct->filter = filter;
paramStruct->region = regions[0];
}
ANGLE_INLINE void SecondaryCommandBuffer::clearAttachments(uint32_t attachmentCount,
const VkClearAttachment *attachments,
uint32_t rectCount,
const VkClearRect *rects)
{
ASSERT(rectCount == 1);
uint8_t *writePtr;
size_t attachSize = attachmentCount * sizeof(VkClearAttachment);
ClearAttachmentsParams *paramStruct =
initCommand<ClearAttachmentsParams>(CommandID::ClearAttachments, attachSize, &writePtr);
paramStruct->attachmentCount = attachmentCount;
paramStruct->rect = rects[0];
// Copy variable sized data
storePointerParameter(writePtr, attachments, attachSize);
}
ANGLE_INLINE void SecondaryCommandBuffer::clearColorImage(const Image &image,
VkImageLayout imageLayout,
const VkClearColorValue &color,
uint32_t rangeCount,
const VkImageSubresourceRange *ranges)
{
ASSERT(rangeCount == 1);
ClearColorImageParams *paramStruct =
initCommand<ClearColorImageParams>(CommandID::ClearColorImage);
paramStruct->image = image.getHandle();
paramStruct->imageLayout = imageLayout;
paramStruct->color = color;
paramStruct->range = ranges[0];
}
ANGLE_INLINE void SecondaryCommandBuffer::clearDepthStencilImage(
const Image &image,
VkImageLayout imageLayout,
const VkClearDepthStencilValue &depthStencil,
uint32_t rangeCount,
const VkImageSubresourceRange *ranges)
{
ASSERT(rangeCount == 1);
ClearDepthStencilImageParams *paramStruct =
initCommand<ClearDepthStencilImageParams>(CommandID::ClearDepthStencilImage);
paramStruct->image = image.getHandle();
paramStruct->imageLayout = imageLayout;
paramStruct->depthStencil = depthStencil;
paramStruct->range = ranges[0];
}
ANGLE_INLINE void SecondaryCommandBuffer::copyBuffer(const Buffer &srcBuffer,
const Buffer &destBuffer,
uint32_t regionCount,
const VkBufferCopy *regions)
{
uint8_t *writePtr;
size_t regionSize = regionCount * sizeof(VkBufferCopy);
CopyBufferParams *paramStruct =
initCommand<CopyBufferParams>(CommandID::CopyBuffer, regionSize, &writePtr);
paramStruct->srcBuffer = srcBuffer.getHandle();
paramStruct->destBuffer = destBuffer.getHandle();
paramStruct->regionCount = regionCount;
// Copy variable sized data
storePointerParameter(writePtr, regions, regionSize);
}
ANGLE_INLINE void SecondaryCommandBuffer::copyBufferToImage(VkBuffer srcBuffer,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkBufferImageCopy *regions)
{
ASSERT(regionCount == 1);
CopyBufferToImageParams *paramStruct =
initCommand<CopyBufferToImageParams>(CommandID::CopyBufferToImage);
paramStruct->srcBuffer = srcBuffer;
paramStruct->dstImage = dstImage.getHandle();
paramStruct->dstImageLayout = dstImageLayout;
paramStruct->region = regions[0];
}
ANGLE_INLINE void SecondaryCommandBuffer::copyImage(const Image &srcImage,
VkImageLayout srcImageLayout,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageCopy *regions)
{
ASSERT(regionCount == 1);
CopyImageParams *paramStruct = initCommand<CopyImageParams>(CommandID::CopyImage);
paramStruct->srcImage = srcImage.getHandle();
paramStruct->srcImageLayout = srcImageLayout;
paramStruct->dstImage = dstImage.getHandle();
paramStruct->dstImageLayout = dstImageLayout;
paramStruct->region = regions[0];
}
ANGLE_INLINE void SecondaryCommandBuffer::copyImageToBuffer(const Image &srcImage,
VkImageLayout srcImageLayout,
VkBuffer dstBuffer,
uint32_t regionCount,
const VkBufferImageCopy *regions)
{
ASSERT(regionCount == 1);
CopyImageToBufferParams *paramStruct =
initCommand<CopyImageToBufferParams>(CommandID::CopyImageToBuffer);
paramStruct->srcImage = srcImage.getHandle();
paramStruct->srcImageLayout = srcImageLayout;
paramStruct->dstBuffer = dstBuffer;
paramStruct->region = regions[0];
}
ANGLE_INLINE void SecondaryCommandBuffer::dispatch(uint32_t groupCountX,
uint32_t groupCountY,
uint32_t groupCountZ)
{
DispatchParams *paramStruct = initCommand<DispatchParams>(CommandID::Dispatch);
paramStruct->groupCountX = groupCountX;
paramStruct->groupCountY = groupCountY;
paramStruct->groupCountZ = groupCountZ;
}
ANGLE_INLINE void SecondaryCommandBuffer::draw(uint32_t vertexCount, uint32_t firstVertex)
{
DrawParams *paramStruct = initCommand<DrawParams>(CommandID::Draw);
paramStruct->vertexCount = vertexCount;
paramStruct->firstVertex = firstVertex;
}
ANGLE_INLINE void SecondaryCommandBuffer::drawIndexed(uint32_t indexCount)
{
DrawIndexedParams *paramStruct = initCommand<DrawIndexedParams>(CommandID::DrawIndexed);
paramStruct->indexCount = indexCount;
}
ANGLE_INLINE void SecondaryCommandBuffer::drawIndexedInstanced(uint32_t indexCount,
uint32_t instanceCount)
{
DrawIndexedInstancedParams *paramStruct =
initCommand<DrawIndexedInstancedParams>(CommandID::DrawIndexedInstanced);
paramStruct->indexCount = indexCount;
paramStruct->instanceCount = instanceCount;
}
ANGLE_INLINE void SecondaryCommandBuffer::drawInstanced(uint32_t vertexCount,
uint32_t instanceCount,
uint32_t firstVertex)
{
DrawInstancedParams *paramStruct = initCommand<DrawInstancedParams>(CommandID::DrawInstanced);
paramStruct->vertexCount = vertexCount;
paramStruct->instanceCount = instanceCount;
paramStruct->firstVertex = firstVertex;
}
ANGLE_INLINE void SecondaryCommandBuffer::endQuery(VkQueryPool queryPool, uint32_t query)
{
EndQueryParams *paramStruct = initCommand<EndQueryParams>(CommandID::EndQuery);
paramStruct->queryPool = queryPool;
paramStruct->query = query;
}
ANGLE_INLINE void SecondaryCommandBuffer::imageBarrier(
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
const VkImageMemoryBarrier *imageMemoryBarrier)
{
ImageBarrierParams *paramStruct = initCommand<ImageBarrierParams>(CommandID::ImageBarrier);
paramStruct->srcStageMask = srcStageMask;
paramStruct->dstStageMask = dstStageMask;
paramStruct->imageMemoryBarrier = *imageMemoryBarrier;
}
ANGLE_INLINE void SecondaryCommandBuffer::memoryBarrier(VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
const VkMemoryBarrier *memoryBarrier)
{
MemoryBarrierParams *paramStruct = initCommand<MemoryBarrierParams>(CommandID::MemoryBarrier);
paramStruct->srcStageMask = srcStageMask;
paramStruct->dstStageMask = dstStageMask;
paramStruct->memoryBarrier = *memoryBarrier;
}
ANGLE_INLINE void SecondaryCommandBuffer::pipelineBarrier(
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
VkDependencyFlags dependencyFlags,
uint32_t memoryBarrierCount,
const VkMemoryBarrier *memoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *bufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *imageMemoryBarriers)
{
uint8_t *writePtr;
size_t memBarrierSize = memoryBarrierCount * sizeof(VkMemoryBarrier);
size_t buffBarrierSize = bufferMemoryBarrierCount * sizeof(VkBufferMemoryBarrier);
size_t imgBarrierSize = imageMemoryBarrierCount * sizeof(VkImageMemoryBarrier);
PipelineBarrierParams *paramStruct = initCommand<PipelineBarrierParams>(
CommandID::PipelineBarrier, memBarrierSize + buffBarrierSize + imgBarrierSize, &writePtr);
paramStruct->srcStageMask = srcStageMask;
paramStruct->dstStageMask = dstStageMask;
paramStruct->dependencyFlags = dependencyFlags;
paramStruct->memoryBarrierCount = memoryBarrierCount;
paramStruct->bufferMemoryBarrierCount = bufferMemoryBarrierCount;
paramStruct->imageMemoryBarrierCount = imageMemoryBarrierCount;
// Copy variable sized data
writePtr = storePointerParameter(writePtr, memoryBarriers, memBarrierSize);
writePtr = storePointerParameter(writePtr, bufferMemoryBarriers, buffBarrierSize);
storePointerParameter(writePtr, imageMemoryBarriers, imgBarrierSize);
}
ANGLE_INLINE void SecondaryCommandBuffer::pushConstants(const PipelineLayout &layout,
VkShaderStageFlags flag,
uint32_t offset,
uint32_t size,
const void *data)
{
ASSERT(size == static_cast<size_t>(size));
uint8_t *writePtr;
PushConstantsParams *paramStruct = initCommand<PushConstantsParams>(
CommandID::PushConstants, static_cast<size_t>(size), &writePtr);
paramStruct->layout = layout.getHandle();
paramStruct->flag = flag;
paramStruct->offset = offset;
paramStruct->size = size;
// Copy variable sized data
storePointerParameter(writePtr, data, static_cast<size_t>(size));
}
ANGLE_INLINE void SecondaryCommandBuffer::resetEvent(VkEvent event, VkPipelineStageFlags stageMask)
{
ResetEventParams *paramStruct = initCommand<ResetEventParams>(CommandID::ResetEvent);
paramStruct->event = event;
paramStruct->stageMask = stageMask;
}
ANGLE_INLINE void SecondaryCommandBuffer::resetQueryPool(VkQueryPool queryPool,
uint32_t firstQuery,
uint32_t queryCount)
{
ResetQueryPoolParams *paramStruct =
initCommand<ResetQueryPoolParams>(CommandID::ResetQueryPool);
paramStruct->queryPool = queryPool;
paramStruct->firstQuery = firstQuery;
paramStruct->queryCount = queryCount;
}
ANGLE_INLINE void SecondaryCommandBuffer::resolveImage(const Image &srcImage,
VkImageLayout srcImageLayout,
const Image &dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageResolve *regions)
{
// Currently ANGLE uses limited params so verify those assumptions and update if they change.
ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
ASSERT(regionCount == 1);
ResolveImageParams *paramStruct = initCommand<ResolveImageParams>(CommandID::ResolveImage);
paramStruct->srcImage = srcImage.getHandle();
paramStruct->dstImage = dstImage.getHandle();
paramStruct->region = regions[0];
}
ANGLE_INLINE void SecondaryCommandBuffer::setEvent(VkEvent event, VkPipelineStageFlags stageMask)
{
SetEventParams *paramStruct = initCommand<SetEventParams>(CommandID::SetEvent);
paramStruct->event = event;
paramStruct->stageMask = stageMask;
}
ANGLE_INLINE void SecondaryCommandBuffer::waitEvents(
uint32_t eventCount,
const VkEvent *events,
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
uint32_t memoryBarrierCount,
const VkMemoryBarrier *memoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *bufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *imageMemoryBarriers)
{
uint8_t *writePtr;
size_t eventSize = eventCount * sizeof(VkEvent);
size_t memBarrierSize = memoryBarrierCount * sizeof(VkMemoryBarrier);
size_t buffBarrierSize = bufferMemoryBarrierCount * sizeof(VkBufferMemoryBarrier);
size_t imgBarrierSize = imageMemoryBarrierCount * sizeof(VkImageMemoryBarrier);
WaitEventsParams *paramStruct = initCommand<WaitEventsParams>(
CommandID::WaitEvents, eventSize + memBarrierSize + buffBarrierSize + imgBarrierSize,
&writePtr);
paramStruct->eventCount = eventCount;
paramStruct->srcStageMask = srcStageMask;
paramStruct->dstStageMask = dstStageMask;
paramStruct->memoryBarrierCount = memoryBarrierCount;
paramStruct->bufferMemoryBarrierCount = bufferMemoryBarrierCount;
paramStruct->imageMemoryBarrierCount = imageMemoryBarrierCount;
// Copy variable sized data
writePtr = storePointerParameter(writePtr, events, eventSize);
writePtr = storePointerParameter(writePtr, memoryBarriers, memBarrierSize);
writePtr = storePointerParameter(writePtr, bufferMemoryBarriers, buffBarrierSize);
storePointerParameter(writePtr, imageMemoryBarriers, imgBarrierSize);
}
ANGLE_INLINE void SecondaryCommandBuffer::writeTimestamp(VkPipelineStageFlagBits pipelineStage,
VkQueryPool queryPool,
uint32_t query)
{
WriteTimestampParams *paramStruct =
initCommand<WriteTimestampParams>(CommandID::WriteTimestamp);
paramStruct->pipelineStage = pipelineStage;
paramStruct->queryPool = queryPool;
paramStruct->query = query;
}
} // namespace priv
} // namespace vk
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_SECONDARYCOMMANDBUFFERVK_H_