#include "libANGLE/renderer/vulkan/UtilsVk.h"
#include "common/spirv/spirv_instruction_builder_autogen.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/RenderTargetVk.h"
#include "libANGLE/renderer/vulkan/SurfaceVk.h"
#include "libANGLE/renderer/vulkan/vk_renderer.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
namespace rx
{
ConvertVertex_comp;
ImageClear_frag;
ImageCopy_frag;
CopyImageToBuffer_comp;
BlitResolve_frag;
Blit3DSrc_frag;
BlitResolveStencilNoExport_comp;
ExportStencil_frag;
ConvertIndexIndirectLineLoop_comp;
GenerateMipmap_comp;
EtcToBc_comp;
spirv;
namespace
{
constexpr uint32_t kConvertIndexDestinationBinding = …;
constexpr uint32_t kConvertVertexDestinationBinding = …;
constexpr uint32_t kConvertVertexSourceBinding = …;
constexpr uint32_t kImageCopySourceBinding = …;
constexpr uint32_t kCopyImageToBufferSourceBinding = …;
constexpr uint32_t kCopyImageToBufferDestinationBinding = …;
constexpr uint32_t kBlitResolveColorOrDepthBinding = …;
constexpr uint32_t kBlitResolveStencilBinding = …;
constexpr uint32_t kBlitResolveSamplerBinding = …;
constexpr uint32_t kBlitResolveStencilNoExportDestBinding = …;
constexpr uint32_t kBlitResolveStencilNoExportSrcBinding = …;
constexpr uint32_t kBlitResolveStencilNoExportSamplerBinding = …;
constexpr uint32_t kExportStencilInputIndex = …;
constexpr uint32_t kExportStencilBinding = …;
constexpr uint32_t kOverlayDrawTextWidgetsBinding = …;
constexpr uint32_t kOverlayDrawGraphWidgetsBinding = …;
constexpr uint32_t kOverlayDrawFontBinding = …;
constexpr uint32_t kGenerateMipmapDestinationBinding = …;
constexpr uint32_t kGenerateMipmapSourceBinding = …;
constexpr uint32_t kGenerateFragmentShadingRateAttachmentBinding = …;
bool ValidateFloatOneAsUint()
{ … }
uint32_t GetConvertVertexFlags(const UtilsVk::ConvertVertexParameters ¶ms)
{ … }
uint32_t GetImageClearFlags(const angle::Format &format, uint32_t attachmentIndex, bool clearDepth)
{ … }
uint32_t GetFormatFlags(const angle::Format &format,
uint32_t intFlag,
uint32_t uintFlag,
uint32_t floatFlag)
{ … }
uint32_t GetImageCopyFlags(const angle::Format &srcIntendedFormat,
const angle::Format &dstIntendedFormat)
{ … }
uint32_t GetCopyImageToBufferFlags(const angle::Format &srcFormat)
{ … }
uint32_t GetBlitResolveFlags(bool blitColor,
bool blitDepth,
bool blitStencil,
const angle::Format &intendedFormat)
{ … }
uint32_t GetConvertIndexIndirectLineLoopFlag(uint32_t indicesBitsWidth)
{ … }
uint32_t GetGenerateMipmapFlags(ContextVk *contextVk, const angle::Format &actualFormat)
{ … }
enum UnresolveColorAttachmentType
{ … };
uint32_t GetUnresolveFlags(uint32_t colorAttachmentCount,
const gl::DrawBuffersArray<vk::ImageHelper *> &colorSrc,
bool unresolveDepth,
bool unresolveStencil,
gl::DrawBuffersArray<UnresolveColorAttachmentType> *attachmentTypesOut)
{ … }
uint32_t GetFormatDefaultChannelMask(const angle::Format &intendedImageFormat,
const angle::Format &actualImageFormat)
{ … }
void CalculateBlitOffset(const UtilsVk::BlitResolveParameters ¶ms, float offset[2])
{ … }
void CalculateResolveOffset(const UtilsVk::BlitResolveParameters ¶ms, int32_t offset[2])
{ … }
void SetDepthStateForWrite(vk::Renderer *renderer, vk::GraphicsPipelineDesc *desc)
{ … }
void SetDepthStateForUnused(vk::Renderer *renderer, vk::GraphicsPipelineDesc *desc)
{ … }
void SetDepthDynamicStateForWrite(vk::Renderer *renderer,
vk::RenderPassCommandBuffer *commandBuffer)
{ … }
void SetDepthDynamicStateForUnused(vk::Renderer *renderer,
vk::RenderPassCommandBuffer *commandBuffer)
{ … }
void SetStencilStateForWrite(vk::Renderer *renderer, vk::GraphicsPipelineDesc *desc)
{ … }
void SetStencilDynamicStateForWrite(vk::Renderer *renderer,
vk::RenderPassCommandBuffer *commandBuffer)
{ … }
void SetStencilDynamicStateForUnused(vk::Renderer *renderer,
vk::RenderPassCommandBuffer *commandBuffer)
{ … }
void HandlePrimitiveRestart(ContextVk *contextVk,
gl::DrawElementsType glIndexType,
GLsizei indexCount,
const uint8_t *srcPtr,
uint8_t *outPtr)
{ … }
namespace unresolve
{
enum
{ … };
void InsertPreamble(uint32_t colorAttachmentCount,
bool unresolveDepth,
bool unresolveStencil,
angle::spirv::Blob *blobOut)
{ … }
void InsertInputDecorations(spirv::IdRef id,
uint32_t attachmentIndex,
uint32_t binding,
angle::spirv::Blob *blobOut)
{ … }
void InsertColorDecorations(uint32_t colorIndex,
uint32_t colorInputIndexStart,
uint32_t colorBindingIndexStart,
angle::spirv::Blob *blobOut)
{ … }
void InsertDepthStencilDecorations(bool unresolveDepth,
bool unresolveStencil,
bool supportsShaderStencilExport,
uint32_t *nextInputIndex,
uint32_t *nextBindingIndex,
angle::spirv::Blob *blobOut)
{ … }
void InsertDerivativeTypes(spirv::IdRef baseId,
spirv::IdRef vec4Id,
spirv::IdRef vec4OutId,
spirv::IdRef imageTypeId,
spirv::IdRef inputTypeId,
angle::spirv::Blob *blobOut)
{ … }
void InsertCommonTypes(angle::spirv::Blob *blobOut)
{ … }
void InsertVariableDecl(spirv::IdRef outType,
spirv::IdRef outId,
spirv::IdRef inType,
spirv::IdRef inId,
angle::spirv::Blob *blobOut)
{ … }
void InsertColorVariableDecl(uint32_t colorIndex,
UnresolveColorAttachmentType type,
angle::spirv::Blob *blobOut)
{ … }
void InsertDepthStencilVariableDecl(bool unresolveDepth,
bool unresolveStencil,
angle::spirv::Blob *blobOut)
{ … }
void InsertTopOfMain(angle::spirv::Blob *blobOut)
{ … }
void InsertColorUnresolveLoadStore(uint32_t colorIndex,
UnresolveColorAttachmentType type,
angle::spirv::Blob *blobOut)
{ … }
void InsertDepthStencilUnresolveLoadStore(bool unresolveDepth,
bool unresolveStencil,
angle::spirv::Blob *blobOut)
{ … }
void InsertBottomOfMain(angle::spirv::Blob *blobOut)
{ … }
angle::spirv::Blob MakeFragShader(
uint32_t colorAttachmentCount,
gl::DrawBuffersArray<UnresolveColorAttachmentType> &colorAttachmentTypes,
bool unresolveDepth,
bool unresolveStencil,
bool supportsShaderStencilExport)
{ … }
}
angle::Result GetUnresolveFrag(
vk::Context *context,
uint32_t colorAttachmentCount,
gl::DrawBuffersArray<UnresolveColorAttachmentType> &colorAttachmentTypes,
bool unresolveDepth,
bool unresolveStencil,
vk::RefCounted<vk::ShaderModule> *shader)
{ … }
gl::DrawBufferMask MakeColorBufferMask(uint32_t colorAttachmentIndexGL)
{ … }
void UpdateColorAccess(ContextVk *contextVk,
gl::DrawBufferMask colorAttachmentMask,
gl::DrawBufferMask colorEnabledMask)
{ … }
void UpdateDepthStencilAccess(ContextVk *contextVk, bool depthWrite, bool stencilWrite)
{ … }
void ResetDynamicState(ContextVk *contextVk, vk::RenderPassCommandBuffer *commandBuffer)
{ … }
}
UtilsVk::ConvertVertexShaderParams::ConvertVertexShaderParams() = default;
UtilsVk::ImageCopyShaderParams::ImageCopyShaderParams() = default;
uint32_t UtilsVk::GetGenerateMipmapMaxLevels(ContextVk *contextVk)
{ … }
UtilsVk::UtilsVk() = default;
UtilsVk::~UtilsVk() = default;
void UtilsVk::destroy(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureResourcesInitialized(ContextVk *contextVk,
Function function,
VkDescriptorPoolSize *setSizes,
size_t setSizesCount,
size_t pushConstantsSize)
{ … }
angle::Result UtilsVk::ensureConvertIndexResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureConvertIndexIndirectResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureConvertIndexIndirectLineLoopResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureConvertIndirectLineLoopResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureConvertVertexResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureImageClearResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureImageCopyResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureImageCopyResourcesInitializedWithSampler(
ContextVk *contextVk,
const vk::SamplerDesc &samplerDesc)
{ … }
angle::Result UtilsVk::ensureCopyImageToBufferResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureBlitResolveResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureBlitResolveStencilNoExportResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureExportStencilResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureOverlayDrawResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureGenerateMipmapResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureTransCodeEtcToBcResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureUnresolveResourcesInitialized(ContextVk *contextVk,
Function function,
uint32_t attachmentCount)
{ … }
angle::Result UtilsVk::ensureSamplersInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::ensureGenerateFragmentShadingRateResourcesInitialized(ContextVk *contextVk)
{ … }
angle::Result UtilsVk::setupComputeProgram(
ContextVk *contextVk,
Function function,
vk::RefCounted<vk::ShaderModule> *csShader,
ComputeShaderProgramAndPipelines *programAndPipelines,
const VkDescriptorSet descriptorSet,
const void *pushConstants,
size_t pushConstantsSize,
vk::OutsideRenderPassCommandBufferHelper *commandBufferHelper)
{ … }
angle::Result UtilsVk::setupGraphicsProgramWithLayout(
ContextVk *contextVk,
const vk::PipelineLayout &pipelineLayout,
vk::RefCounted<vk::ShaderModule> *vsShader,
vk::RefCounted<vk::ShaderModule> *fsShader,
GraphicsShaderProgramAndPipelines *programAndPipelines,
const vk::GraphicsPipelineDesc *pipelineDesc,
const VkDescriptorSet descriptorSet,
const void *pushConstants,
size_t pushConstantsSize,
vk::RenderPassCommandBuffer *commandBuffer)
{ … }
angle::Result UtilsVk::setupGraphicsProgram(ContextVk *contextVk,
Function function,
vk::RefCounted<vk::ShaderModule> *vsShader,
vk::RefCounted<vk::ShaderModule> *fsShader,
GraphicsShaderProgramAndPipelines *programAndPipelines,
const vk::GraphicsPipelineDesc *pipelineDesc,
const VkDescriptorSet descriptorSet,
const void *pushConstants,
size_t pushConstantsSize,
vk::RenderPassCommandBuffer *commandBuffer)
{ … }
angle::Result UtilsVk::convertIndexBuffer(ContextVk *contextVk,
vk::BufferHelper *dst,
vk::BufferHelper *src,
const ConvertIndexParameters ¶ms)
{ … }
angle::Result UtilsVk::convertIndexIndirectBuffer(ContextVk *contextVk,
vk::BufferHelper *srcIndirectBuf,
vk::BufferHelper *srcIndexBuf,
vk::BufferHelper *dstIndirectBuf,
vk::BufferHelper *dstIndexBuf,
const ConvertIndexIndirectParameters ¶ms)
{ … }
angle::Result UtilsVk::convertLineLoopIndexIndirectBuffer(
ContextVk *contextVk,
vk::BufferHelper *srcIndirectBuffer,
vk::BufferHelper *srcIndexBuffer,
vk::BufferHelper *dstIndirectBuffer,
vk::BufferHelper *dstIndexBuffer,
const ConvertLineLoopIndexIndirectParameters ¶ms)
{ … }
angle::Result UtilsVk::convertLineLoopArrayIndirectBuffer(
ContextVk *contextVk,
vk::BufferHelper *srcIndirectBuffer,
vk::BufferHelper *dstIndirectBuffer,
vk::BufferHelper *dstIndexBuffer,
const ConvertLineLoopArrayIndirectParameters ¶ms)
{ … }
angle::Result UtilsVk::convertVertexBuffer(ContextVk *contextVk,
vk::BufferHelper *dst,
vk::BufferHelper *src,
const ConvertVertexParameters ¶ms)
{ … }
angle::Result UtilsVk::convertVertexBufferImpl(
ContextVk *contextVk,
vk::BufferHelper *dst,
vk::BufferHelper *src,
uint32_t flags,
vk::OutsideRenderPassCommandBufferHelper *commandBufferHelper,
const ConvertVertexShaderParams &shaderParams)
{ … }
angle::Result UtilsVk::startRenderPass(ContextVk *contextVk,
vk::ImageHelper *image,
const vk::ImageView *imageView,
const vk::RenderPassDesc &renderPassDesc,
const gl::Rectangle &renderArea,
vk::RenderPassCommandBuffer **commandBufferOut)
{ … }
angle::Result UtilsVk::clearFramebuffer(ContextVk *contextVk,
FramebufferVk *framebuffer,
const ClearFramebufferParameters ¶ms)
{ … }
angle::Result UtilsVk::clearImage(ContextVk *contextVk,
vk::ImageHelper *dst,
const ClearImageParameters ¶ms)
{ … }
angle::Result UtilsVk::colorBlitResolve(ContextVk *contextVk,
FramebufferVk *framebuffer,
vk::ImageHelper *src,
const vk::ImageView *srcView,
const BlitResolveParameters ¶ms)
{ … }
angle::Result UtilsVk::depthStencilBlitResolve(ContextVk *contextVk,
FramebufferVk *framebuffer,
vk::ImageHelper *src,
const vk::ImageView *srcDepthView,
const vk::ImageView *srcStencilView,
const BlitResolveParameters ¶ms)
{ … }
angle::Result UtilsVk::blitResolveImpl(ContextVk *contextVk,
FramebufferVk *framebuffer,
vk::ImageHelper *src,
const vk::ImageView *srcColorView,
const vk::ImageView *srcDepthView,
const vk::ImageView *srcStencilView,
const BlitResolveParameters ¶ms)
{ … }
angle::Result UtilsVk::stencilBlitResolveNoShaderExport(ContextVk *contextVk,
FramebufferVk *framebuffer,
vk::ImageHelper *src,
const vk::ImageView *srcStencilView,
const BlitResolveParameters ¶ms)
{ … }
angle::Result UtilsVk::copyImage(ContextVk *contextVk,
vk::ImageHelper *dst,
const vk::ImageView *destView,
vk::ImageHelper *src,
const vk::ImageView *srcView,
const CopyImageParameters ¶ms)
{ … }
angle::Result UtilsVk::copyImageBits(ContextVk *contextVk,
vk::ImageHelper *dst,
vk::ImageHelper *src,
const CopyImageBitsParameters ¶ms)
{ … }
angle::Result UtilsVk::copyImageToBuffer(ContextVk *contextVk,
vk::BufferHelper *dst,
vk::ImageHelper *src,
const CopyImageToBufferParameters ¶ms)
{ … }
angle::Result UtilsVk::copyRgbToRgba(ContextVk *contextVk,
const angle::Format &srcFormat,
vk::BufferHelper *srcBuffer,
uint32_t srcOffset,
uint32_t pixelCount,
vk::BufferHelper *dstBuffer)
{ … }
uint32_t GetEtcToBcFlags(const angle::Format &format)
{ … }
angle::FormatID GetCompactibleUINTFormat(const angle::Format &format)
{ … }
angle::Result UtilsVk::transCodeEtcToBc(ContextVk *contextVk,
vk::BufferHelper *srcBuffer,
vk::ImageHelper *dstImage,
const VkBufferImageCopy *copyRegion)
{ … }
angle::Result UtilsVk::generateMipmap(ContextVk *contextVk,
vk::ImageHelper *src,
const vk::ImageView *srcLevelZeroView,
vk::ImageHelper *dst,
const GenerateMipmapDestLevelViews &destLevelViews,
const vk::Sampler &sampler,
const GenerateMipmapParameters ¶ms)
{ … }
angle::Result UtilsVk::unresolve(ContextVk *contextVk,
const FramebufferVk *framebuffer,
const UnresolveParameters ¶ms)
{ … }
angle::Result UtilsVk::drawOverlay(ContextVk *contextVk,
vk::BufferHelper *textWidgetsBuffer,
vk::BufferHelper *graphWidgetsBuffer,
vk::ImageHelper *font,
const vk::ImageView *fontView,
vk::ImageHelper *dst,
const vk::ImageView *destView,
const OverlayDrawParameters ¶ms)
{ … }
angle::Result UtilsVk::generateFragmentShadingRate(
ContextVk *contextVk,
vk::ImageHelper *shadingRateAttachmentImageHelper,
vk::ImageViewHelper *shadingRateAttachmentImageViewHelper,
const GenerateFragmentShadingRateParameters &shadingRateParameters)
{ … }
angle::Result UtilsVk::allocateDescriptorSetWithLayout(
ContextVk *contextVk,
vk::CommandBufferHelperCommon *commandBufferHelper,
vk::DynamicDescriptorPool &descriptorPool,
const vk::DescriptorSetLayout &descriptorSetLayout,
VkDescriptorSet *descriptorSetOut)
{ … }
angle::Result UtilsVk::allocateDescriptorSet(ContextVk *contextVk,
vk::CommandBufferHelperCommon *commandBufferHelper,
Function function,
VkDescriptorSet *descriptorSetOut)
{ … }
angle::Result UtilsVk::allocateDescriptorSetForImageCopyWithSampler(
ContextVk *contextVk,
vk::CommandBufferHelperCommon *commandBufferHelper,
const vk::SamplerDesc &samplerDesc,
VkDescriptorSet *descriptorSetOut)
{ … }
UtilsVk::ClearFramebufferParameters::ClearFramebufferParameters()
: … { … }
LineLoopHelper::LineLoopHelper(vk::Renderer *renderer) { … }
LineLoopHelper::~LineLoopHelper() = default;
angle::Result LineLoopHelper::getIndexBufferForDrawArrays(ContextVk *contextVk,
uint32_t clampedVertexCount,
GLint firstVertex,
vk::BufferHelper **bufferOut)
{ … }
angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(ContextVk *contextVk,
BufferVk *elementArrayBufferVk,
gl::DrawElementsType glIndexType,
int indexCount,
intptr_t elementArrayOffset,
vk::BufferHelper **bufferOut,
uint32_t *indexCountOut)
{ … }
angle::Result LineLoopHelper::streamIndices(ContextVk *contextVk,
gl::DrawElementsType glIndexType,
GLsizei indexCount,
const uint8_t *srcPtr,
vk::BufferHelper **bufferOut,
uint32_t *indexCountOut)
{ … }
angle::Result LineLoopHelper::streamIndicesIndirect(ContextVk *contextVk,
gl::DrawElementsType glIndexType,
vk::BufferHelper *srcIndexBuffer,
vk::BufferHelper *srcIndirectBuffer,
VkDeviceSize indirectBufferOffset,
vk::BufferHelper **dstIndexBufferOut,
vk::BufferHelper **dstIndirectBufferOut)
{ … }
angle::Result LineLoopHelper::streamArrayIndirect(ContextVk *contextVk,
size_t vertexCount,
vk::BufferHelper *arrayIndirectBuffer,
VkDeviceSize arrayIndirectBufferOffset,
vk::BufferHelper **dstIndexBufferOut,
vk::BufferHelper **dstIndexIndirectBufferOut)
{ … }
void LineLoopHelper::release(ContextVk *contextVk)
{ … }
void LineLoopHelper::destroy(vk::Renderer *renderer)
{ … }
}