Revise WSI setup.

- Set up present queue creation correctly.
- Move WSI functions to VulkanTestContext.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1899213002

Review URL: https://codereview.chromium.org/1899213002
This commit is contained in:
jvanverth 2016-04-21 11:46:23 -07:00 committed by Commit bot
parent fa7ff470a8
commit b0d4352ca6
11 changed files with 166 additions and 208 deletions

View File

@ -84,7 +84,7 @@
'skiaserve.gyp:skiaserve',
],
}],
[ 'skia_vulkan == 0 or skia_os != "win" or skia_os != "android"', {
[ 'skia_vulkan == 0 or (skia_os != "win" and skia_os != "android")', {
'dependencies!': [
'vulkanviewer.gyp:vulkanviewer',
],

View File

@ -45,14 +45,17 @@ struct GrVkBackendContext : public SkRefCnt {
VkPhysicalDevice fPhysicalDevice;
VkDevice fDevice;
VkQueue fQueue;
uint32_t fQueueFamilyIndex;
uint32_t fGraphicsQueueIndex;
uint32_t fMinAPIVersion;
uint32_t fExtensions;
uint32_t fFeatures;
SkAutoTUnref<const GrVkInterface> fInterface;
// Helper function to create the default Vulkan objects needed by the GrVkGpu object
static const GrVkBackendContext* Create();
// If presentQueueIndex is non-NULL, will try to set up presentQueue as part of device
// creation. canPresent() is a device-dependent function.
static const GrVkBackendContext* Create(uint32_t* presentQueueIndex = nullptr,
bool(*canPresent)(VkInstance, VkPhysicalDevice, uint32_t queueIndex) = nullptr);
~GrVkBackendContext() override;
};

View File

@ -195,33 +195,7 @@ public:
VkPtr<PFN_vkCmdNextSubpass> fCmdNextSubpass;
VkPtr<PFN_vkCmdEndRenderPass> fCmdEndRenderPass;
VkPtr<PFN_vkCmdExecuteCommands> fCmdExecuteCommands;
VkPtr<PFN_vkDestroySurfaceKHR> fDestroySurfaceKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfaceSupportKHR> fGetPhysicalDeviceSurfaceSupportKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR> fGetPhysicalDeviceSurfaceCapabilitiesKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR> fGetPhysicalDeviceSurfaceFormatsKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR> fGetPhysicalDeviceSurfacePresentModesKHR;
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VkPtr<PFN_vkCreateWin32SurfaceKHR> fCreateWin32SurfaceKHR;
VkPtr<PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR> fGetPhysicalDeviceWin32PresentationSupportKHR;
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
VkPtr<PFN_vkCreateAndroidSurfaceKHR> fCreateAndroidSurfaceKHR;
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
VkPtr<PFN_vkCreateXlibSurfaceKHR> fCreateXlibSurfaceKHR;
VkPtr<PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR> fGetPhysicalDeviceXlibPresentationSupportKHR;
#endif
VkPtr<PFN_vkCreateSwapchainKHR> fCreateSwapchainKHR;
VkPtr<PFN_vkDestroySwapchainKHR> fDestroySwapchainKHR;
VkPtr<PFN_vkGetSwapchainImagesKHR> fGetSwapchainImagesKHR;
VkPtr<PFN_vkAcquireNextImageKHR> fAcquireNextImageKHR;
VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR;
VkPtr<PFN_vkGetPhysicalDeviceDisplayPropertiesKHR> fGetPhysicalDeviceDisplayPropertiesKHR;
VkPtr<PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR> fGetPhysicalDeviceDisplayPlanePropertiesKHR;
VkPtr<PFN_vkGetDisplayPlaneSupportedDisplaysKHR> fGetDisplayPlaneSupportedDisplaysKHR;
VkPtr<PFN_vkGetDisplayModePropertiesKHR> fGetDisplayModePropertiesKHR;
VkPtr<PFN_vkCreateDisplayModeKHR> fCreateDisplayModeKHR;
VkPtr<PFN_vkGetDisplayPlaneCapabilitiesKHR> fGetDisplayPlaneCapabilitiesKHR;
VkPtr<PFN_vkCreateDisplayPlaneSurfaceKHR> fCreateDisplayPlaneSurfaceKHR;
VkPtr<PFN_vkCreateSharedSwapchainsKHR> fCreateSharedSwapchainsKHR;
VkPtr<PFN_vkCreateDebugReportCallbackEXT> fCreateDebugReportCallbackEXT;
VkPtr<PFN_vkDebugReportMessageEXT> fDebugReportMessageEXT;
VkPtr<PFN_vkDestroyDebugReportCallbackEXT> fDestroyDebugReportCallbackEXT;

View File

@ -35,7 +35,8 @@ const char* kDebugLayerNames[] = {
const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 8);
// Create the base Vulkan objects needed by the GrVkGpu object
const GrVkBackendContext* GrVkBackendContext::Create() {
const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndexPtr,
bool(*canPresent)(VkInstance, VkPhysicalDevice, uint32_t queueIndex)) {
VkPhysicalDevice physDev;
VkDevice device;
VkInstance inst;
@ -141,7 +142,7 @@ const GrVkBackendContext* GrVkBackendContext::Create() {
vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueProps);
// iterate to find the graphics queue
uint32_t graphicsQueueIndex = -1;
uint32_t graphicsQueueIndex = queueCount;
for (uint32_t i = 0; i < queueCount; i++) {
if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
graphicsQueueIndex = i;
@ -150,6 +151,19 @@ const GrVkBackendContext* GrVkBackendContext::Create() {
}
SkASSERT(graphicsQueueIndex < queueCount);
// iterate to find the present queue, if needed
uint32_t presentQueueIndex = graphicsQueueIndex;
if (presentQueueIndexPtr && canPresent) {
for (uint32_t i = 0; i < queueCount; i++) {
if (canPresent(inst, physDev, i)) {
presentQueueIndex = i;
break;
}
}
SkASSERT(presentQueueIndex < queueCount);
*presentQueueIndexPtr = presentQueueIndex;
}
extensions.initDevice(kGrVkMinimumVersion, inst, physDev);
SkTArray<const char*> deviceLayerNames;
@ -191,20 +205,32 @@ const GrVkBackendContext* GrVkBackendContext::Create() {
float queuePriorities[1] = { 0.0 };
// Here we assume no need for swapchain queue
// If one is needed, the client will need its own setup code
const VkDeviceQueueCreateInfo queueInfo = {
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
nullptr, // pNext
0, // VkDeviceQueueCreateFlags
graphicsQueueIndex, // queueFamilyIndex
1, // queueCount
queuePriorities, // pQueuePriorities
const VkDeviceQueueCreateInfo queueInfo[2] = {
{
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
nullptr, // pNext
0, // VkDeviceQueueCreateFlags
graphicsQueueIndex, // queueFamilyIndex
1, // queueCount
queuePriorities, // pQueuePriorities
},
{
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
nullptr, // pNext
0, // VkDeviceQueueCreateFlags
presentQueueIndex, // queueFamilyIndex
1, // queueCount
queuePriorities, // pQueuePriorities
}
};
uint32_t queueInfoCount = (presentQueueIndex != graphicsQueueIndex) ? 2 : 1;
const VkDeviceCreateInfo deviceInfo = {
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
nullptr, // pNext
0, // VkDeviceCreateFlags
1, // queueCreateInfoCount
&queueInfo, // pQueueCreateInfos
queueInfoCount, // queueCreateInfoCount
queueInfo, // pQueueCreateInfos
(uint32_t) deviceLayerNames.count(), // layerCount
deviceLayerNames.begin(), // ppEnabledLayerNames
(uint32_t) deviceExtensionNames.count(), // extensionCount
@ -227,7 +253,7 @@ const GrVkBackendContext* GrVkBackendContext::Create() {
ctx->fPhysicalDevice = physDev;
ctx->fDevice = device;
ctx->fQueue = queue;
ctx->fQueueFamilyIndex = graphicsQueueIndex;
ctx->fGraphicsQueueIndex = graphicsQueueIndex;
ctx->fMinAPIVersion = kGrVkMinimumVersion;
ctx->fExtensions = extensionFlags;
ctx->fFeatures = featureFlags;

View File

@ -120,7 +120,7 @@ GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options,
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType
nullptr, // pNext
VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // CmdPoolCreateFlags
backendCtx->fQueueFamilyIndex, // queueFamilyIndex
backendCtx->fGraphicsQueueIndex, // queueFamilyIndex
};
GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateCommandPool(fDevice, &cmdPoolInfo, nullptr,
&fCmdPool));

View File

@ -157,45 +157,6 @@ const GrVkInterface* GrVkCreateInterface(VkInstance instance, VkDevice device,
GET_DEV_PROC(CmdNextSubpass);
GET_DEV_PROC(CmdEndRenderPass);
GET_DEV_PROC(CmdExecuteCommands);
if (extensionFlags & kKHR_surface_GrVkExtensionFlag) {
GET_PROC(DestroySurfaceKHR);
GET_PROC(GetPhysicalDeviceSurfaceSupportKHR);
GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
}
if (extensionFlags & kKHR_surface_GrVkExtensionFlag) {
GET_DEV_PROC(CreateSwapchainKHR);
GET_DEV_PROC(DestroySwapchainKHR);
GET_DEV_PROC(GetSwapchainImagesKHR);
GET_DEV_PROC(AcquireNextImageKHR);
GET_DEV_PROC(QueuePresentKHR);
}
#if defined(VK_USE_PLATFORM_WIN32_KHR)
if (extensionFlags & kKHR_win32_surface_GrVkExtensionFlag) {
GET_PROC(CreateWin32SurfaceKHR);
GET_PROC(GetPhysicalDeviceWin32PresentationSupportKHR);
}
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
if (extensionFlags & kKHR_android_surface_GrVkExtensionFlag) {
GET_PROC(CreateAndroidSurfaceKHR);
}
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
if (extensionFlags & kKHR_xlib_surface_GrVkExtensionFlag) {
GET_PROC(CreateXlibSurfaceKHR);
GET_PROC(GetPhysicalDeviceXlibPresentationSupportKHR);
}
#endif
// We probably don't care about these, they're for consoles
//GET_PROC(GetPhysicalDeviceDisplayPropertiesKHR);
//GET_PROC(GetPhysicalDeviceDisplayPlanePropertiesKHR);
//GET_PROC(GetDisplayPlaneSupportedDisplaysKHR);
//GET_PROC(GetDisplayModePropertiesKHR);
//GET_PROC(CreateDisplayModeKHR);
//GET_PROC(GetDisplayPlaneCapabilitiesKHR);
//GET_PROC(CreateDisplayPlaneSurfaceKHR);
//GET_DEV_PROC(CreateSharedSwapchainsKHR);
if (extensionFlags & kEXT_debug_report_GrVkExtensionFlag) {
GET_PROC(CreateDebugReportCallbackEXT);
@ -347,24 +308,6 @@ bool GrVkInterface::validate() const {
NULL == fFunctions.fCmdNextSubpass ||
NULL == fFunctions.fCmdEndRenderPass ||
NULL == fFunctions.fCmdExecuteCommands ||
NULL == fFunctions.fDestroySurfaceKHR ||
NULL == fFunctions.fGetPhysicalDeviceSurfaceSupportKHR ||
NULL == fFunctions.fGetPhysicalDeviceSurfaceCapabilitiesKHR ||
NULL == fFunctions.fGetPhysicalDeviceSurfaceFormatsKHR ||
NULL == fFunctions.fGetPhysicalDeviceSurfacePresentModesKHR ||
NULL == fFunctions.fCreateSwapchainKHR ||
NULL == fFunctions.fDestroySwapchainKHR ||
NULL == fFunctions.fGetSwapchainImagesKHR ||
NULL == fFunctions.fAcquireNextImageKHR ||
NULL == fFunctions.fQueuePresentKHR ||
//NULL == fFunctions.fGetPhysicalDeviceDisplayPropertiesKHR ||
//NULL == fFunctions.fGetPhysicalDeviceDisplayPlanePropertiesKHR ||
//NULL == fFunctions.fGetDisplayPlaneSupportedDisplaysKHR ||
//NULL == fFunctions.fGetDisplayModePropertiesKHR ||
//NULL == fFunctions.fCreateDisplayModeKHR ||
//NULL == fFunctions.fGetDisplayPlaneCapabilitiesKHR ||
//NULL == fFunctions.fCreateDisplayPlaneSurfaceKHR ||
//NULL == fFunctions.fCreateSharedSwapchainsKHR ||
NULL == fFunctions.fCreateDebugReportCallbackEXT ||
NULL == fFunctions.fDebugReportMessageEXT ||
NULL == fFunctions.fDestroyDebugReportCallbackEXT) {

View File

@ -68,7 +68,6 @@ bool GrVkMemory::AllocAndBindBufferMemory(const GrVkGpu* gpu,
VkMemoryRequirements memReqs;
GR_VK_CALL(iface, GetBufferMemoryRequirements(device, buffer, &memReqs));
if (!alloc_device_memory(gpu, &memReqs, flags, memory)) {
return false;
}

View File

@ -19,6 +19,9 @@
#undef CreateSemaphore
#endif
#define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk" #F)
#define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk" #F)
VulkanTestContext::VulkanTestContext(void* platformData, int msaaSampleCount)
: fSurface(VK_NULL_HANDLE)
, fSwapchain(VK_NULL_HANDLE)
@ -32,11 +35,29 @@ VulkanTestContext::VulkanTestContext(void* platformData, int msaaSampleCount)
void VulkanTestContext::initializeContext(void* platformData) {
fBackendContext.reset(GrVkBackendContext::Create());
fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPresent));
if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) ||
!(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) {
fBackendContext.reset(nullptr);
return;
}
VkInstance instance = fBackendContext->fInstance;
VkDevice device = fBackendContext->fDevice;
GET_PROC(DestroySurfaceKHR);
GET_PROC(GetPhysicalDeviceSurfaceSupportKHR);
GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
GET_DEV_PROC(CreateSwapchainKHR);
GET_DEV_PROC(DestroySwapchainKHR);
GET_DEV_PROC(GetSwapchainImagesKHR);
GET_DEV_PROC(AcquireNextImageKHR);
GET_DEV_PROC(QueuePresentKHR);
fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext)fBackendContext.get());
fSurface = createVkSurface(platformData);
fSurface = createVkSurface(instance, platformData);
if (VK_NULL_HANDLE == fSurface) {
fBackendContext.reset(nullptr);
return;
@ -57,22 +78,10 @@ void VulkanTestContext::initializeContext(void* platformData) {
GetPhysicalDeviceQueueFamilyProperties(fBackendContext->fPhysicalDevice, &queueCount,
queueProps));
// iterate to find the present queue
fPresentQueueIndex = -1;
for (uint32_t i = 0; i < queueCount; i++) {
if ((queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && canPresent(i)) {
fPresentQueueIndex = i;
break;
}
}
SkASSERT(fPresentQueueIndex < queueCount);
VkBool32 supported;
VkResult res = GR_VK_CALL(fBackendContext->fInterface,
GetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysicalDevice,
fPresentQueueIndex,
fSurface,
&supported));
VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysicalDevice,
fPresentQueueIndex, fSurface,
&supported);
if (VK_SUCCESS != res) {
this->destroyContext();
return;
@ -85,60 +94,44 @@ void VulkanTestContext::initializeContext(void* platformData) {
// create presentQueue
vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQueue);
}
bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height)
{
// check for capabilities
VkSurfaceCapabilitiesKHR caps;
VkResult res = GR_VK_CALL(fBackendContext->fInterface,
GetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPhysicalDevice,
fSurface,
&caps));
VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPhysicalDevice,
fSurface, &caps);
if (VK_SUCCESS != res) {
return false;
}
uint32_t surfaceFormatCount;
res = GR_VK_CALL(fBackendContext->fInterface,
GetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice,
fSurface,
&surfaceFormatCount,
nullptr));
res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice, fSurface,
&surfaceFormatCount, nullptr);
if (VK_SUCCESS != res) {
return false;
}
SkAutoMalloc surfaceFormatAlloc(surfaceFormatCount * sizeof(VkSurfaceFormatKHR));
VkSurfaceFormatKHR* surfaceFormats = (VkSurfaceFormatKHR*)surfaceFormatAlloc.get();
res = GR_VK_CALL(fBackendContext->fInterface,
GetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice,
fSurface,
&surfaceFormatCount,
surfaceFormats));
res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice, fSurface,
&surfaceFormatCount, surfaceFormats);
if (VK_SUCCESS != res) {
return false;
}
uint32_t presentModeCount;
res = GR_VK_CALL(fBackendContext->fInterface,
GetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDevice,
fSurface,
&presentModeCount,
nullptr));
res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDevice, fSurface,
&presentModeCount, nullptr);
if (VK_SUCCESS != res) {
return false;
}
SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR));
VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get();
res = GR_VK_CALL(fBackendContext->fInterface,
GetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDevice,
fSurface,
&presentModeCount,
presentModes));
res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDevice, fSurface,
&presentModeCount, presentModes);
if (VK_SUCCESS != res) {
return false;
}
@ -205,8 +198,8 @@ bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height)
swapchainCreateInfo.imageArrayLayers = 1;
swapchainCreateInfo.imageUsage = usageFlags;
uint32_t queueFamilies[] = { fBackendContext->fQueueFamilyIndex, fPresentQueueIndex };
if (fBackendContext->fQueueFamilyIndex != fPresentQueueIndex) {
uint32_t queueFamilies[] = { fBackendContext->fGraphicsQueueIndex, fPresentQueueIndex };
if (fBackendContext->fGraphicsQueueIndex != fPresentQueueIndex) {
swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
swapchainCreateInfo.queueFamilyIndexCount = 2;
swapchainCreateInfo.pQueueFamilyIndices = queueFamilies;
@ -222,9 +215,7 @@ bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height)
swapchainCreateInfo.clipped = true;
swapchainCreateInfo.oldSwapchain = fSwapchain;
res = GR_VK_CALL(fBackendContext->fInterface,
CreateSwapchainKHR(fBackendContext->fDevice,
&swapchainCreateInfo, nullptr, &fSwapchain));
res = fCreateSwapchainKHR(fBackendContext->fDevice, &swapchainCreateInfo, nullptr, &fSwapchain);
if (VK_SUCCESS != res) {
return false;
}
@ -235,9 +226,7 @@ bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height)
this->destroyBuffers();
GR_VK_CALL(fBackendContext->fInterface, DestroySwapchainKHR(fBackendContext->fDevice,
swapchainCreateInfo.oldSwapchain,
nullptr));
fDestroySwapchainKHR(fBackendContext->fDevice, swapchainCreateInfo.oldSwapchain, nullptr);
}
this->createBuffers(swapchainCreateInfo.imageFormat);
@ -248,16 +237,10 @@ bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height)
void VulkanTestContext::createBuffers(VkFormat format) {
GrVkFormatToPixelConfig(format, &fPixelConfig);
GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, GetSwapchainImagesKHR(fBackendContext->fDevice,
fSwapchain,
&fImageCount,
nullptr));
fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, nullptr);
SkASSERT(fImageCount);
fImages = new VkImage[fImageCount];
GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, GetSwapchainImagesKHR(fBackendContext->fDevice,
fSwapchain,
&fImageCount,
fImages));
fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, fImages);
// set up initial image layouts and create surfaces
fImageLayouts = new VkImageLayout[fImageCount];
@ -289,7 +272,7 @@ void VulkanTestContext::createBuffers(VkFormat format) {
memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo));
commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
// this needs to be on the render queue
commandPoolInfo.queueFamilyIndex = fBackendContext->fQueueFamilyIndex;
commandPoolInfo.queueFamilyIndex = fBackendContext->fGraphicsQueueIndex;
commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
CreateCommandPool(fBackendContext->fDevice, &commandPoolInfo,
@ -397,14 +380,12 @@ void VulkanTestContext::destroyContext() {
}
if (VK_NULL_HANDLE != fSwapchain) {
GR_VK_CALL(fBackendContext->fInterface, DestroySwapchainKHR(fBackendContext->fDevice,
fSwapchain, nullptr));
fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr);
fSwapchain = VK_NULL_HANDLE;
}
if (VK_NULL_HANDLE != fSurface) {
GR_VK_CALL(fBackendContext->fInterface, DestroySurfaceKHR(fBackendContext->fInstance,
fSurface, nullptr));
fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr);
fSurface = VK_NULL_HANDLE;
}
@ -439,13 +420,9 @@ SkSurface* VulkanTestContext::getBackbufferSurface() {
// semaphores should be in unsignaled state
// acquire the image
VkResult res = GR_VK_CALL(fBackendContext->fInterface,
AcquireNextImageKHR(fBackendContext->fDevice,
fSwapchain,
UINT64_MAX,
backbuffer->fAcquireSemaphore,
VK_NULL_HANDLE,
&backbuffer->fImageIndex));
VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX,
backbuffer->fAcquireSemaphore, VK_NULL_HANDLE,
&backbuffer->fImageIndex);
if (VK_ERROR_SURFACE_LOST_KHR == res) {
// need to figure out how to create a new vkSurface without the platformData*
// maybe use attach somehow? but need a Window
@ -458,13 +435,9 @@ SkSurface* VulkanTestContext::getBackbufferSurface() {
}
// acquire the image
res = GR_VK_CALL(fBackendContext->fInterface,
AcquireNextImageKHR(fBackendContext->fDevice,
fSwapchain,
UINT64_MAX,
backbuffer->fAcquireSemaphore,
VK_NULL_HANDLE,
&backbuffer->fImageIndex));
res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX,
backbuffer->fAcquireSemaphore, VK_NULL_HANDLE,
&backbuffer->fImageIndex);
if (VK_SUCCESS != res) {
return nullptr;
@ -489,7 +462,7 @@ SkSurface* VulkanTestContext::getBackbufferSurface() {
layout, // oldLayout
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout
fPresentQueueIndex, // srcQueueFamilyIndex
fBackendContext->fQueueFamilyIndex, // dstQueueFamilyIndex
fBackendContext->fGraphicsQueueIndex, // dstQueueFamilyIndex
fImages[backbuffer->fImageIndex], // image
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange
};
@ -549,7 +522,7 @@ void VulkanTestContext::swapBuffers() {
dstAccessMask, // inputMask
layout, // oldLayout
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout
fBackendContext->fQueueFamilyIndex, // srcQueueFamilyIndex
fBackendContext->fGraphicsQueueIndex, // srcQueueFamilyIndex
fPresentQueueIndex, // dstQueueFamilyIndex
fImages[backbuffer->fImageIndex], // image
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange
@ -601,7 +574,6 @@ void VulkanTestContext::swapBuffers() {
NULL // pResults
};
GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
QueuePresentKHR(fPresentQueue, &presentInfo));
fQueuePresentKHR(fPresentQueue, &presentInfo);
}

