Merge pull request #2775 from Themaister/master

Vulkan: Various fixes and cleanups
This commit is contained in:
Twinaphex 2016-03-06 12:38:43 +01:00
commit 787924fc8f
6 changed files with 406 additions and 227 deletions

View File

@ -756,7 +756,7 @@ ifeq ($(HAVE_VULKAN), 1)
-Ideps/glslang/glslang/SPIRV \
-Ideps/glslang
CXXFLAGS += -Wno-switch -Wno-sign-compare -fno-strict-aliasing -Wno-maybe-uninitialized -I./gfx/include/vulkan
CXXFLAGS += -Wno-switch -Wno-sign-compare -fno-strict-aliasing -Wno-maybe-uninitialized -Wno-reorder -I./gfx/include/vulkan
CFLAGS += -I./gfx/include/vulkan
GLSLANG_OBJ := $(GLSLANG_SOURCES:.cpp=.o)

View File

@ -32,28 +32,34 @@ static dylib_t vulkan_library;
static VkInstance cached_instance;
static VkDevice cached_device;
#define VKSYM(vk, entrypoint) do { \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) dylib_proc(vulkan_library, "vk"#entrypoint);\
if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetInstanceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \
} \
#define VKSYM(vk, entrypoint) do { \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) dylib_proc(vulkan_library, "vk"#entrypoint); \
if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("dylib_proc failed to find vk%s\n", #entrypoint); \
return false; \
} \
} while(0)
#define VK_GET_INSTANCE_PROC_ADDR(vk, inst, entrypoint) do { \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) vkcfp.vkGetInstanceProcAddr(inst, "vk"#entrypoint); \
if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetInstanceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \
} \
#define VK_GET_INSTANCE_PROC_ADDR(entrypoint) do { \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) vkcfp.vkGetInstanceProcAddr(vk->context.instance, \
"vk"#entrypoint); \
if (vkcfp.vk##entrypoint == NULL) \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) dylib_proc(vulkan_library, "vk"#entrypoint); \
if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetInstanceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \
} \
} while(0)
#define VK_GET_DEVICE_PROC_ADDR(vk, dev, entrypoint) do { \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) vkcfp.vkGetDeviceProcAddr(dev, "vk" #entrypoint); \
if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetDeviceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \
} \
#define VK_GET_DEVICE_PROC_ADDR(entrypoint) do { \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) vkcfp.vkGetDeviceProcAddr(vk->context.device, \
"vk" #entrypoint); \
if (vkcfp.vk##entrypoint == NULL) \
vkcfp.vk##entrypoint = (PFN_vk##entrypoint) dylib_proc(vulkan_library, "vk"#entrypoint); \
if (vkcfp.vk##entrypoint == NULL) { \
RARCH_ERR("vkGetDeviceProcAddr failed to find vk%s\n", #entrypoint); \
return false; \
} \
} while(0)
uint32_t vulkan_find_memory_type(
@ -1006,11 +1012,174 @@ void vulkan_buffer_chain_free(
memset(chain, 0, sizeof(*chain));
}
static bool vulkan_load_instance_symbols(gfx_ctx_vulkan_data_t *vk)
{
VK_GET_INSTANCE_PROC_ADDR(GetDeviceProcAddr);
VK_GET_INSTANCE_PROC_ADDR(DestroyInstance);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceFormatProperties);
VK_GET_INSTANCE_PROC_ADDR(EnumeratePhysicalDevices);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceProperties);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceMemoryProperties);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceQueueFamilyProperties);
VK_GET_INSTANCE_PROC_ADDR(CreateDevice);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceSurfaceSupportKHR);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceSurfaceCapabilitiesKHR);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceSurfaceFormatsKHR);
VK_GET_INSTANCE_PROC_ADDR(GetPhysicalDeviceSurfacePresentModesKHR);
VK_GET_INSTANCE_PROC_ADDR(DestroySurfaceKHR);
return true;
}
static bool vulkan_load_device_symbols(gfx_ctx_vulkan_data_t *vk)
{
/* Memory */
VK_GET_DEVICE_PROC_ADDR(AllocateMemory);
VK_GET_DEVICE_PROC_ADDR(FreeMemory);
/* Device destruction */
VK_GET_DEVICE_PROC_ADDR(DestroyDevice);
/* Waiting */
VK_GET_DEVICE_PROC_ADDR(DeviceWaitIdle);
/* Queues */
VK_GET_DEVICE_PROC_ADDR(GetDeviceQueue);
VK_GET_DEVICE_PROC_ADDR(QueueWaitIdle);
VK_GET_DEVICE_PROC_ADDR(QueueSubmit);
/* Semaphores */
VK_GET_DEVICE_PROC_ADDR(CreateSemaphore);
VK_GET_DEVICE_PROC_ADDR(DestroySemaphore);
/* Buffers */
VK_GET_DEVICE_PROC_ADDR(CreateBuffer);
VK_GET_DEVICE_PROC_ADDR(DestroyBuffer);
/* Fences */
VK_GET_DEVICE_PROC_ADDR(CreateFence);
VK_GET_DEVICE_PROC_ADDR(DestroyFence);
VK_GET_DEVICE_PROC_ADDR(ResetFences);
VK_GET_DEVICE_PROC_ADDR(WaitForFences);
/* Images */
VK_GET_DEVICE_PROC_ADDR(CreateImage);
VK_GET_DEVICE_PROC_ADDR(DestroyImage);
VK_GET_DEVICE_PROC_ADDR(GetImageSubresourceLayout);
/* Images (Resource Memory Association) */
VK_GET_DEVICE_PROC_ADDR(GetBufferMemoryRequirements);
VK_GET_DEVICE_PROC_ADDR(BindBufferMemory);
VK_GET_DEVICE_PROC_ADDR(BindImageMemory);
/* Image Views */
VK_GET_DEVICE_PROC_ADDR(CreateImageView);
VK_GET_DEVICE_PROC_ADDR(DestroyImageView);
/* Resource Memory Associations */
VK_GET_DEVICE_PROC_ADDR(GetImageMemoryRequirements);
/* Descriptor pools */
VK_GET_DEVICE_PROC_ADDR(CreateDescriptorPool);
VK_GET_DEVICE_PROC_ADDR(DestroyDescriptorPool);
/* Descriptor sets */
VK_GET_DEVICE_PROC_ADDR(AllocateDescriptorSets);
VK_GET_DEVICE_PROC_ADDR(FreeDescriptorSets);
VK_GET_DEVICE_PROC_ADDR(UpdateDescriptorSets);
/* Descriptor Set Layout */
VK_GET_DEVICE_PROC_ADDR(CreateDescriptorSetLayout);
VK_GET_DEVICE_PROC_ADDR(DestroyDescriptorSetLayout);
/* Framebuffers */
VK_GET_DEVICE_PROC_ADDR(CreateFramebuffer);
VK_GET_DEVICE_PROC_ADDR(DestroyFramebuffer);
VK_GET_DEVICE_PROC_ADDR(AllocateCommandBuffers);
VK_GET_DEVICE_PROC_ADDR(FreeCommandBuffers);
/* Memory allocation */
VK_GET_DEVICE_PROC_ADDR(MapMemory);
VK_GET_DEVICE_PROC_ADDR(UnmapMemory);
/* Render Passes */
VK_GET_DEVICE_PROC_ADDR(CreateRenderPass);
VK_GET_DEVICE_PROC_ADDR(DestroyRenderPass);
/* Pipelines */
VK_GET_DEVICE_PROC_ADDR(DestroyPipeline);
VK_GET_DEVICE_PROC_ADDR(CreateGraphicsPipelines);
/* Shaders */
VK_GET_DEVICE_PROC_ADDR(CreateShaderModule);
VK_GET_DEVICE_PROC_ADDR(DestroyShaderModule);
/* Pipeline Layouts */
VK_GET_DEVICE_PROC_ADDR(CreatePipelineLayout);
VK_GET_DEVICE_PROC_ADDR(DestroyPipelineLayout);
/* Pipeline Cache */
VK_GET_DEVICE_PROC_ADDR(CreatePipelineCache);
VK_GET_DEVICE_PROC_ADDR(DestroyPipelineCache);
/* Command buffers */
VK_GET_DEVICE_PROC_ADDR(CreateCommandPool);
VK_GET_DEVICE_PROC_ADDR(DestroyCommandPool);
VK_GET_DEVICE_PROC_ADDR(BeginCommandBuffer);
VK_GET_DEVICE_PROC_ADDR(ResetCommandBuffer);
VK_GET_DEVICE_PROC_ADDR(EndCommandBuffer);
/* Image commands */
VK_GET_DEVICE_PROC_ADDR(CmdCopyImage);
/* Vertex input descriptions */
VK_GET_DEVICE_PROC_ADDR(CmdBindVertexBuffers);
/* Descriptor Set commands */
VK_GET_DEVICE_PROC_ADDR(CmdBindDescriptorSets);
/* Fragment operations */
VK_GET_DEVICE_PROC_ADDR(CmdSetScissor);
/* Render Pass commands */
VK_GET_DEVICE_PROC_ADDR(CmdBeginRenderPass);
VK_GET_DEVICE_PROC_ADDR(CmdEndRenderPass);
/* Samplers */
VK_GET_DEVICE_PROC_ADDR(CreateSampler);
VK_GET_DEVICE_PROC_ADDR(DestroySampler);
/* Fixed-function vertex postprocessing */
VK_GET_DEVICE_PROC_ADDR(CmdSetViewport);
/* Clear commands */
VK_GET_DEVICE_PROC_ADDR(CmdClearAttachments);
/* Pipeline */
VK_GET_DEVICE_PROC_ADDR(CmdBindPipeline);
/* Pipeline Barriers */
VK_GET_DEVICE_PROC_ADDR(CmdPipelineBarrier);
/* Drawing commands */
VK_GET_DEVICE_PROC_ADDR(CmdDraw);
/* Swapchain */
VK_GET_DEVICE_PROC_ADDR(CreateSwapchainKHR);
VK_GET_DEVICE_PROC_ADDR(DestroySwapchainKHR);
VK_GET_DEVICE_PROC_ADDR(GetSwapchainImagesKHR);
VK_GET_DEVICE_PROC_ADDR(AcquireNextImageKHR);
VK_GET_DEVICE_PROC_ADDR(QueuePresentKHR);
return true;
}
bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
enum vulkan_wsi_type type)
{
unsigned i;
uint32_t queue_count;
VkResult res;
VkQueueFamilyProperties queue_properties[32];
VkInstanceCreateInfo info = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
VkApplicationInfo app = { VK_STRUCTURE_TYPE_APPLICATION_INFO };
@ -1065,12 +1234,7 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
RARCH_LOG("Vulkan dynamic library loaded.\n");
VKSYM(vk, CreateInstance);
VKSYM(vk, DestroyInstance);
VKSYM(vk, AllocateMemory);
VKSYM(vk, FreeMemory);
VKSYM(vk, GetInstanceProcAddr);
VKSYM(vk, GetDeviceProcAddr);
app.pApplicationName = "RetroArch";
app.applicationVersion = 0;
@ -1086,112 +1250,32 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
{
vk->context.instance = cached_instance;
cached_instance = NULL;
res = VK_SUCCESS;
}
else if (VKFUNC(vkCreateInstance)(&info, NULL, &vk->context.instance) != VK_SUCCESS)
else
{
/* This will be called with a NULL instance, which
* is what we want. */
VK_GET_INSTANCE_PROC_ADDR(CreateInstance);
res = VKFUNC(vkCreateInstance)(&info, NULL, &vk->context.instance);
}
/* Try different API versions if driver has compatible
* but slightly different VK_API_VERSION. */
for (i = 1; i < 4 && res == VK_ERROR_INCOMPATIBLE_DRIVER; i++)
{
app.apiVersion = VK_MAKE_VERSION(1, 0, i);
res = VKFUNC(vkCreateInstance)(&info, NULL, &vk->context.instance);
}
if (res == VK_ERROR_INCOMPATIBLE_DRIVER)
{
RARCH_ERR("Failed to create Vulkan instance.\n");
return false;
}
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance,
GetPhysicalDeviceFormatProperties);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance,
EnumeratePhysicalDevices);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance,
GetPhysicalDeviceProperties);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance,
GetPhysicalDeviceMemoryProperties);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance,
GetPhysicalDeviceQueueFamilyProperties);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateDevice);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyDevice);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DeviceWaitIdle);
/* Queues */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, GetDeviceQueue);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, QueueWaitIdle);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, QueueSubmit);
/* Semaphores */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateSemaphore);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroySemaphore);
/* Buffers */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateBuffer);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyBuffer);
/* Fences */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateFence);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyFence);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, ResetFences);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, WaitForFences);
/* Images */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateImage);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyImage);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, GetImageSubresourceLayout);
/* Images (Resource Memory Association) */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, GetBufferMemoryRequirements);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, BindBufferMemory);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, BindImageMemory);
/* Image Views */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateImageView);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyImageView);
/* Resource Memory Associations */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, GetImageMemoryRequirements);
/* Descriptor pools */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateDescriptorPool);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyDescriptorPool);
/* Descriptor sets */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, AllocateDescriptorSets);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, FreeDescriptorSets);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, UpdateDescriptorSets);
/* Descriptor Set Layout */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateDescriptorSetLayout);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyDescriptorSetLayout);
/* Framebuffers */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateFramebuffer);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyFramebuffer);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, AllocateCommandBuffers);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, FreeCommandBuffers);
/* Memory allocation */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, MapMemory);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, UnmapMemory);
/* Render Passes */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateRenderPass);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyRenderPass);
/* Pipelines */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyPipeline);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateGraphicsPipelines);
/* Shaders */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateShaderModule);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyShaderModule);
/* Pipeline Layouts */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreatePipelineLayout);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyPipelineLayout);
/* Pipeline Cache */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreatePipelineCache);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyPipelineCache);
/* Command buffers */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateCommandPool);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroyCommandPool);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, BeginCommandBuffer);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, ResetCommandBuffer);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, EndCommandBuffer);
if (!vulkan_load_instance_symbols(vk))
return false;
if (VKFUNC(vkEnumeratePhysicalDevices)(vk->context.instance,
&gpu_count, NULL) != VK_SUCCESS)
@ -1269,61 +1353,8 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
NULL, &vk->context.device) != VK_SUCCESS)
return false;
/* Image commands */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdCopyImage);
/* Vertex input descriptions */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdBindVertexBuffers);
/* Descriptor Set commands */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdBindDescriptorSets);
/* Fragment operations */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdSetScissor);
/* Render Pass commands */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdBeginRenderPass);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdEndRenderPass);
/* Samplers */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CreateSampler);
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, DestroySampler);
/* Fixed-function vertex postprocessing */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdSetViewport);
/* Clear commands */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdClearAttachments);
/* Pipeline */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdBindPipeline);
/* Pipeline Barriers */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdPipelineBarrier);
/* Drawing commands */
VK_GET_INSTANCE_PROC_ADDR(vk, vk->context.instance, CmdDraw);
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, GetPhysicalDeviceSurfaceSupportKHR);
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, GetPhysicalDeviceSurfaceCapabilitiesKHR);
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, GetPhysicalDeviceSurfaceFormatsKHR);
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, GetPhysicalDeviceSurfacePresentModesKHR);
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, DestroySurfaceKHR);
VK_GET_DEVICE_PROC_ADDR(vk,
vk->context.device, CreateSwapchainKHR);
VK_GET_DEVICE_PROC_ADDR(vk,
vk->context.device, DestroySwapchainKHR);
VK_GET_DEVICE_PROC_ADDR(vk,
vk->context.device, GetSwapchainImagesKHR);
VK_GET_DEVICE_PROC_ADDR(vk,
vk->context.device, AcquireNextImageKHR);
VK_GET_DEVICE_PROC_ADDR(vk,
vk->context.device, QueuePresentKHR);
if (!vulkan_load_device_symbols(vk))
return false;
VKFUNC(vkGetDeviceQueue)(vk->context.device,
vk->context.graphics_queue_index, 0, &vk->context.queue);
@ -1332,38 +1363,32 @@ bool vulkan_context_init(gfx_ctx_vulkan_data_t *vk,
{
case VULKAN_WSI_WAYLAND:
#ifdef HAVE_WAYLAND
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, CreateWaylandSurfaceKHR);
VK_GET_INSTANCE_PROC_ADDR(CreateWaylandSurfaceKHR);
#endif
break;
case VULKAN_WSI_ANDROID:
#ifdef ANDROID
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, CreateAndroidSurfaceKHR);
VK_GET_INSTANCE_PROC_ADDR(CreateAndroidSurfaceKHR);
#endif
break;
case VULKAN_WSI_WIN32:
#ifdef _WIN32
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, CreateWin32SurfaceKHR);
VK_GET_INSTANCE_PROC_ADDR(CreateWin32SurfaceKHR);
#endif
break;
case VULKAN_WSI_XLIB:
#ifdef HAVE_XLIB
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, CreateXlibSurfaceKHR);
VK_GET_INSTANCE_PROC_ADDR(CreateXlibSurfaceKHR);
#endif
break;
case VULKAN_WSI_XCB:
#ifdef HAVE_XCB
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, CreateXcbSurfaceKHR);
VK_GET_INSTANCE_PROC_ADDR(CreateXcbSurfaceKHR);
#endif
break;
case VULKAN_WSI_MIR:
#ifdef HAVE_MIR
VK_GET_INSTANCE_PROC_ADDR(vk,
vk->context.instance, CreateMirSurfaceKHR);
VK_GET_INSTANCE_PROC_ADDR(CreateMirSurfaceKHR);
#endif
break;
case VULKAN_WSI_NONE:

