vk: Add an initial implementation of the actual Khronos WSI extension

Unfortunately, this is a very large commit and removes the old LunarG WSI
extension.  This is because there are a couple of entrypoints that have the
same name between the two extensions so implementing them both is
impractiacl.

Support is still incomplete, but this is enough to get vkcube up and going
again.
This commit is contained in:
Jason Ekstrand 2015-09-01 18:59:06 -07:00
parent 3d9fbb6575
commit ca3cfbf6f1
7 changed files with 327 additions and 312 deletions

View File

@ -1,212 +0,0 @@
//
// File: vk_wsi_display.h
//
/*
** Copyright (c) 2014 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
** "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 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 __VK_WSI_LUNARG_H__
#define __VK_WSI_LUNARG_H__
#include "vulkan.h"
#define VK_WSI_LUNARG_REVISION 3
#define VK_WSI_LUNARG_EXTENSION_NUMBER 1
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
// This macro defines INT_MAX in enumerations to force compilers to use 32 bits
// to represent them. This may or may not be necessary on some compilers. The
// option to compile it out may allow compilers that warn about missing enumerants
// in switch statements to be silenced.
// Using this macro is not needed for flag bit enums because those aren't used
// as storage type anywhere.
#define VK_MAX_ENUM(Prefix) VK_##Prefix##_MAX_ENUM = 0x7FFFFFFF
// This macro defines the BEGIN_RANGE, END_RANGE, NUM, and MAX_ENUM constants for
// the enumerations.
#define VK_ENUM_RANGE(Prefix, First, Last) \
VK_##Prefix##_BEGIN_RANGE = VK_##Prefix##_##First, \
VK_##Prefix##_END_RANGE = VK_##Prefix##_##Last, \
VK_NUM_##Prefix = (VK_##Prefix##_END_RANGE - VK_##Prefix##_BEGIN_RANGE + 1), \
VK_MAX_ENUM(Prefix)
// This is a helper macro to define the value of flag bit enum values.
#define VK_BIT(bit) (1 << (bit))
// ------------------------------------------------------------------------------------------------
// Objects
VK_DEFINE_HANDLE(VkDisplayWSI)
VK_DEFINE_HANDLE(VkSwapChainWSI)
// ------------------------------------------------------------------------------------------------
// Enumeration constants
#define VK_WSI_LUNARG_ENUM(type,id) ((type)(VK_WSI_LUNARG_EXTENSION_NUMBER * -1000 + (id)))
// Extend VkPhysicalDeviceInfoType enum with extension specific constants
#define VK_PHYSICAL_DEVICE_INFO_TYPE_DISPLAY_PROPERTIES_WSI VK_WSI_LUNARG_ENUM(VkPhysicalDeviceInfoType, 0)
#define VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PRESENT_PROPERTIES_WSI VK_WSI_LUNARG_ENUM(VkPhysicalDeviceInfoType, 1)
// Extend VkStructureType enum with extension specific constants
#define VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI VK_WSI_LUNARG_ENUM(VkStructureType, 0)
#define VK_STRUCTURE_TYPE_PRESENT_INFO_WSI VK_WSI_LUNARG_ENUM(VkStructureType, 1)
// Extend VkImageLayout enum with extension specific constants
#define VK_IMAGE_LAYOUT_PRESENT_SOURCE_WSI VK_WSI_LUNARG_ENUM(VkImageLayout, 0)
// ------------------------------------------------------------------------------------------------
// Enumerations
typedef enum VkDisplayInfoTypeWSI_
{
// Info type for vkGetDisplayInfo()
VK_DISPLAY_INFO_TYPE_FORMAT_PROPERTIES_WSI = 0x00000003, // Return the VkFormat(s) supported for swap chains with the display
VK_ENUM_RANGE(DISPLAY_INFO_TYPE, FORMAT_PROPERTIES_WSI, FORMAT_PROPERTIES_WSI)
} VkDisplayInfoTypeWSI;
typedef enum VkSwapChainInfoTypeWSI_
{
// Info type for vkGetSwapChainInfo()
VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI = 0x00000000, // Return information about the persistent images of the swapchain
VK_ENUM_RANGE(SWAP_CHAIN_INFO_TYPE, PERSISTENT_IMAGES_WSI, PERSISTENT_IMAGES_WSI)
} VkSwapChainInfoTypeWSI;
// ------------------------------------------------------------------------------------------------
// Flags
typedef VkFlags VkSwapModeFlagsWSI;
typedef enum VkSwapModeFlagBitsWSI_
{
VK_SWAP_MODE_FLIP_BIT_WSI = VK_BIT(0),
VK_SWAP_MODE_BLIT_BIT_WSI = VK_BIT(1),
} VkSwapModeFlagBitsWSI;
// ------------------------------------------------------------------------------------------------
// Structures
typedef struct VkDisplayPropertiesWSI_
{
VkDisplayWSI display; // Handle of the display object
VkExtent2D physicalResolution; // Max resolution for CRT?
} VkDisplayPropertiesWSI;
typedef struct VkDisplayFormatPropertiesWSI_
{
VkFormat swapChainFormat; // Format of the images of the swap chain
} VkDisplayFormatPropertiesWSI;
typedef struct VkSwapChainCreateInfoWSI_
{
VkStructureType sType; // Must be VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI
const void* pNext; // Pointer to next structure
// TBD: It is not yet clear what the use will be for the following two
// values. It seems to be needed for more-global window-system handles
// (e.g. X11 display). If not needed for the SDK, we will drop it from
// this extension, and from a future version of this header.
const void* pNativeWindowSystemHandle; // Pointer to native window system handle
const void* pNativeWindowHandle; // Pointer to native window handle
uint32_t displayCount; // Number of displays the swap chain is created for
const VkDisplayWSI* pDisplays; // displayCount number of display objects the swap chain is created for
uint32_t imageCount; // Number of images in the swap chain
VkFormat imageFormat; // Format of the images of the swap chain
VkExtent2D imageExtent; // Width and height of the images of the swap chain
uint32_t imageArraySize; // Number of layers of the images of the swap chain (needed for multi-view rendering)
VkFlags imageUsageFlags; // Usage flags for the images of the swap chain (see VkImageUsageFlags)
VkFlags swapModeFlags; // Allowed swap modes (see VkSwapModeFlagsWSI)
} VkSwapChainCreateInfoWSI;
typedef struct VkSwapChainImageInfoWSI_
{
VkImage image; // Persistent swap chain image handle
VkDeviceMemory memory; // Persistent swap chain image's memory handle
} VkSwapChainImageInfoWSI;
typedef struct VkPhysicalDeviceQueuePresentPropertiesWSI_
{
VkBool32 supportsPresent; // Tells whether the queue supports presenting
} VkPhysicalDeviceQueuePresentPropertiesWSI;
typedef struct VkPresentInfoWSI_
{
VkStructureType sType; // Must be VK_STRUCTURE_TYPE_PRESENT_INFO_WSI
const void* pNext; // Pointer to next structure
VkImage image; // Image to present
uint32_t flipInterval; // Flip interval
} VkPresentInfoWSI;
// ------------------------------------------------------------------------------------------------
// Function types
typedef VkResult (VKAPI *PFN_vkGetDisplayInfoWSI)(VkDisplayWSI display, VkDisplayInfoTypeWSI infoType, size_t* pDataSize, void* pData);
typedef VkResult (VKAPI *PFN_vkCreateSwapChainWSI)(VkDevice device, const VkSwapChainCreateInfoWSI* pCreateInfo, VkSwapChainWSI* pSwapChain);
typedef VkResult (VKAPI *PFN_vkDestroySwapChainWSI)(VkSwapChainWSI swapChain);
typedef VkResult (VKAPI *PFN_vkGetSwapChainInfoWSI)(VkSwapChainWSI swapChain, VkSwapChainInfoTypeWSI infoType, size_t* pDataSize, void* pData);
typedef VkResult (VKAPI *PFN_vkQueuePresentWSI)(VkQueue queue, const VkPresentInfoWSI* pPresentInfo);
// ------------------------------------------------------------------------------------------------
// Function prototypes
#ifdef VK_PROTOTYPES
VkResult VKAPI vkGetDisplayInfoWSI(
VkDisplayWSI display,
VkDisplayInfoTypeWSI infoType,
size_t* pDataSize,
void* pData);
VkResult VKAPI vkCreateSwapChainWSI(
VkDevice device,
const VkSwapChainCreateInfoWSI* pCreateInfo,
VkSwapChainWSI* pSwapChain);
VkResult VKAPI vkDestroySwapChainWSI(
VkSwapChainWSI swapChain);
VkResult VKAPI vkGetSwapChainInfoWSI(
VkSwapChainWSI swapChain,
VkSwapChainInfoTypeWSI infoType,
size_t* pDataSize,
void* pData);
VkResult VKAPI vkQueuePresentWSI(
VkQueue queue,
const VkPresentInfoWSI* pPresentInfo);
#endif // VK_PROTOTYPES
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __VK_WSI_LUNARG_H__

View File

@ -28,7 +28,7 @@ vulkan_include_HEADERS = \
$(top_srcdir)/include/vulkan/vulkan.h \
$(top_srcdir)/include/vulkan/vulkan_intel.h \
$(top_srcdir)/include/vulkan/vk_wsi_swapchain.h \
$(top_srcdir)/include/vulkan/vk_wsi_lunarg.h
$(top_srcdir)/include/vulkan/vk_wsi_device_swapchain.h
lib_LTLIBRARIES = libvulkan.la

View File

@ -637,10 +637,6 @@ static const VkExtensionProperties global_extensions[] = {
.extName = "VK_WSI_swapchain",
.specVersion = 12
},
{
.extName = "VK_WSI_LunarG",
.specVersion = 3
}
};
VkResult anv_GetGlobalExtensionProperties(
@ -662,6 +658,10 @@ VkResult anv_GetGlobalExtensionProperties(
}
static const VkExtensionProperties device_extensions[] = {
{
.extName = "VK_WSI_device_swapchain",
.specVersion = 12
},
};
VkResult anv_GetPhysicalDeviceExtensionProperties(

View File

@ -46,8 +46,8 @@
#define VK_PROTOTYPES
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_intel.h>
#include <vulkan/vk_wsi_lunarg.h>
#include <vulkan/vk_wsi_swapchain.h>
#include <vulkan/vk_wsi_device_swapchain.h>
#include "anv_entrypoints.h"
@ -1060,8 +1060,6 @@ struct anv_image {
struct anv_bo *bo;
VkDeviceSize offset;
struct anv_swap_chain *swap_chain;
/** RENDER_SURFACE_STATE.SurfaceType */
uint8_t surf_type;
@ -1287,7 +1285,6 @@ ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
ANV_DEFINE_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI);
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCmdPool)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view, VkAttachmentView)