View File

@ -21,8 +21,8 @@ public:
~VulkanTestContext();
// each platform will have to implement these in its CPP file
VkSurfaceKHR createVkSurface(void* platformData);
bool canPresent(uint32_t queueFamilyIndex);
static VkSurfaceKHR createVkSurface(VkInstance, void* platformData);
static bool canPresent(VkInstance, VkPhysicalDevice, uint32_t queueFamilyIndex);
static VulkanTestContext* Create(void* platformData, int msaaSampleCount) {
VulkanTestContext* ctx = new VulkanTestContext(platformData, msaaSampleCount);
@ -69,6 +69,30 @@ private:
SkAutoTUnref<const GrVkBackendContext> fBackendContext;
// simple wrapper class that exists only to initialize a pointer to NULL
template <typename FNPTR_TYPE> class VkPtr {
public:
VkPtr() : fPtr(NULL) {}
VkPtr operator=(FNPTR_TYPE ptr) { fPtr = ptr; return *this; }
operator FNPTR_TYPE() const { return fPtr; }
private:
FNPTR_TYPE fPtr;
};
// WSI interface functions
VkPtr<PFN_vkDestroySurfaceKHR> fDestroySurfaceKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfaceSupportKHR> fGetPhysicalDeviceSurfaceSupportKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR> fGetPhysicalDeviceSurfaceCapabilitiesKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR> fGetPhysicalDeviceSurfaceFormatsKHR;
VkPtr<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR> fGetPhysicalDeviceSurfacePresentModesKHR;
VkPtr<PFN_vkCreateSwapchainKHR> fCreateSwapchainKHR;
VkPtr<PFN_vkDestroySwapchainKHR> fDestroySwapchainKHR;
VkPtr<PFN_vkGetSwapchainImagesKHR> fGetSwapchainImagesKHR;
VkPtr<PFN_vkAcquireNextImageKHR> fAcquireNextImageKHR;
VkPtr<PFN_vkQueuePresentKHR> fQueuePresentKHR;
VkPtr<PFN_vkCreateSharedSwapchainsKHR> fCreateSharedSwapchainsKHR;
GrContext* fContext;
VkSurfaceKHR fSurface;
VkSwapchainKHR fSwapchain;

View File

@ -1,6 +1,6 @@
/*
* Copyright 2015 Google Inc.
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
@ -9,11 +9,18 @@
#include "VulkanTestContext_android.h"
#include "vk/GrVkInterface.h"
#include "../../src/gpu/vk/GrVkUtil.h"
#include "vk/GrVkUtil.h"
VkSurfaceKHR VulkanTestContext::createVkSurface(void* platformData) {
// need better error handling here
SkASSERT(platformData);
VkSurfaceKHR VulkanTestContext::createVkSurface(VkInstance instance, void* platformData) {
static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr;
if (!createAndroidSurfaceKHR) {
createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(instance,
"vkCreateAndroidSurfaceKHR");
}
if (!platformData) {
return VK_NULL_HANDLE;
}
ContextPlatformData_android* androidPlatformData =
reinterpret_cast<ContextPlatformData_android*>(platformData);
VkSurfaceKHR surface;
@ -25,13 +32,12 @@ VkSurfaceKHR VulkanTestContext::createVkSurface(void* platformData) {
surfaceCreateInfo.flags = 0;
surfaceCreateInfo.window = androidPlatformData->fNativeWindow;
VkResult res = GR_VK_CALL(fBackendContext->fInterface,
CreateAndroidSurfaceKHR(fBackendContext->fInstance,
&surfaceCreateInfo,
nullptr, &surface));
VkResult res = createAndroidSurfaceKHR(fBackendContext->fInstance, &surfaceCreateInfo,
nullptr, &surface);
return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE;
}
bool VulkanTestContext::canPresent(uint32_t queueFamilyIndex) {
bool VulkanTestContext::canPresent(VkInstance instance, VkPhysicalDevice physDev,
uint32_t queueFamilyIndex) {
return true;
}

View File

@ -1,6 +1,6 @@
/*
* Copyright 2015 Google Inc.
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
@ -9,12 +9,19 @@
#include "VulkanTestContext_win.h"
#include "vk/GrVkInterface.h"
#include "../../src/gpu/vk/GrVkUtil.h"
#include "vk/GrVkUtil.h"
// Platform dependant call
VkSurfaceKHR VulkanTestContext::createVkSurface(void* platformData) {
// need better error handling here
SkASSERT(platformData);
VkSurfaceKHR VulkanTestContext::createVkSurface(VkInstance instance, void* platformData) {
static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr;
if (!createWin32SurfaceKHR) {
createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)vkGetInstanceProcAddr(instance,
"vkCreateWin32SurfaceKHR");
}
if (!platformData) {
return VK_NULL_HANDLE;
}
ContextPlatformData_win* winPlatformData =
reinterpret_cast<ContextPlatformData_win*>(platformData);
VkSurfaceKHR surface;
@ -27,9 +34,7 @@ VkSurfaceKHR VulkanTestContext::createVkSurface(void* platformData) {
surfaceCreateInfo.hinstance = winPlatformData->fHInstance;
surfaceCreateInfo.hwnd = winPlatformData->fHWnd;
VkResult res = GR_VK_CALL(fBackendContext->fInterface,
CreateWin32SurfaceKHR(fBackendContext->fInstance, &surfaceCreateInfo,
nullptr, &surface));
VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
if (VK_SUCCESS != res) {
return VK_NULL_HANDLE;
}
@ -38,10 +43,16 @@ VkSurfaceKHR VulkanTestContext::createVkSurface(void* platformData) {
}
// Platform dependant call
bool VulkanTestContext::canPresent(uint32_t queueFamilyIndex) {
VkBool32 check = GR_VK_CALL(fBackendContext->fInterface,
GetPhysicalDeviceWin32PresentationSupportKHR(
fBackendContext->fPhysicalDevice,
queueFamilyIndex));
bool VulkanTestContext::canPresent(VkInstance instance, VkPhysicalDevice physDev,
uint32_t queueFamilyIndex) {
static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
getPhysicalDeviceWin32PresentationSupportKHR = nullptr;
if (!getPhysicalDeviceWin32PresentationSupportKHR) {
getPhysicalDeviceWin32PresentationSupportKHR =
(PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) vkGetInstanceProcAddr(instance,
"vkGetPhysicalDeviceWin32PresentationSupportKHR");
}
VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex);
return (VK_FALSE != check);
}