2016-02-16 19:24:00 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2016 - Hans-Kristian Arntzen
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VULKAN_COMMON_H__
|
|
|
|
#define VULKAN_COMMON_H__
|
|
|
|
|
2016-02-19 13:23:51 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-02-19 13:38:15 +00:00
|
|
|
#define VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS 16
|
|
|
|
#define VULKAN_MAX_DESCRIPTOR_POOL_SIZES 16
|
|
|
|
#define VULKAN_BUFFER_BLOCK_SIZE (4 * 1024)
|
|
|
|
|
|
|
|
#define VULKAN_MAX_SWAPCHAIN_IMAGES 8
|
|
|
|
|
|
|
|
#define VULKAN_DIRTY_DYNAMIC_BIT 0x0001
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
#define VK_PROTOTYPES
|
2016-02-19 13:23:51 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_WAYLAND
|
|
|
|
#define VK_USE_PLATFORM_WAYLAND_KHR
|
|
|
|
#endif
|
|
|
|
|
2016-02-19 13:26:45 +00:00
|
|
|
#ifdef HAVE_MIR
|
|
|
|
#define VK_USE_PLATFORM_MIR_KHR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define VK_USE_PLATFORM_WIN32_KHR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XCB
|
|
|
|
#define VK_USE_PLATFORM_XCB_KHR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XLIB
|
|
|
|
#define VK_USE_PLATFORM_XLIB_KHR
|
|
|
|
#endif
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
2016-02-23 00:24:15 +00:00
|
|
|
#ifndef VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL
|
|
|
|
#define VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL 1024
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct VkDmaBufImageCreateInfo_
|
|
|
|
{
|
|
|
|
VkStructureType sType; /* Must be VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL */
|
|
|
|
const void* pNext; /* Pointer to next structure. */
|
|
|
|
int fd;
|
|
|
|
VkFormat format;
|
|
|
|
VkExtent3D extent; /* Depth must be 1 */
|
|
|
|
uint32_t strideInBytes;
|
|
|
|
} VkDmaBufImageCreateInfo;
|
|
|
|
|
|
|
|
typedef VkResult (VKAPI_PTR *PFN_vkCreateDmaBufImageINTEL)(VkDevice device,
|
|
|
|
const VkDmaBufImageCreateInfo* pCreateInfo,
|
|
|
|
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMem, VkImage* pImage);
|
|
|
|
|
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDmaBufImageINTEL(
|
|
|
|
VkDevice _device,
|
|
|
|
const VkDmaBufImageCreateInfo* pCreateInfo,
|
|
|
|
const VkAllocationCallbacks* pAllocator,
|
|
|
|
VkDeviceMemory* pMem,
|
|
|
|
VkImage* pImage);
|
|
|
|
|
2016-02-21 09:11:35 +00:00
|
|
|
#include <boolean.h>
|
2016-02-16 19:24:00 +00:00
|
|
|
#include <retro_inline.h>
|
|
|
|
#include <retro_miscellaneous.h>
|
2016-02-21 09:11:35 +00:00
|
|
|
#include <gfx/math/matrix_4x4.h>
|
|
|
|
#include <gfx/scaler/scaler.h>
|
|
|
|
#include <rthreads/rthreads.h>
|
|
|
|
#include <formats/image.h>
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
#include "../../driver.h"
|
|
|
|
#include "../../performance.h"
|
|
|
|
#include "../../libretro.h"
|
|
|
|
#include "../../general.h"
|
|
|
|
#include "../../retroarch.h"
|
|
|
|
#include "../font_driver.h"
|
|
|
|
#include "../video_context_driver.h"
|
|
|
|
#include "libretro_vulkan.h"
|
|
|
|
#include "../drivers_shader/shader_vulkan.h"
|
|
|
|
|
2016-02-19 13:38:15 +00:00
|
|
|
enum vk_texture_type
|
|
|
|
{
|
2016-02-21 11:33:16 +00:00
|
|
|
/* We will use the texture as a sampled linear texture. */
|
2016-02-19 13:38:15 +00:00
|
|
|
VULKAN_TEXTURE_STREAMED = 0,
|
2016-02-21 11:33:16 +00:00
|
|
|
|
|
|
|
/* We will use the texture as a linear texture, but only
|
|
|
|
* for copying to a DYNAMIC texture. */
|
|
|
|
VULKAN_TEXTURE_STAGING,
|
|
|
|
|
|
|
|
/* We will use the texture as an optimally tiled texture,
|
|
|
|
* and we will update the texture by copying from STAGING
|
|
|
|
* textures. */
|
|
|
|
VULKAN_TEXTURE_DYNAMIC,
|
|
|
|
|
|
|
|
/* We will upload content once. */
|
2016-02-19 13:38:15 +00:00
|
|
|
VULKAN_TEXTURE_STATIC,
|
2016-02-21 11:33:16 +00:00
|
|
|
|
|
|
|
/* We will use the texture for reading back transfers from GPU. */
|
2016-02-19 13:38:15 +00:00
|
|
|
VULKAN_TEXTURE_READBACK
|
|
|
|
};
|
2016-02-16 19:24:00 +00:00
|
|
|
|
2016-02-19 10:36:46 +00:00
|
|
|
enum vulkan_wsi_type
|
|
|
|
{
|
|
|
|
VULKAN_WSI_NONE = 0,
|
2016-02-19 10:50:25 +00:00
|
|
|
VULKAN_WSI_WAYLAND,
|
2016-02-19 11:24:20 +00:00
|
|
|
VULKAN_WSI_MIR,
|
2016-02-19 10:50:25 +00:00
|
|
|
VULKAN_WSI_ANDROID,
|
|
|
|
VULKAN_WSI_WIN32,
|
2016-02-19 11:23:16 +00:00
|
|
|
VULKAN_WSI_XCB,
|
2016-02-19 10:50:25 +00:00
|
|
|
VULKAN_WSI_XLIB
|
2016-02-19 10:36:46 +00:00
|
|
|
};
|
|
|
|
|
2016-02-29 15:47:21 +00:00
|
|
|
#define VKFUNC(sym) (vkcfp->sym)
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
typedef struct vulkan_context
|
|
|
|
{
|
2016-02-29 15:47:21 +00:00
|
|
|
struct vulkan_context_fp
|
2016-02-29 03:21:08 +00:00
|
|
|
{
|
2016-02-29 20:27:18 +00:00
|
|
|
/* Instance */
|
|
|
|
PFN_vkCreateInstance vkCreateInstance;
|
|
|
|
PFN_vkDestroyInstance vkDestroyInstance;
|
|
|
|
|
2016-02-29 21:36:53 +00:00
|
|
|
/* Device */
|
|
|
|
PFN_vkCreateDevice vkCreateDevice;
|
|
|
|
PFN_vkDestroyDevice vkDestroyDevice;
|
|
|
|
|
|
|
|
/* Device Memory */
|
|
|
|
PFN_vkAllocateMemory vkAllocateMemory;
|
|
|
|
PFN_vkFreeMemory vkFreeMemory;
|
|
|
|
|
2016-02-29 22:04:17 +00:00
|
|
|
/* Command Function Pointers */
|
|
|
|
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
|
|
|
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
|
|
|
|
|
2016-02-29 21:36:53 +00:00
|
|
|
/* Buffers */
|
|
|
|
PFN_vkCreateBuffer vkCreateBuffer;
|
|
|
|
PFN_vkDestroyBuffer vkDestroyBuffer;
|
|
|
|
|
2016-02-29 16:21:40 +00:00
|
|
|
/* Fences */
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateFence vkCreateFence;
|
2016-02-29 16:21:40 +00:00
|
|
|
PFN_vkDestroyFence vkDestroyFence;
|
2016-02-29 05:16:31 +00:00
|
|
|
PFN_vkResetFences vkResetFences;
|
|
|
|
PFN_vkWaitForFences vkWaitForFences;
|
2016-02-29 16:21:40 +00:00
|
|
|
|
|
|
|
/* Semaphores */
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateSemaphore vkCreateSemaphore;
|
2016-02-29 16:21:40 +00:00
|
|
|
PFN_vkDestroySemaphore vkDestroySemaphore;
|
|
|
|
|
|
|
|
/* Images */
|
2016-02-29 15:48:55 +00:00
|
|
|
PFN_vkCreateImage vkCreateImage;
|
2016-02-29 16:16:01 +00:00
|
|
|
PFN_vkDestroyImage vkDestroyImage;
|
2016-02-29 16:21:40 +00:00
|
|
|
PFN_vkCmdCopyImage vkCmdCopyImage;
|
|
|
|
|
2016-02-29 20:55:54 +00:00
|
|
|
/* Image Views */
|
|
|
|
PFN_vkCreateImageView vkCreateImageView;
|
|
|
|
PFN_vkDestroyImageView vkDestroyImageView;
|
|
|
|
|
2016-02-29 22:04:17 +00:00
|
|
|
/* Resource Memory Association */
|
|
|
|
PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
|
|
|
|
|
2016-02-29 16:21:40 +00:00
|
|
|
/* Queues */
|
|
|
|
PFN_vkGetDeviceQueue vkGetDeviceQueue;
|
|
|
|
PFN_vkQueueWaitIdle vkQueueWaitIdle;
|
|
|
|
|
|
|
|
/* Pipelines */
|
2016-02-29 21:04:23 +00:00
|
|
|
PFN_vkDestroyPipeline vkDestroyPipeline;
|
2016-02-29 21:55:31 +00:00
|
|
|
PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines;
|
2016-02-29 21:04:23 +00:00
|
|
|
|
|
|
|
/* Pipeline Layouts */
|
2016-02-29 15:37:15 +00:00
|
|
|
PFN_vkCreatePipelineLayout vkCreatePipelineLayout;
|
2016-02-29 21:04:23 +00:00
|
|
|
PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout;
|
|
|
|
|
|
|
|
/* Pipeline Cache */
|
2016-02-29 15:37:15 +00:00
|
|
|
PFN_vkCreatePipelineCache vkCreatePipelineCache;
|
2016-02-29 21:38:58 +00:00
|
|
|
PFN_vkDestroyPipelineCache vkDestroyPipelineCache;
|
2016-02-29 21:30:23 +00:00
|
|
|
|
|
|
|
/* Pipeline Barriers */
|
|
|
|
PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
|
2016-02-29 17:40:30 +00:00
|
|
|
|
|
|
|
/* Descriptor pools */
|
|
|
|
PFN_vkCreateDescriptorPool vkCreateDescriptorPool;
|
|
|
|
|
|
|
|
/* Descriptor sets */
|
|
|
|
PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets;
|
|
|
|
PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets;
|
2016-02-29 16:21:40 +00:00
|
|
|
|
2016-02-29 21:04:23 +00:00
|
|
|
/* Descriptor Set Layout */
|
|
|
|
PFN_vkCreateDescriptorSetLayout vkCreateDescriptorSetLayout;
|
|
|
|
PFN_vkDestroyDescriptorSetLayout vkDestroyDescriptorSetLayout;
|
|
|
|
|
2016-02-29 20:37:35 +00:00
|
|
|
/* Command Buffers */
|
2016-02-29 18:11:09 +00:00
|
|
|
PFN_vkCreateCommandPool vkCreateCommandPool;
|
2016-02-29 20:17:21 +00:00
|
|
|
PFN_vkDestroyCommandPool vkDestroyCommandPool;
|
2016-02-29 20:37:35 +00:00
|
|
|
PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
|
2016-02-29 20:31:51 +00:00
|
|
|
PFN_vkEndCommandBuffer vkEndCommandBuffer;
|
2016-02-29 20:37:35 +00:00
|
|
|
PFN_vkResetCommandBuffer vkResetCommandBuffer;
|
2016-02-29 20:58:10 +00:00
|
|
|
PFN_vkFreeCommandBuffers vkFreeCommandBuffers;
|
2016-02-29 20:51:42 +00:00
|
|
|
PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
|
2016-02-29 20:37:35 +00:00
|
|
|
|
|
|
|
/* Command Buffer Submission */
|
|
|
|
PFN_vkQueueSubmit vkQueueSubmit;
|
2016-02-29 18:11:09 +00:00
|
|
|
|
2016-02-29 18:03:18 +00:00
|
|
|
/* Framebuffers */
|
2016-02-29 16:21:40 +00:00
|
|
|
PFN_vkCreateFramebuffer vkCreateFramebuffer;
|
2016-02-29 20:55:54 +00:00
|
|
|
PFN_vkDestroyFramebuffer vkDestroyFramebuffer;
|
2016-02-29 18:03:18 +00:00
|
|
|
|
|
|
|
/* Memory allocation */
|
|
|
|
PFN_vkMapMemory vkMapMemory;
|
|
|
|
PFN_vkUnmapMemory vkUnmapMemory;
|
|
|
|
|
2016-02-29 18:11:09 +00:00
|
|
|
/* Samplers */
|
|
|
|
PFN_vkCreateSampler vkCreateSampler;
|
|
|
|
PFN_vkDestroySampler vkDestroySampler;
|
2016-02-29 16:21:40 +00:00
|
|
|
|
2016-02-29 18:39:49 +00:00
|
|
|
/* Render Passes */
|
|
|
|
PFN_vkCreateRenderPass vkCreateRenderPass;
|
2016-02-29 21:23:35 +00:00
|
|
|
PFN_vkDestroyRenderPass vkDestroyRenderPass;
|
2016-02-29 18:39:49 +00:00
|
|
|
|
2016-02-29 21:55:31 +00:00
|
|
|
/* Pipeline commands */
|
|
|
|
PFN_vkCmdBindPipeline vkCmdBindPipeline;
|
|
|
|
|
2016-02-29 20:43:04 +00:00
|
|
|
/* Render Pass commands */
|
|
|
|
PFN_vkCmdBeginRenderPass vkCmdBeginRenderPass;
|
|
|
|
PFN_vkCmdEndRenderPass vkCmdEndRenderPass;
|
|
|
|
|
2016-02-29 18:34:40 +00:00
|
|
|
/* Clear commands */
|
|
|
|
PFN_vkCmdClearAttachments vkCmdClearAttachments;
|
|
|
|
|
2016-02-29 18:39:49 +00:00
|
|
|
/* Drawing commands */
|
|
|
|
PFN_vkCmdDraw vkCmdDraw;
|
|
|
|
|
|
|
|
/* Fragment operations */
|
|
|
|
PFN_vkCmdSetScissor vkCmdSetScissor;
|
|
|
|
|
|
|
|
/* Fixed-function vertex postprocessing */
|
|
|
|
PFN_vkCmdSetViewport vkCmdSetViewport;
|
|
|
|
|
2016-02-29 21:55:31 +00:00
|
|
|
/* Shaders */
|
|
|
|
PFN_vkCreateShaderModule vkCreateShaderModule;
|
|
|
|
PFN_vkDestroyShaderModule vkDestroyShaderModule;
|
|
|
|
|
2016-02-29 16:13:13 +00:00
|
|
|
PFN_vkGetPhysicalDeviceFormatProperties vkGetPhysicalDeviceFormatProperties;
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
|
|
|
|
PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
|
|
|
|
PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
|
|
|
|
PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
|
2016-02-29 16:21:40 +00:00
|
|
|
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
|
2016-02-29 16:22:57 +00:00
|
|
|
|
|
|
|
/* Swapchains */
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR;
|
|
|
|
PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
|
|
|
|
PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
|
2016-02-29 16:22:57 +00:00
|
|
|
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
|
|
|
|
PFN_vkQueuePresentKHR vkQueuePresentKHR;
|
2016-02-29 16:22:57 +00:00
|
|
|
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
|
|
|
|
|
|
|
|
/* Platform-specific surface functions */
|
2016-02-19 13:23:51 +00:00
|
|
|
#ifdef _WIN32
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR;
|
2016-02-19 13:23:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XCB
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR;
|
2016-02-19 13:23:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_XLIB
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR;
|
2016-02-19 13:23:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ANDROID
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR;
|
2016-02-19 13:23:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WAYLAND
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR;
|
2016-02-19 13:23:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MIR
|
2016-02-29 04:57:23 +00:00
|
|
|
PFN_vkCreateMirSurfaceKHR vkCreateMirSurfaceKHR;
|
2016-02-19 13:23:51 +00:00
|
|
|
#endif
|
2016-02-29 03:21:08 +00:00
|
|
|
} fp;
|
|
|
|
|
2016-02-29 04:48:34 +00:00
|
|
|
VkInstance instance;
|
|
|
|
VkPhysicalDevice gpu;
|
|
|
|
VkDevice device;
|
|
|
|
VkQueue queue;
|
|
|
|
uint32_t graphics_queue_index;
|
|
|
|
|
|
|
|
VkPhysicalDeviceProperties gpu_properties;
|
|
|
|
VkPhysicalDeviceMemoryProperties memory_properties;
|
|
|
|
|
|
|
|
bool invalid_swapchain;
|
|
|
|
VkImage swapchain_images[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
|
|
|
VkFence swapchain_fences[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
|
|
|
VkSemaphore swapchain_semaphores[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
|
|
|
uint32_t num_swapchain_images;
|
|
|
|
uint32_t current_swapchain_index;
|
|
|
|
unsigned swapchain_width;
|
|
|
|
unsigned swapchain_height;
|
|
|
|
VkFormat swapchain_format;
|
|
|
|
|
|
|
|
slock_t *queue_lock;
|
|
|
|
|
|
|
|
/* Used by screenshot to get blits with correct colorspace. */
|
|
|
|
bool swapchain_is_srgb;
|
|
|
|
} vulkan_context_t;
|
2016-02-19 13:23:51 +00:00
|
|
|
|
2016-02-29 04:48:34 +00:00
|
|
|
typedef struct gfx_ctx_vulkan_data
|
|
|
|
{
|
|
|
|
vulkan_context_t context;
|
2016-02-19 13:23:51 +00:00
|
|
|
VkSurfaceKHR vk_surface;
|
|
|
|
VkSwapchainKHR swapchain;
|
|
|
|
bool need_new_swapchain;
|
|
|
|
} gfx_ctx_vulkan_data_t;
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
struct vk_color
|
|
|
|
{
|
|
|
|
float r, g, b, a;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_vertex
|
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
float tex_x, tex_y;
|
|
|
|
struct vk_color color;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_image
|
|
|
|
{
|
|
|
|
VkImage image;
|
|
|
|
VkImageView view;
|
|
|
|
VkFramebuffer framebuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_texture
|
|
|
|
{
|
|
|
|
VkImage image;
|
|
|
|
VkImageView view;
|
|
|
|
VkDeviceMemory memory;
|
|
|
|
|
|
|
|
unsigned width, height;
|
|
|
|
VkFormat format;
|
|
|
|
|
|
|
|
void *mapped;
|
|
|
|
size_t offset;
|
|
|
|
size_t stride;
|
|
|
|
size_t size;
|
|
|
|
VkDeviceSize memory_size;
|
|
|
|
uint32_t memory_type;
|
|
|
|
|
|
|
|
VkImageLayout layout;
|
2016-02-21 11:33:16 +00:00
|
|
|
enum vk_texture_type type;
|
2016-02-16 19:24:00 +00:00
|
|
|
bool default_smooth;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_buffer
|
|
|
|
{
|
|
|
|
VkBuffer buffer;
|
|
|
|
VkDeviceMemory memory;
|
|
|
|
VkDeviceSize size;
|
|
|
|
void *mapped;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_buffer_node
|
|
|
|
{
|
|
|
|
struct vk_buffer buffer;
|
|
|
|
struct vk_buffer_node *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_buffer_chain
|
|
|
|
{
|
|
|
|
VkDeviceSize block_size;
|
|
|
|
VkDeviceSize alignment;
|
|
|
|
VkDeviceSize offset;
|
|
|
|
VkBufferUsageFlags usage;
|
|
|
|
struct vk_buffer_node *head;
|
|
|
|
struct vk_buffer_node *current;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_buffer_range
|
|
|
|
{
|
|
|
|
uint8_t *data;
|
|
|
|
VkBuffer buffer;
|
|
|
|
VkDeviceSize offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_buffer_chain vulkan_buffer_chain_init(
|
|
|
|
VkDeviceSize block_size,
|
|
|
|
VkDeviceSize alignment,
|
|
|
|
VkBufferUsageFlags usage);
|
2016-02-19 13:38:15 +00:00
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
void vulkan_buffer_chain_discard(struct vk_buffer_chain *chain);
|
2016-02-19 13:38:15 +00:00
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
|
2016-02-19 13:38:15 +00:00
|
|
|
struct vk_buffer_chain *chain, size_t size,
|
|
|
|
struct vk_buffer_range *range);
|
|
|
|
|
2016-02-29 18:03:18 +00:00
|
|
|
void vulkan_buffer_chain_free(
|
|
|
|
struct vulkan_context_fp *vkcfp,
|
|
|
|
VkDevice device,
|
2016-02-19 13:38:15 +00:00
|
|
|
struct vk_buffer_chain *chain);
|
2016-02-16 19:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct vk_descriptor_pool
|
|
|
|
{
|
|
|
|
VkDescriptorPool pool;
|
|
|
|
VkDescriptorSet sets[VULKAN_DESCRIPTOR_MANAGER_BLOCK_SETS];
|
|
|
|
struct vk_descriptor_pool *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_descriptor_manager
|
|
|
|
{
|
|
|
|
struct vk_descriptor_pool *head;
|
|
|
|
struct vk_descriptor_pool *current;
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
VkDescriptorPoolSize sizes[VULKAN_MAX_DESCRIPTOR_POOL_SIZES];
|
|
|
|
VkDescriptorSetLayout set_layout;
|
|
|
|
unsigned num_sizes;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_per_frame
|
|
|
|
{
|
|
|
|
struct vk_image backbuffer;
|
|
|
|
struct vk_texture texture;
|
2016-02-21 11:33:16 +00:00
|
|
|
struct vk_texture texture_optimal;
|
2016-02-16 19:24:00 +00:00
|
|
|
struct vk_buffer_chain vbo;
|
|
|
|
struct vk_buffer_chain ubo;
|
|
|
|
struct vk_descriptor_manager descriptor_manager;
|
|
|
|
|
|
|
|
VkCommandPool cmd_pool;
|
|
|
|
VkCommandBuffer cmd;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_draw_quad
|
|
|
|
{
|
|
|
|
VkPipeline pipeline;
|
|
|
|
struct vk_texture *texture;
|
|
|
|
VkSampler sampler;
|
|
|
|
const math_matrix_4x4 *mvp;
|
|
|
|
struct vk_color color;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vk_draw_triangles
|
|
|
|
{
|
|
|
|
VkPipeline pipeline;
|
|
|
|
struct vk_texture *texture;
|
|
|
|
VkSampler sampler;
|
|
|
|
const math_matrix_4x4 *mvp;
|
|
|
|
|
|
|
|
const struct vk_buffer_range *vbo;
|
|
|
|
unsigned vertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct vk
|
|
|
|
{
|
|
|
|
vulkan_context_t *context;
|
|
|
|
video_info_t video;
|
|
|
|
unsigned full_x, full_y;
|
|
|
|
|
|
|
|
unsigned tex_w, tex_h;
|
|
|
|
VkFormat tex_fmt;
|
|
|
|
bool vsync;
|
|
|
|
bool keep_aspect;
|
|
|
|
bool fullscreen;
|
|
|
|
bool quitting;
|
|
|
|
bool should_resize;
|
|
|
|
unsigned vp_out_width, vp_out_height;
|
|
|
|
|
|
|
|
unsigned rotation;
|
|
|
|
math_matrix_4x4 mvp, mvp_no_rot;
|
|
|
|
struct video_viewport vp;
|
|
|
|
VkViewport vk_vp;
|
|
|
|
|
|
|
|
VkRenderPass render_pass;
|
|
|
|
struct vk_per_frame swapchain[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
|
|
|
unsigned num_swapchain_images;
|
|
|
|
|
2016-02-19 13:38:15 +00:00
|
|
|
/* Currently active command buffer. */
|
|
|
|
VkCommandBuffer cmd;
|
|
|
|
/* Staging pool for doing buffer transfers on GPU. */
|
|
|
|
VkCommandPool staging_pool;
|
2016-02-16 19:24:00 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct vk_texture staging[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
|
|
|
struct scaler_ctx scaler;
|
|
|
|
bool pending;
|
|
|
|
bool streamed;
|
|
|
|
} readback;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct vk_texture *images;
|
|
|
|
struct vk_vertex *vertex;
|
|
|
|
unsigned count;
|
|
|
|
bool enable;
|
|
|
|
bool full_screen;
|
|
|
|
} overlay;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
VkPipeline alpha_blend;
|
2016-02-21 12:52:30 +00:00
|
|
|
VkPipeline font;
|
2016-02-16 19:24:00 +00:00
|
|
|
VkDescriptorSetLayout set_layout;
|
|
|
|
VkPipelineLayout layout;
|
|
|
|
VkPipelineCache cache;
|
|
|
|
} pipelines;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
bool blend;
|
|
|
|
VkPipeline pipelines[4];
|
|
|
|
struct vk_texture blank_texture;
|
|
|
|
} display;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct vk_texture textures[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
2016-02-21 11:33:16 +00:00
|
|
|
struct vk_texture textures_optimal[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
|
|
|
bool dirty[VULKAN_MAX_SWAPCHAIN_IMAGES];
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
float alpha;
|
|
|
|
unsigned last_index;
|
|
|
|
bool enable;
|
|
|
|
bool full_screen;
|
|
|
|
} menu;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
VkSampler linear;
|
|
|
|
VkSampler nearest;
|
|
|
|
} samplers;
|
|
|
|
|
|
|
|
unsigned last_valid_index;
|
|
|
|
|
|
|
|
struct vk_per_frame *chain;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct retro_hw_render_interface_vulkan iface;
|
|
|
|
const struct retro_vulkan_image *image;
|
|
|
|
const VkSemaphore *semaphores;
|
|
|
|
uint32_t num_semaphores;
|
|
|
|
|
|
|
|
VkPipelineStageFlags *wait_dst_stages;
|
|
|
|
|
|
|
|
VkCommandBuffer *cmd;
|
|
|
|
uint32_t num_cmd;
|
|
|
|
unsigned capacity_cmd;
|
|
|
|
|
|
|
|
unsigned last_width;
|
|
|
|
unsigned last_height;
|
|
|
|
|
|
|
|
bool enable;
|
|
|
|
} hw;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
VkPipeline pipeline;
|
|
|
|
VkImageView view;
|
|
|
|
VkSampler sampler;
|
2016-02-18 17:36:07 +00:00
|
|
|
math_matrix_4x4 mvp;
|
2016-02-16 19:24:00 +00:00
|
|
|
uint64_t dirty;
|
|
|
|
} tracker;
|
|
|
|
|
|
|
|
vulkan_filter_chain_t *filter_chain;
|
|
|
|
} vk_t;
|
|
|
|
|
2016-02-19 13:38:15 +00:00
|
|
|
uint32_t vulkan_find_memory_type(
|
|
|
|
const VkPhysicalDeviceMemoryProperties *mem_props,
|
2016-02-16 19:24:00 +00:00
|
|
|
uint32_t device_reqs, uint32_t host_reqs);
|
|
|
|
|
2016-02-19 13:38:15 +00:00
|
|
|
uint32_t vulkan_find_memory_type_fallback(
|
|
|
|
const VkPhysicalDeviceMemoryProperties *mem_props,
|
2016-02-20 11:04:53 +00:00
|
|
|
uint32_t device_reqs, uint32_t host_reqs_first,
|
|
|
|
uint32_t host_reqs_second);
|
2016-02-16 19:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct vk_texture vulkan_create_texture(vk_t *vk,
|
|
|
|
struct vk_texture *old,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
VkFormat format,
|
|
|
|
const void *initial, const VkComponentMapping *swizzle,
|
|
|
|
enum vk_texture_type type);
|
|
|
|
|
|
|
|
void vulkan_transition_texture(vk_t *vk, struct vk_texture *texture);
|
|
|
|
|
2016-02-29 18:03:18 +00:00
|
|
|
void vulkan_map_persistent_texture(
|
|
|
|
struct vulkan_context_fp *vkcfp,
|
|
|
|
VkDevice device,
|
|
|
|
struct vk_texture *texture);
|
|
|
|
|
|
|
|
void vulkan_destroy_texture(
|
|
|
|
struct vulkan_context_fp *vkcfp,
|
|
|
|
VkDevice device,
|
|
|
|
struct vk_texture *tex);
|
2016-02-16 19:24:00 +00:00
|
|
|
|
2016-02-21 11:33:16 +00:00
|
|
|
void vulkan_copy_staging_to_dynamic(vk_t *vk, VkCommandBuffer cmd,
|
|
|
|
struct vk_texture *dynamic,
|
|
|
|
struct vk_texture *staging);
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
/* VBO will be written to here. */
|
|
|
|
void vulkan_draw_quad(vk_t *vk, const struct vk_draw_quad *quad);
|
|
|
|
|
|
|
|
/* The VBO needs to be written to before calling this.
|
|
|
|
* Use vulkan_buffer_chain_alloc.
|
|
|
|
*/
|
|
|
|
void vulkan_draw_triangles(vk_t *vk, const struct vk_draw_triangles *call);
|
|
|
|
|
2016-02-21 09:11:35 +00:00
|
|
|
void vulkan_image_layout_transition(vk_t *vk,
|
|
|
|
VkCommandBuffer cmd, VkImage image,
|
2016-02-16 19:24:00 +00:00
|
|
|
VkImageLayout old_layout, VkImageLayout new_layout,
|
|
|
|
VkAccessFlags srcAccess, VkAccessFlags dstAccess,
|
|
|
|
VkPipelineStageFlags srcStages, VkPipelineStageFlags dstStages);
|
|
|
|
|
2016-02-19 13:38:15 +00:00
|
|
|
static INLINE unsigned vulkan_format_to_bpp(VkFormat format)
|
2016-02-16 19:24:00 +00:00
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case VK_FORMAT_B8G8R8A8_UNORM:
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
|
|
|
|
case VK_FORMAT_R5G6B5_UNORM_PACK16:
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case VK_FORMAT_R8_UNORM:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
RARCH_ERR("[Vulkan]: Unknown format.\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-19 13:38:15 +00:00
|
|
|
static INLINE void vulkan_write_quad_vbo(struct vk_vertex *pv,
|
2016-02-16 19:24:00 +00:00
|
|
|
float x, float y, float width, float height,
|
|
|
|
float tex_x, float tex_y, float tex_width, float tex_height,
|
|
|
|
const struct vk_color *color)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
static const float strip[2 * 6] = {
|
|
|
|
0.0f, 0.0f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
2016-02-21 09:11:35 +00:00
|
|
|
pv[i].x = x + strip[2 * i + 0] * width;
|
|
|
|
pv[i].y = y + strip[2 * i + 1] * height;
|
2016-02-16 19:24:00 +00:00
|
|
|
pv[i].tex_x = tex_x + strip[2 * i + 0] * tex_width;
|
|
|
|
pv[i].tex_y = tex_y + strip[2 * i + 1] * tex_height;
|
|
|
|
pv[i].color = *color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-29 18:20:42 +00:00
|
|
|
struct vk_buffer vulkan_create_buffer(
|
|
|
|
struct vulkan_context_fp *vkcfp,
|
|
|
|
const struct vulkan_context *context,
|
2016-02-16 19:24:00 +00:00
|
|
|
size_t size, VkBufferUsageFlags usage);
|
2016-02-29 18:03:18 +00:00
|
|
|
|
|
|
|
void vulkan_destroy_buffer(
|
|
|
|
struct vulkan_context_fp *vkcfp,
|
|
|
|
VkDevice device,
|
|
|
|
struct vk_buffer *buffer);
|
2016-02-16 19:24:00 +00:00
|
|
|
|
2016-02-29 17:40:30 +00:00
|
|
|
VkDescriptorSet vulkan_descriptor_manager_alloc(
|
|
|
|
struct vulkan_context_fp *vkcfp,
|
|
|
|
VkDevice device,
|
2016-02-19 13:38:15 +00:00
|
|
|
struct vk_descriptor_manager *manager);
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
void vulkan_descriptor_manager_restart(struct vk_descriptor_manager *manager);
|
2016-02-19 13:38:15 +00:00
|
|
|
|
2016-02-29 17:40:30 +00:00
|
|
|
struct vk_descriptor_manager vulkan_create_descriptor_manager(
|
|
|
|
struct vulkan_context_fp *vkcfp,
|
|
|
|
VkDevice device,
|
2016-02-16 19:24:00 +00:00
|
|
|
const VkDescriptorPoolSize *sizes, unsigned num_sizes,
|
|
|
|
VkDescriptorSetLayout set_layout);
|
|
|
|
void vulkan_destroy_descriptor_manager(VkDevice device,
|
|
|
|
struct vk_descriptor_manager *manager);
|
2016-02-19 13:38:15 +00:00
|
|
|
|
|
|
|
bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
|
|
|
|
enum vulkan_wsi_type type);
|
|
|
|
|
|
|
|
void vulkan_context_destroy(gfx_ctx_vulkan_data_t *vk,
|
|
|
|
bool destroy_surface);
|
|
|
|
|
|
|
|
bool vulkan_surface_create(gfx_ctx_vulkan_data_t *vk,
|
|
|
|
enum vulkan_wsi_type type,
|
|
|
|
void *display, void *surface,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
unsigned swap_interval);
|
|
|
|
|
|
|
|
void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index);
|
|
|
|
|
|
|
|
void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk);
|
|
|
|
|
|
|
|
bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
unsigned swap_interval);
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
#endif
|
|
|
|
|