View File

@ -21,7 +21,7 @@
* IN THE SOFTWARE.
*/
#include "anv_private.h"
#include "anv_wsi.h"
VkResult
anv_GetPhysicalDeviceSurfaceSupportWSI(
@ -39,3 +39,147 @@ anv_GetPhysicalDeviceSurfaceSupportWSI(
return VK_SUCCESS;
}
VkResult
anv_GetSurfaceInfoWSI(
VkDevice _device,
const VkSurfaceDescriptionWSI* pSurfaceDescription,
VkSurfaceInfoTypeWSI infoType,
size_t* pDataSize,
void* pData)
{
ANV_FROM_HANDLE(anv_device, device, _device);
assert(pSurfaceDescription->sType ==
VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
VkSurfaceDescriptionWindowWSI *window =
(VkSurfaceDescriptionWindowWSI *)pSurfaceDescription;
switch (window->platform) {
case VK_PLATFORM_XCB_WSI:
return anv_x11_get_surface_info(device, window, infoType,
pDataSize, pData);
default:
return vk_error(VK_ERROR_INVALID_VALUE);
}
}
VkResult
anv_CreateSwapChainWSI(
VkDevice _device,
const VkSwapChainCreateInfoWSI* pCreateInfo,
VkSwapChainWSI* pSwapChain)
{
ANV_FROM_HANDLE(anv_device, device, _device);
struct anv_swap_chain *swap_chain;
VkResult result;
assert(pCreateInfo->pSurfaceDescription->sType ==
VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
VkSurfaceDescriptionWindowWSI *window =
(VkSurfaceDescriptionWindowWSI *)pCreateInfo->pSurfaceDescription;
switch (window->platform) {
case VK_PLATFORM_XCB_WSI:
result = anv_x11_create_swap_chain(device, pCreateInfo,
(void *)&swap_chain);
break;
default:
return vk_error(VK_ERROR_INVALID_VALUE);
}
if (result == VK_SUCCESS)
*pSwapChain = anv_swap_chain_to_handle(swap_chain);
return result;
}
VkResult
anv_DestroySwapChainWSI(
VkDevice device,
VkSwapChainWSI swapChain)
{
ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
assert(swap_chain->device == anv_device_from_handle(device));
switch (swap_chain->type) {
case ANV_SWAP_CHAIN_TYPE_X11:
return anv_x11_destroy_swap_chain((void *)swap_chain);
default:
return vk_error(VK_ERROR_INVALID_VALUE);
}
}
VkResult
anv_GetSwapChainInfoWSI(
VkDevice device,
VkSwapChainWSI swapChain,
VkSwapChainInfoTypeWSI infoType,
size_t* pDataSize,
void* pData)
{
ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
assert(swap_chain->device == anv_device_from_handle(device));
switch (swap_chain->type) {
case ANV_SWAP_CHAIN_TYPE_X11:
return anv_x11_get_swap_chain_info((void *)swap_chain,
infoType, pDataSize, pData);
default:
return vk_error(VK_ERROR_INVALID_VALUE);
}
}
VkResult
anv_AcquireNextImageWSI(
VkDevice device,
VkSwapChainWSI swapChain,
uint64_t timeout,
VkSemaphore semaphore,
uint32_t* pImageIndex)
{
ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
assert(swap_chain->device == anv_device_from_handle(device));
switch (swap_chain->type) {
case ANV_SWAP_CHAIN_TYPE_X11:
return anv_x11_acquire_next_image((void *)swap_chain,
timeout, semaphore, pImageIndex);
default:
return vk_error(VK_ERROR_INVALID_VALUE);
}
}
VkResult
anv_QueuePresentWSI(
VkQueue _queue,
VkPresentInfoWSI* pPresentInfo)
{
ANV_FROM_HANDLE(anv_queue, queue, _queue);
VkResult result;
for (uint32_t i = 0; i < pPresentInfo->swapChainCount; i++) {
ANV_FROM_HANDLE(anv_swap_chain, swap_chain, pPresentInfo->swapChains[i]);
assert(swap_chain->device == queue->device);
switch (swap_chain->type) {
case ANV_SWAP_CHAIN_TYPE_X11:
result = anv_x11_queue_present(queue, (void *)swap_chain,
pPresentInfo->imageIndices[i]);
/* TODO: What if one of them returns OUT_OF_DATE? */
if (result != VK_SUCCESS)
return result;
else
continue;
default:
return vk_error(VK_ERROR_INVALID_VALUE);
}
}
return VK_SUCCESS;
}

59
src/vulkan/anv_wsi.h Normal file
View File

@ -0,0 +1,59 @@
/*
* Copyright © 2015 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#pragma once
#include "anv_private.h"
enum anv_swap_chain_type {
ANV_SWAP_CHAIN_TYPE_X11 = 11,
};
struct anv_swap_chain {
enum anv_swap_chain_type type;
struct anv_device * device;
};
struct anv_x11_swap_chain;
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI)
VkResult anv_x11_get_surface_info(struct anv_device *device,
VkSurfaceDescriptionWindowWSI *window,
VkSurfaceInfoTypeWSI infoType,
size_t* pDataSize, void* pData);
VkResult anv_x11_create_swap_chain(struct anv_device *device,
const VkSwapChainCreateInfoWSI *pCreateInfo,
struct anv_x11_swap_chain **swap_chain);
VkResult anv_x11_destroy_swap_chain(struct anv_x11_swap_chain *swap_chain);
VkResult anv_x11_get_swap_chain_info(struct anv_x11_swap_chain *swap_chain,
VkSwapChainInfoTypeWSI infoType,
size_t* pDataSize, void* pData);
VkResult anv_x11_acquire_next_image(struct anv_x11_swap_chain *swap_chain,
uint64_t timeout,
VkSemaphore semaphore,
uint32_t *image_index);
VkResult anv_x11_queue_present(struct anv_queue *queue,
struct anv_x11_swap_chain *swap_chain,
uint32_t image_index);

View File

@ -21,61 +21,86 @@
* IN THE SOFTWARE.
*/
#include "anv_private.h"
#include <xcb/xcb.h>
#include <xcb/dri3.h>
#include <xcb/present.h>
#include "anv_wsi.h"
static const VkFormat formats[] = {
VK_FORMAT_B5G6R5_UNORM,
VK_FORMAT_B8G8R8A8_UNORM,
VK_FORMAT_B8G8R8A8_SRGB,
};
VkResult anv_GetDisplayInfoWSI(
VkDisplayWSI display,
VkDisplayInfoTypeWSI infoType,
size_t* pDataSize,
void* pData)
{
VkDisplayFormatPropertiesWSI *properties = pData;
size_t size;
static const VkSurfacePresentModePropertiesWSI present_modes[] = {
{ VK_PRESENT_MODE_MAILBOX_WSI },
};
VkResult
anv_x11_get_surface_info(struct anv_device *device,
VkSurfaceDescriptionWindowWSI *window,
VkSurfaceInfoTypeWSI infoType,
size_t* pDataSize, void* pData)
{
if (pDataSize == NULL)
return VK_ERROR_INVALID_POINTER;
return vk_error(VK_ERROR_INVALID_POINTER);
switch (infoType) {
case VK_DISPLAY_INFO_TYPE_FORMAT_PROPERTIES_WSI:
size = sizeof(properties[0]) * ARRAY_SIZE(formats);
case VK_SURFACE_INFO_TYPE_PROPERTIES_WSI: {
assert(*pDataSize >= sizeof(VkSurfacePropertiesWSI));
VkSurfacePropertiesWSI *props = pData;
props->minImageCount = 2;
props->maxImageCount = 4;
props->currentExtent = (VkExtent2D) { -1, -1 };
props->minImageExtent = (VkExtent2D) { 1, 1 };
props->maxImageExtent = (VkExtent2D) { INT16_MAX, INT16_MAX };
props->supportedTransforms = VK_SURFACE_TRANSFORM_NONE_BIT_WSI;
props->currentTransform = VK_SURFACE_TRANSFORM_NONE_WSI;
props->maxImageArraySize = 1;
props->supportedUsageFlags =
VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
return VK_SUCCESS;
}
case VK_SURFACE_INFO_TYPE_FORMATS_WSI:
if (pData == NULL) {
*pDataSize = size;
*pDataSize = sizeof(formats);
return VK_SUCCESS;
}
if (*pDataSize < size)
return vk_error(VK_ERROR_INVALID_VALUE);
*pDataSize = size;
for (uint32_t i = 0; i < ARRAY_SIZE(formats); i++)
properties[i].swapChainFormat = formats[i];
assert(*pDataSize >= sizeof(formats));
memcpy(pData, formats, *pDataSize);
return VK_SUCCESS;
case VK_SURFACE_INFO_TYPE_PRESENT_MODES_WSI:
if (pData == NULL) {
*pDataSize = sizeof(present_modes);
return VK_SUCCESS;
}
assert(*pDataSize >= sizeof(present_modes));
memcpy(pData, present_modes, *pDataSize);
return VK_SUCCESS;
default:
return VK_UNSUPPORTED;
return vk_error(VK_ERROR_INVALID_VALUE);
}
}
struct anv_swap_chain {
struct anv_device * device;
struct anv_x11_swap_chain {
struct anv_swap_chain base;
xcb_connection_t * conn;
xcb_window_t window;
xcb_gc_t gc;
VkExtent2D extent;
uint32_t count;
uint32_t image_count;
uint32_t next_image;
struct {
struct anv_image * image;
struct anv_device_memory * memory;
@ -83,41 +108,50 @@ struct anv_swap_chain {
} images[0];
};
VkResult anv_CreateSwapChainWSI(
VkDevice _device,
const VkSwapChainCreateInfoWSI* pCreateInfo,
VkSwapChainWSI* pSwapChain)
VkResult
anv_x11_create_swap_chain(struct anv_device *device,
const VkSwapChainCreateInfoWSI *pCreateInfo,
struct anv_x11_swap_chain **swap_chain_out)
{
ANV_FROM_HANDLE(anv_device, device, _device);
struct anv_swap_chain *chain;
struct anv_x11_swap_chain *chain;
xcb_void_cookie_t cookie;
VkResult result;
size_t size;
int ret;
assert(pCreateInfo->pSurfaceDescription->sType ==
VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
VkSurfaceDescriptionWindowWSI *vk_window =
(VkSurfaceDescriptionWindowWSI *)pCreateInfo->pSurfaceDescription;
assert(vk_window->platform == VK_PLATFORM_XCB_WSI);
int num_images = pCreateInfo->minImageCount;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI);
size = sizeof(*chain) + pCreateInfo->imageCount * sizeof(chain->images[0]);
size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);
chain = anv_device_alloc(device, size, 8,
VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
if (chain == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
chain->device = device;
chain->conn = (xcb_connection_t *) pCreateInfo->pNativeWindowSystemHandle;
chain->window = (xcb_window_t) (uintptr_t) pCreateInfo->pNativeWindowHandle;
chain->count = pCreateInfo->imageCount;
chain->extent = pCreateInfo->imageExtent;
chain->base.type = ANV_SWAP_CHAIN_TYPE_X11;
chain->base.device = device;
for (uint32_t i = 0; i < chain->count; i++) {
VkPlatformHandleXcbWSI *vk_xcb_handle = vk_window->pPlatformHandle;
chain->conn = (xcb_connection_t *) vk_xcb_handle->connection;
chain->window = (xcb_window_t) (uintptr_t)vk_window->pPlatformWindow;
chain->extent = pCreateInfo->imageExtent;
chain->image_count = num_images;
chain->next_image = 0;
for (uint32_t i = 0; i < chain->image_count; i++) {
VkDeviceMemory memory_h;
VkImage image_h;
struct anv_image *image;
struct anv_surface *surface;
struct anv_device_memory *memory;
anv_image_create(_device,
anv_image_create(anv_device_to_handle(device),
&(struct anv_image_create_info) {
.force_tile_mode = true,
.tile_mode = XMAJOR,
@ -147,7 +181,7 @@ VkResult anv_CreateSwapChainWSI(
surface = &image->color_surface;
anv_AllocMemory(_device,
anv_AllocMemory(anv_device_to_handle(device),
&(VkMemoryAllocInfo) {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO,
.allocationSize = image->size,
@ -160,8 +194,8 @@ VkResult anv_CreateSwapChainWSI(
anv_BindImageMemory(VK_NULL_HANDLE, anv_image_to_handle(image),
memory_h, 0);
ret = anv_gem_set_tiling(device, memory->bo.gem_handle,
surface->stride, I915_TILING_X);
int ret = anv_gem_set_tiling(device, memory->bo.gem_handle,
surface->stride, I915_TILING_X);
if (ret) {
result = vk_errorf(VK_ERROR_UNKNOWN, "set_tiling failed: %m");
goto fail;
@ -190,7 +224,6 @@ VkResult anv_CreateSwapChainWSI(
chain->images[i].image = image;
chain->images[i].memory = memory;
chain->images[i].pixmap = pixmap;
image->swap_chain = chain;
xcb_discard_reply(chain->conn, cookie.sequence);
}
@ -208,7 +241,7 @@ VkResult anv_CreateSwapChainWSI(
(uint32_t []) { 0 });
xcb_discard_reply(chain->conn, cookie.sequence);
*pSwapChain = anv_swap_chain_to_handle(chain);
*swap_chain_out = chain;
return VK_SUCCESS;
@ -216,72 +249,66 @@ VkResult anv_CreateSwapChainWSI(
return result;
}
VkResult anv_DestroySwapChainWSI(
VkSwapChainWSI _chain)
VkResult
anv_x11_destroy_swap_chain(struct anv_x11_swap_chain *chain)
{
ANV_FROM_HANDLE(anv_swap_chain, chain, _chain);
anv_device_free(chain->device, chain);
anv_device_free(chain->base.device, chain);
return VK_SUCCESS;
}
VkResult anv_GetSwapChainInfoWSI(
VkSwapChainWSI _chain,
VkSwapChainInfoTypeWSI infoType,
size_t* pDataSize,
void* pData)
VkResult
anv_x11_get_swap_chain_info(struct anv_x11_swap_chain *chain,
VkSwapChainInfoTypeWSI infoType,
size_t* pDataSize, void* pData)
{
ANV_FROM_HANDLE(anv_swap_chain, chain, _chain);
VkSwapChainImageInfoWSI *images;
size_t size;
switch (infoType) {
case VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI:
size = sizeof(*images) * chain->count;
if (pData && *pDataSize < size)
return VK_ERROR_INVALID_VALUE;
case VK_SWAP_CHAIN_INFO_TYPE_IMAGES_WSI: {
VkSwapChainImagePropertiesWSI *images = pData;
*pDataSize = size;
if (!pData)
size = chain->image_count * sizeof(*images);
if (pData == NULL) {
*pDataSize = size;
return VK_SUCCESS;
images = pData;
for (uint32_t i = 0; i < chain->count; i++) {
images[i].image = anv_image_to_handle(chain->images[i].image);
images[i].memory = anv_device_memory_to_handle(chain->images[i].memory);
}
assert(size <= *pDataSize);
for (uint32_t i = 0; i < chain->image_count; i++)
images[i].image = anv_image_to_handle(chain->images[i].image);
*pDataSize = size;
return VK_SUCCESS;
}
default:
return VK_UNSUPPORTED;
return vk_error(VK_ERROR_INVALID_VALUE);
}
}
VkResult anv_QueuePresentWSI(
VkQueue queue_,
const VkPresentInfoWSI* pPresentInfo)
VkResult
anv_x11_acquire_next_image(struct anv_x11_swap_chain *chain,
uint64_t timeout,
VkSemaphore semaphore,
uint32_t *image_index)
{
ANV_FROM_HANDLE(anv_image, image, pPresentInfo->image);
anv_finishme("Implement real blocking AcquireNextImage");
*image_index = chain->next_image;
chain->next_image = (chain->next_image + 1) % chain->image_count;
return VK_SUCCESS;
}
struct anv_swap_chain *chain = image->swap_chain;
VkResult
anv_x11_queue_present(struct anv_queue *queue,
struct anv_x11_swap_chain *chain,
uint32_t image_index)
{
xcb_void_cookie_t cookie;
xcb_pixmap_t pixmap;
assert(pPresentInfo->sType == VK_STRUCTURE_TYPE_PRESENT_INFO_WSI);
if (chain == NULL)
return vk_error(VK_ERROR_INVALID_VALUE);
pixmap = XCB_NONE;
for (uint32_t i = 0; i < chain->count; i++) {
if (image == chain->images[i].image) {
pixmap = chain->images[i].pixmap;
break;
}
}
xcb_pixmap_t pixmap = chain->images[image_index].pixmap;
if (pixmap == XCB_NONE)
return vk_error(VK_ERROR_INVALID_VALUE);