View File

@ -73,7 +73,8 @@ static const gfx_ctx_driver_t *vulkan_get_context(vk_t *vk)
static void vulkan_init_render_pass(
vk_t *vk)
{
VkRenderPassCreateInfo rp_info;
VkRenderPassCreateInfo rp_info = {
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO };
VkAttachmentDescription attachment = {0};
VkSubpassDescription subpass = {0};
VkAttachmentReference color_ref = { 0,
@ -928,6 +929,8 @@ static void *vulkan_init(const video_info_t *video,
gfx_ctx_ctl(GFX_CTL_GET_VIDEO_SIZE, &mode);
vk->full_x = mode.width;
vk->full_y = mode.height;
mode.width = 0;
mode.height = 0;
RARCH_LOG("Detecting screen resolution %ux%u.\n", vk->full_x, vk->full_y);
interval = video->vsync ? settings->video.swap_interval : 0;
@ -942,6 +945,8 @@ static void *vulkan_init(const video_info_t *video,
win_height = vk->full_y;
}
mode.width = win_width;
mode.height = win_height;
mode.fullscreen = video->fullscreen;
if (!gfx_ctx_ctl(GFX_CTL_SET_VIDEO_MODE, &mode))
goto error;
@ -1355,9 +1360,13 @@ static bool vulkan_frame(void *data, const void *frame,
VkClearValue clear_value;
vk_t *vk = (vk_t*)data;
static struct retro_perf_counter frame_run = {0};
static struct retro_perf_counter begin_cmd = {0};
static struct retro_perf_counter build_cmd = {0};
static struct retro_perf_counter end_cmd = {0};
static struct retro_perf_counter copy_frame = {0};
static struct retro_perf_counter swapbuffers = {0};
static struct retro_perf_counter queue_submit = {0};
VkCommandBufferBeginInfo begin_info = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
VkRenderPassBeginInfo rp_info = {
@ -1371,6 +1380,9 @@ static bool vulkan_frame(void *data, const void *frame,
rarch_perf_init(&copy_frame, "copy_frame");
rarch_perf_init(&swapbuffers, "swapbuffers");
rarch_perf_init(&queue_submit, "queue_submit");
rarch_perf_init(&begin_cmd, "begin_command");
rarch_perf_init(&build_cmd, "build_command");
rarch_perf_init(&end_cmd, "end_command");
retro_perf_start(&frame_run);
video_driver_get_size(&width, &height);
@ -1383,12 +1395,15 @@ static bool vulkan_frame(void *data, const void *frame,
vulkan_buffer_chain_discard(&chain->vbo);
vulkan_buffer_chain_discard(&chain->ubo);
retro_perf_start(&begin_cmd);
/* Start recording the command buffer. */
vk->cmd = chain->cmd;
begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
VKFUNC(vkResetCommandBuffer)(vk->cmd, 0);
VKFUNC(vkBeginCommandBuffer)(vk->cmd, &begin_info);
retro_perf_stop(&begin_cmd);
memset(&vk->tracker, 0, sizeof(vk->tracker));
/* Upload texture */
@ -1446,6 +1461,7 @@ static bool vulkan_frame(void *data, const void *frame,
/* Notify filter chain about the new sync index. */
vulkan_filter_chain_notify_sync_index(vk->filter_chain, frame_index);
retro_perf_start(&build_cmd);
/* Render offscreen filter chain passes. */
{
/* Set the source texture in the filter chain */
@ -1498,7 +1514,6 @@ static bool vulkan_frame(void *data, const void *frame,
vulkan_filter_chain_build_offscreen_passes(
vk->filter_chain, vk->cmd, &vk->vk_vp);
/* Render to backbuffer. */
clear_value.color.float32[0] = 0.0f;
clear_value.color.float32[1] = 0.0f;
@ -1568,6 +1583,7 @@ static bool vulkan_frame(void *data, const void *frame,
if (vk->overlay.enable)
vulkan_render_overlay(vk);
#endif
retro_perf_stop(&build_cmd);
/* End the render pass. We're done rendering to backbuffer now. */
VKFUNC(vkCmdEndRenderPass)(vk->cmd);
@ -1616,7 +1632,9 @@ static bool vulkan_frame(void *data, const void *frame,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
}
retro_perf_start(&end_cmd);
VKFUNC(vkEndCommandBuffer)(vk->cmd);
retro_perf_stop(&end_cmd);
/* Submit command buffers to GPU. */

View File

@ -1,3 +1,32 @@
//
// File: vk_icd.h
//
/*
* Copyright (c) 2015-2016 The Khronos Group Inc.
* Copyright (c) 2015-2016 Valve Corporation
* Copyright (c) 2015-2016 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and/or associated documentation files (the "Materials"), to
* deal in the Materials without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Materials, and to permit persons to whom the Materials are
* furnished to do so, subject to the following conditions:
*
* The above copyright notice(s) and this permission notice shall be included in
* all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
* USE OR OTHER DEALINGS IN THE MATERIALS.
*
*/
#ifndef VKICD_H
#define VKICD_H
@ -9,20 +38,20 @@
* The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro.
*/
#define ICD_LOADER_MAGIC 0x01CDC0DE
#define ICD_LOADER_MAGIC 0x01CDC0DE
typedef union _VK_LOADER_DATA {
uintptr_t loaderMagic;
void *loaderData;
uintptr_t loaderMagic;
void *loaderData;
} VK_LOADER_DATA;
static inline void set_loader_magic_value(void* pNewObject) {
VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *) pNewObject;
static inline void set_loader_magic_value(void *pNewObject) {
VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
loader_info->loaderMagic = ICD_LOADER_MAGIC;
}
static inline bool valid_loader_magic_value(void* pNewObject) {
const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *) pNewObject;
static inline bool valid_loader_magic_value(void *pNewObject) {
const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC;
}
@ -39,46 +68,46 @@ typedef enum _VkIcdWsiPlatform {
} VkIcdWsiPlatform;
typedef struct _VkIcdSurfaceBase {
VkIcdWsiPlatform platform;
VkIcdWsiPlatform platform;
} VkIcdSurfaceBase;
#ifdef VK_USE_PLATFORM_MIR_KHR
typedef struct _VkIcdSurfaceMir {
VkIcdSurfaceBase base;
MirConnection* connection;
MirSurface* mirSurface;
VkIcdSurfaceBase base;
MirConnection *connection;
MirSurface *mirSurface;
} VkIcdSurfaceMir;
#endif // VK_USE_PLATFORM_MIR_KHR
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
typedef struct _VkIcdSurfaceWayland {
VkIcdSurfaceBase base;
struct wl_display* display;
struct wl_surface* surface;
VkIcdSurfaceBase base;
struct wl_display *display;
struct wl_surface *surface;
} VkIcdSurfaceWayland;
#endif // VK_USE_PLATFORM_WAYLAND_KHR
#ifdef VK_USE_PLATFORM_WIN32_KHR
typedef struct _VkIcdSurfaceWin32 {
VkIcdSurfaceBase base;
HINSTANCE hinstance;
HWND hwnd;
VkIcdSurfaceBase base;
HINSTANCE hinstance;
HWND hwnd;
} VkIcdSurfaceWin32;
#endif // VK_USE_PLATFORM_WIN32_KHR
#ifdef VK_USE_PLATFORM_XCB_KHR
typedef struct _VkIcdSurfaceXcb {
VkIcdSurfaceBase base;
xcb_connection_t* connection;
xcb_window_t window;
VkIcdSurfaceBase base;
xcb_connection_t *connection;
xcb_window_t window;
} VkIcdSurfaceXcb;
#endif // VK_USE_PLATFORM_XCB_KHR
#ifdef VK_USE_PLATFORM_XLIB_KHR
typedef struct _VkIcdSurfaceXlib {
VkIcdSurfaceBase base;
Display* dpy;
Window window;
VkIcdSurfaceBase base;
Display *dpy;
Window window;
} VkIcdSurfaceXlib;
#endif // VK_USE_PLATFORM_XLIB_KHR

View File

@ -25,8 +25,8 @@
*/
#ifndef __VK_PLATFORM_H__
#define __VK_PLATFORM_H__
#ifndef VK_PLATFORM_H_
#define VK_PLATFORM_H_
#ifdef __cplusplus
extern "C"
@ -124,4 +124,4 @@ extern "C"
#include <xcb/xcb.h>
#endif
#endif // __VK_PLATFORM_H__
#endif

View File

@ -1,12 +1,12 @@
#ifndef __vulkan_h_
#define __vulkan_h_ 1
#ifndef VULKAN_H_
#define VULKAN_H_ 1
#ifdef __cplusplus
extern "C" {
#endif
/*
** Copyright (c) 2015 The Khronos Group Inc.
** Copyright (c) 2015-2016 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
@ -41,7 +41,7 @@ extern "C" {
(((major) << 22) | ((minor) << 12) | (patch))
// Vulkan API version supported by this file
#define VK_API_VERSION VK_MAKE_VERSION(1, 0, 3)
#define VK_API_VERSION VK_MAKE_VERSION(1, 0, 4)
#define VK_VERSION_MAJOR(version) ((uint32_t)(version) >> 22)
#define VK_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3ff)
@ -209,7 +209,7 @@ typedef enum VkStructureType {
VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR = 1000007000,
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR = 1000008000,
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT = 1000011000,
VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT = 1000011000,
VK_STRUCTURE_TYPE_BEGIN_RANGE = VK_STRUCTURE_TYPE_APPLICATION_INFO,
VK_STRUCTURE_TYPE_END_RANGE = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO,
VK_STRUCTURE_TYPE_RANGE_SIZE = (VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO - VK_STRUCTURE_TYPE_APPLICATION_INFO + 1),
@ -701,8 +701,8 @@ typedef enum VkSamplerAddressMode {
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER = 3,
VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE = 4,
VK_SAMPLER_ADDRESS_MODE_BEGIN_RANGE = VK_SAMPLER_ADDRESS_MODE_REPEAT,
VK_SAMPLER_ADDRESS_MODE_END_RANGE = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_RANGE_SIZE = (VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE - VK_SAMPLER_ADDRESS_MODE_REPEAT + 1),
VK_SAMPLER_ADDRESS_MODE_END_RANGE = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
VK_SAMPLER_ADDRESS_MODE_RANGE_SIZE = (VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER - VK_SAMPLER_ADDRESS_MODE_REPEAT + 1),
VK_SAMPLER_ADDRESS_MODE_MAX_ENUM = 0x7FFFFFFF
} VkSamplerAddressMode;
@ -3326,8 +3326,8 @@ typedef enum VkDisplayPlaneAlphaFlagBitsKHR {
VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR = 0x00000004,
VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR = 0x00000008,
} VkDisplayPlaneAlphaFlagBitsKHR;
typedef VkFlags VkDisplayModeCreateFlagsKHR;
typedef VkFlags VkDisplayPlaneAlphaFlagsKHR;
typedef VkFlags VkDisplayModeCreateFlagsKHR;
typedef VkFlags VkDisplaySurfaceCreateFlagsKHR;
typedef struct VkDisplayPropertiesKHR {
@ -3667,6 +3667,113 @@ VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(
#endif
#endif /* VK_USE_PLATFORM_WIN32_KHR */
#define VK_KHR_sampler_mirror_clamp_to_edge 1
#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_SPEC_VERSION 1
#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME "VK_KHR_sampler_mirror_clamp_to_edge"
#define VK_EXT_debug_report 1
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT)
#define VK_EXT_DEBUG_REPORT_SPEC_VERSION 2
#define VK_EXT_DEBUG_REPORT_EXTENSION_NAME "VK_EXT_debug_report"
#define VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT
typedef enum VkDebugReportObjectTypeEXT {
VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT = 0,
VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT = 1,
VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT = 2,
VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT = 3,
VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT = 4,
VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT = 5,
VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT = 6,
VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT = 7,
VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT = 8,
VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT = 9,
VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT = 10,
VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT = 11,
VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT = 12,
VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT = 13,
VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT = 14,
VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT = 15,
VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT = 16,
VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT = 17,
VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT = 18,
VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT = 19,
VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT = 20,
VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT = 21,
VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT = 22,
VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT = 23,
VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT = 24,
VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT = 25,
VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT = 26,
VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT = 27,
VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT = 28,
} VkDebugReportObjectTypeEXT;
typedef enum VkDebugReportErrorEXT {
VK_DEBUG_REPORT_ERROR_NONE_EXT = 0,
VK_DEBUG_REPORT_ERROR_CALLBACK_REF_EXT = 1,
} VkDebugReportErrorEXT;
typedef enum VkDebugReportFlagBitsEXT {
VK_DEBUG_REPORT_INFORMATION_BIT_EXT = 0x00000001,
VK_DEBUG_REPORT_WARNING_BIT_EXT = 0x00000002,
VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT = 0x00000004,
VK_DEBUG_REPORT_ERROR_BIT_EXT = 0x00000008,
VK_DEBUG_REPORT_DEBUG_BIT_EXT = 0x00000010,
} VkDebugReportFlagBitsEXT;
typedef VkFlags VkDebugReportFlagsEXT;
typedef VkBool32 (VKAPI_PTR *PFN_vkDebugReportCallbackEXT)(
VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objectType,
uint64_t object,
size_t location,
int32_t messageCode,
const char* pLayerPrefix,
const char* pMessage,
void* pUserData);
typedef struct VkDebugReportCallbackCreateInfoEXT {
VkStructureType sType;
const void* pNext;
VkDebugReportFlagsEXT flags;
PFN_vkDebugReportCallbackEXT pfnCallback;
void* pUserData;
} VkDebugReportCallbackCreateInfoEXT;
typedef VkResult (VKAPI_PTR *PFN_vkCreateDebugReportCallbackEXT)(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback);
typedef void (VKAPI_PTR *PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator);
typedef void (VKAPI_PTR *PFN_vkDebugReportMessageEXT)(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage);
#ifndef VK_NO_PROTOTYPES
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
VkInstance instance,
const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkDebugReportCallbackEXT* pCallback);
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
VkInstance instance,
VkDebugReportCallbackEXT callback,
const VkAllocationCallbacks* pAllocator);
VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
VkInstance instance,
VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objectType,
uint64_t object,
size_t location,
int32_t messageCode,
const char* pLayerPrefix,
const char* pMessage);
#endif
#ifdef __cplusplus
}
#endif