#include "libANGLE/renderer/vulkan/vk_utils.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/vulkan/BufferVk.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/android/vk_android_utils.h"
#include "libANGLE/renderer/vulkan/vk_mem_alloc_wrapper.h"
#include "libANGLE/renderer/vulkan/vk_ref_counted_event.h"
#include "libANGLE/renderer/vulkan/vk_renderer.h"
#include "libANGLE/renderer/vulkan/vk_resource.h"
namespace angle
{
egl::Error ToEGL(Result result, EGLint errorCode)
{ … }
}
namespace rx
{
namespace
{
constexpr int kNonZeroInitValue = …;
VkImageUsageFlags GetStagingBufferUsageFlags(vk::StagingUsage usage)
{ … }
bool FindCompatibleMemory(const VkPhysicalDeviceMemoryProperties &memoryProperties,
const VkMemoryRequirements &memoryRequirements,
VkMemoryPropertyFlags requestedMemoryPropertyFlags,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
uint32_t *typeIndexOut)
{ … }
VkResult FindAndAllocateCompatibleMemory(vk::Context *context,
vk::MemoryAllocationType memoryAllocationType,
const vk::MemoryProperties &memoryProperties,
VkMemoryPropertyFlags requestedMemoryPropertyFlags,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
const VkMemoryRequirements &memoryRequirements,
const void *extraAllocationInfo,
uint32_t *memoryTypeIndexOut,
vk::DeviceMemory *deviceMemoryOut)
{ … }
template <typename T>
VkResult AllocateAndBindBufferOrImageMemory(vk::Context *context,
vk::MemoryAllocationType memoryAllocationType,
VkMemoryPropertyFlags requestedMemoryPropertyFlags,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
const VkMemoryRequirements &memoryRequirements,
const void *extraAllocationInfo,
const VkBindImagePlaneMemoryInfoKHR *extraBindInfo,
T *bufferOrImage,
uint32_t *memoryTypeIndexOut,
vk::DeviceMemory *deviceMemoryOut);
template <>
VkResult AllocateAndBindBufferOrImageMemory(vk::Context *context,
vk::MemoryAllocationType memoryAllocationType,
VkMemoryPropertyFlags requestedMemoryPropertyFlags,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
const VkMemoryRequirements &memoryRequirements,
const void *extraAllocationInfo,
const VkBindImagePlaneMemoryInfoKHR *extraBindInfo,
vk::Image *image,
uint32_t *memoryTypeIndexOut,
vk::DeviceMemory *deviceMemoryOut)
{ … }
template <>
VkResult AllocateAndBindBufferOrImageMemory(vk::Context *context,
vk::MemoryAllocationType memoryAllocationType,
VkMemoryPropertyFlags requestedMemoryPropertyFlags,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
const VkMemoryRequirements &memoryRequirements,
const void *extraAllocationInfo,
const VkBindImagePlaneMemoryInfoKHR *extraBindInfo,
vk::Buffer *buffer,
uint32_t *memoryTypeIndexOut,
vk::DeviceMemory *deviceMemoryOut)
{ … }
template <typename T>
VkResult AllocateBufferOrImageMemory(vk::Context *context,
vk::MemoryAllocationType memoryAllocationType,
VkMemoryPropertyFlags requestedMemoryPropertyFlags,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
const void *extraAllocationInfo,
T *bufferOrImage,
uint32_t *memoryTypeIndexOut,
vk::DeviceMemory *deviceMemoryOut,
VkDeviceSize *sizeOut)
{ … }
constexpr char kVkKhronosValidationLayerName[] = …;
constexpr char kVkStandardValidationLayerName[] = …;
const char *kVkValidationLayerNames[] = …;
}
const char *VulkanResultString(VkResult result)
{ … }
bool GetAvailableValidationLayers(const std::vector<VkLayerProperties> &layerProps,
bool mustHaveLayers,
VulkanLayerVector *enabledLayerNames)
{ … }
vk
#if !defined(ANGLE_SHARED_LIBVULKAN)
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT = nullptr;
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = nullptr;
PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT = nullptr;
PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT = nullptr;
PFN_vkCmdInsertDebugUtilsLabelEXT vkCmdInsertDebugUtilsLabelEXT = nullptr;
PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT = nullptr;
PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR = nullptr;
PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR = nullptr;
PFN_vkGetPhysicalDeviceMemoryProperties2KHR vkGetPhysicalDeviceMemoryProperties2KHR = nullptr;
PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR = nullptr;
PFN_vkResetQueryPoolEXT vkResetQueryPoolEXT = nullptr;
PFN_vkCmdBindTransformFeedbackBuffersEXT vkCmdBindTransformFeedbackBuffersEXT = nullptr;
PFN_vkCmdBeginTransformFeedbackEXT vkCmdBeginTransformFeedbackEXT = nullptr;
PFN_vkCmdEndTransformFeedbackEXT vkCmdEndTransformFeedbackEXT = nullptr;
PFN_vkCmdBeginQueryIndexedEXT vkCmdBeginQueryIndexedEXT = nullptr;
PFN_vkCmdEndQueryIndexedEXT vkCmdEndQueryIndexedEXT = nullptr;
PFN_vkCmdDrawIndirectByteCountEXT vkCmdDrawIndirectByteCountEXT = nullptr;
PFN_vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2KHR = nullptr;
PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2KHR = nullptr;
PFN_vkBindBufferMemory2KHR vkBindBufferMemory2KHR = nullptr;
PFN_vkBindImageMemory2KHR vkBindImageMemory2KHR = nullptr;
PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR vkGetPhysicalDeviceExternalFencePropertiesKHR =
nullptr;
PFN_vkGetFenceFdKHR vkGetFenceFdKHR = nullptr;
PFN_vkImportFenceFdKHR vkImportFenceFdKHR = nullptr;
PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR
vkGetPhysicalDeviceExternalSemaphorePropertiesKHR = nullptr;
PFN_vkCreateSamplerYcbcrConversionKHR vkCreateSamplerYcbcrConversionKHR = nullptr;
PFN_vkDestroySamplerYcbcrConversionKHR vkDestroySamplerYcbcrConversionKHR = nullptr;
PFN_vkCreateRenderPass2KHR vkCreateRenderPass2KHR = nullptr;
# if defined(ANGLE_PLATFORM_FUCHSIA)
PFN_vkCreateImagePipeSurfaceFUCHSIA vkCreateImagePipeSurfaceFUCHSIA = nullptr;
# endif
# if defined(ANGLE_PLATFORM_ANDROID)
PFN_vkGetAndroidHardwareBufferPropertiesANDROID vkGetAndroidHardwareBufferPropertiesANDROID =
nullptr;
PFN_vkGetMemoryAndroidHardwareBufferANDROID vkGetMemoryAndroidHardwareBufferANDROID = nullptr;
# endif
# if defined(ANGLE_PLATFORM_GGP)
PFN_vkCreateStreamDescriptorSurfaceGGP vkCreateStreamDescriptorSurfaceGGP = nullptr;
# endif
#define GET_INSTANCE_FUNC …
#define GET_DEVICE_FUNC …
PFN_vkGetSwapchainStatusKHR vkGetSwapchainStatusKHR = nullptr;
PFN_vkCmdBindVertexBuffers2EXT vkCmdBindVertexBuffers2EXT = nullptr;
PFN_vkCmdSetCullModeEXT vkCmdSetCullModeEXT = nullptr;
PFN_vkCmdSetDepthBoundsTestEnableEXT vkCmdSetDepthBoundsTestEnableEXT = nullptr;
PFN_vkCmdSetDepthCompareOpEXT vkCmdSetDepthCompareOpEXT = nullptr;
PFN_vkCmdSetDepthTestEnableEXT vkCmdSetDepthTestEnableEXT = nullptr;
PFN_vkCmdSetDepthWriteEnableEXT vkCmdSetDepthWriteEnableEXT = nullptr;
PFN_vkCmdSetFrontFaceEXT vkCmdSetFrontFaceEXT = nullptr;
PFN_vkCmdSetPrimitiveTopologyEXT vkCmdSetPrimitiveTopologyEXT = nullptr;
PFN_vkCmdSetScissorWithCountEXT vkCmdSetScissorWithCountEXT = nullptr;
PFN_vkCmdSetStencilOpEXT vkCmdSetStencilOpEXT = nullptr;
PFN_vkCmdSetStencilTestEnableEXT vkCmdSetStencilTestEnableEXT = nullptr;
PFN_vkCmdSetViewportWithCountEXT vkCmdSetViewportWithCountEXT = nullptr;
PFN_vkCmdSetDepthBiasEnableEXT vkCmdSetDepthBiasEnableEXT = nullptr;
PFN_vkCmdSetLogicOpEXT vkCmdSetLogicOpEXT = nullptr;
PFN_vkCmdSetPatchControlPointsEXT vkCmdSetPatchControlPointsEXT = nullptr;
PFN_vkCmdSetPrimitiveRestartEnableEXT vkCmdSetPrimitiveRestartEnableEXT = nullptr;
PFN_vkCmdSetRasterizerDiscardEnableEXT vkCmdSetRasterizerDiscardEnableEXT = nullptr;
PFN_vkCmdSetVertexInputEXT vkCmdSetVertexInputEXT = nullptr;
PFN_vkCmdBeginRenderingKHR vkCmdBeginRenderingKHR = nullptr;
PFN_vkCmdEndRenderingKHR vkCmdEndRenderingKHR = nullptr;
PFN_vkCmdSetRenderingAttachmentLocationsKHR vkCmdSetRenderingAttachmentLocationsKHR = nullptr;
PFN_vkCmdSetRenderingInputAttachmentIndicesKHR vkCmdSetRenderingInputAttachmentIndicesKHR = nullptr;
PFN_vkGetPhysicalDeviceFragmentShadingRatesKHR vkGetPhysicalDeviceFragmentShadingRatesKHR = nullptr;
PFN_vkCmdSetFragmentShadingRateKHR vkCmdSetFragmentShadingRateKHR = nullptr;
PFN_vkGetPastPresentationTimingGOOGLE vkGetPastPresentationTimingGOOGLE = nullptr;
PFN_vkCopyImageToImageEXT vkCopyImageToImageEXT = nullptr;
PFN_vkCopyImageToMemoryEXT vkCopyImageToMemoryEXT = nullptr;
PFN_vkCopyMemoryToImageEXT vkCopyMemoryToImageEXT = nullptr;
PFN_vkGetImageSubresourceLayout2EXT vkGetImageSubresourceLayout2EXT = nullptr;
PFN_vkTransitionImageLayoutEXT vkTransitionImageLayoutEXT = nullptr;
void InitDebugUtilsEXTFunctions(VkInstance instance)
{
GET_INSTANCE_FUNC(vkCreateDebugUtilsMessengerEXT);
GET_INSTANCE_FUNC(vkDestroyDebugUtilsMessengerEXT);
GET_INSTANCE_FUNC(vkCmdBeginDebugUtilsLabelEXT);
GET_INSTANCE_FUNC(vkCmdEndDebugUtilsLabelEXT);
GET_INSTANCE_FUNC(vkCmdInsertDebugUtilsLabelEXT);
GET_INSTANCE_FUNC(vkSetDebugUtilsObjectNameEXT);
}
void InitTransformFeedbackEXTFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCmdBindTransformFeedbackBuffersEXT);
GET_DEVICE_FUNC(vkCmdBeginTransformFeedbackEXT);
GET_DEVICE_FUNC(vkCmdEndTransformFeedbackEXT);
GET_DEVICE_FUNC(vkCmdBeginQueryIndexedEXT);
GET_DEVICE_FUNC(vkCmdEndQueryIndexedEXT);
GET_DEVICE_FUNC(vkCmdDrawIndirectByteCountEXT);
}
void InitRenderPass2KHRFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCreateRenderPass2KHR);
}
# if defined(ANGLE_PLATFORM_FUCHSIA)
void InitImagePipeSurfaceFUCHSIAFunctions(VkInstance instance)
{
GET_INSTANCE_FUNC(vkCreateImagePipeSurfaceFUCHSIA);
}
# endif
# if defined(ANGLE_PLATFORM_ANDROID)
void InitExternalMemoryHardwareBufferANDROIDFunctions(VkInstance instance)
{
GET_INSTANCE_FUNC(vkGetAndroidHardwareBufferPropertiesANDROID);
GET_INSTANCE_FUNC(vkGetMemoryAndroidHardwareBufferANDROID);
}
# endif
# if defined(ANGLE_PLATFORM_GGP)
void InitGGPStreamDescriptorSurfaceFunctions(VkInstance instance)
{
GET_INSTANCE_FUNC(vkCreateStreamDescriptorSurfaceGGP);
}
# endif
void InitExternalSemaphoreFdFunctions(VkInstance instance)
{
GET_INSTANCE_FUNC(vkImportSemaphoreFdKHR);
}
void InitHostQueryResetFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkResetQueryPoolEXT);
}
void InitExternalFenceFdFunctions(VkInstance instance)
{
GET_INSTANCE_FUNC(vkGetFenceFdKHR);
GET_INSTANCE_FUNC(vkImportFenceFdKHR);
}
void InitGetSwapchainStatusKHRFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkGetSwapchainStatusKHR);
}
void InitExtendedDynamicStateEXTFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCmdBindVertexBuffers2EXT);
GET_DEVICE_FUNC(vkCmdSetCullModeEXT);
GET_DEVICE_FUNC(vkCmdSetDepthBoundsTestEnableEXT);
GET_DEVICE_FUNC(vkCmdSetDepthCompareOpEXT);
GET_DEVICE_FUNC(vkCmdSetDepthTestEnableEXT);
GET_DEVICE_FUNC(vkCmdSetDepthWriteEnableEXT);
GET_DEVICE_FUNC(vkCmdSetFrontFaceEXT);
GET_DEVICE_FUNC(vkCmdSetPrimitiveTopologyEXT);
GET_DEVICE_FUNC(vkCmdSetScissorWithCountEXT);
GET_DEVICE_FUNC(vkCmdSetStencilOpEXT);
GET_DEVICE_FUNC(vkCmdSetStencilTestEnableEXT);
GET_DEVICE_FUNC(vkCmdSetViewportWithCountEXT);
}
void InitExtendedDynamicState2EXTFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCmdSetDepthBiasEnableEXT);
GET_DEVICE_FUNC(vkCmdSetLogicOpEXT);
GET_DEVICE_FUNC(vkCmdSetPatchControlPointsEXT);
GET_DEVICE_FUNC(vkCmdSetPrimitiveRestartEnableEXT);
GET_DEVICE_FUNC(vkCmdSetRasterizerDiscardEnableEXT);
}
void InitVertexInputDynamicStateEXTFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCmdSetVertexInputEXT);
}
void InitDynamicRenderingFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCmdBeginRenderingKHR);
GET_DEVICE_FUNC(vkCmdEndRenderingKHR);
}
void InitDynamicRenderingLocalReadFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCmdSetRenderingAttachmentLocationsKHR);
GET_DEVICE_FUNC(vkCmdSetRenderingInputAttachmentIndicesKHR);
}
void InitFragmentShadingRateKHRInstanceFunction(VkInstance instance)
{
GET_INSTANCE_FUNC(vkGetPhysicalDeviceFragmentShadingRatesKHR);
}
void InitFragmentShadingRateKHRDeviceFunction(VkDevice device)
{
GET_DEVICE_FUNC(vkCmdSetFragmentShadingRateKHR);
}
void InitGetPastPresentationTimingGoogleFunction(VkDevice device)
{
GET_DEVICE_FUNC(vkGetPastPresentationTimingGOOGLE);
}
void InitHostImageCopyFunctions(VkDevice device)
{
GET_DEVICE_FUNC(vkCopyImageToImageEXT);
GET_DEVICE_FUNC(vkCopyImageToMemoryEXT);
GET_DEVICE_FUNC(vkCopyMemoryToImageEXT);
GET_DEVICE_FUNC(vkGetImageSubresourceLayout2EXT);
GET_DEVICE_FUNC(vkTransitionImageLayoutEXT);
}
# undef GET_INSTANCE_FUNC
# undef GET_DEVICE_FUNC
#endif
#define ASSIGN_FROM_CORE …
void InitGetPhysicalDeviceProperties2KHRFunctionsFromCore()
{ … }
void InitExternalFenceCapabilitiesFunctionsFromCore()
{ … }
void InitExternalSemaphoreCapabilitiesFunctionsFromCore()
{ … }
void InitSamplerYcbcrKHRFunctionsFromCore()
{ … }
void InitGetMemoryRequirements2KHRFunctionsFromCore()
{ … }
void InitBindMemory2KHRFunctionsFromCore()
{ … }
#undef ASSIGN_FROM_CORE
GLenum CalculateGenerateMipmapFilter(ContextVk *contextVk, angle::FormatID formatID)
{ … }
namespace gl_vk
{
VkFilter GetFilter(const GLenum filter)
{ … }
VkSamplerMipmapMode GetSamplerMipmapMode(const GLenum filter)
{ … }
VkSamplerAddressMode GetSamplerAddressMode(const GLenum wrap)
{ … }
VkRect2D GetRect(const gl::Rectangle &source)
{ … }
VkPrimitiveTopology GetPrimitiveTopology(gl::PrimitiveMode mode)
{ … }
VkPolygonMode GetPolygonMode(const gl::PolygonMode polygonMode)
{ … }
VkCullModeFlagBits GetCullMode(const gl::RasterizerState &rasterState)
{ … }
VkFrontFace GetFrontFace(GLenum frontFace, bool invertCullFace)
{ … }
VkSampleCountFlagBits GetSamples(GLint sampleCount, bool limitSampleCountTo2)
{ … }
VkComponentSwizzle GetSwizzle(const GLenum swizzle)
{ … }
VkCompareOp GetCompareOp(const GLenum compareFunc)
{ … }
VkStencilOp GetStencilOp(GLenum compareOp)
{ … }
VkLogicOp GetLogicOp(const GLenum logicOp)
{ … }
void GetOffset(const gl::Offset &glOffset, VkOffset3D *vkOffset)
{ … }
void GetExtent(const gl::Extents &glExtent, VkExtent3D *vkExtent)
{ … }
VkImageType GetImageType(gl::TextureType textureType)
{ … }
VkImageViewType GetImageViewType(gl::TextureType textureType)
{ … }
VkColorComponentFlags GetColorComponentFlags(bool red, bool green, bool blue, bool alpha)
{ … }
VkShaderStageFlags GetShaderStageFlags(gl::ShaderBitSet activeShaders)
{ … }
void GetViewport(const gl::Rectangle &viewport,
float nearPlane,
float farPlane,
bool invertViewport,
bool clipSpaceOriginUpperLeft,
GLint renderAreaHeight,
VkViewport *viewportOut)
{ … }
void GetExtentsAndLayerCount(gl::TextureType textureType,
const gl::Extents &extents,
VkExtent3D *extentsOut,
uint32_t *layerCountOut)
{ … }
vk::LevelIndex GetLevelIndex(gl::LevelIndex levelGL, gl::LevelIndex baseLevel)
{ … }
VkImageTiling GetTilingMode(gl::TilingMode tilingMode)
{ … }
}
namespace vk_gl
{
void AddSampleCounts(VkSampleCountFlags sampleCounts, gl::SupportedSampleSet *setOut)
{ … }
GLuint GetMaxSampleCount(VkSampleCountFlags sampleCounts)
{ … }
GLuint GetSampleCount(VkSampleCountFlags supportedCounts, GLuint requestedCount)
{ … }
gl::LevelIndex GetLevelIndex(vk::LevelIndex levelVk, gl::LevelIndex baseLevel)
{ … }
}
}