RenderBackend.h:

* Renamed vkwindow to sdlWindow in struct vulkanContext_t to matche the rest of the struct naming conventions.

Image_VK.cpp:
  * disabled printing "Vulkan Image alloc " to the terminal, flooding it
  with data

RenderBackend_VK.cpp:
  * Re-enabled r_vkEnableValidationLayers enabling/disabling Vulkan
  validation checking, I had it hard-coded to true for testing reasons.
  * static void DestroySwapChain():
    * I don't know if the changes I introduced here are helping or not,
    or even doing anything, so this part can be ignored or changed back.
  * GL_StartFrame() and GL_BlockingSwapBuffers():
    * VkResult for these two functions, vkAcquireNextImageKHR and
    vkQueuePresentKHR, don't need to return VK_SUCCESS for the
    application to be valid, so handle them differently here. There may
    be others like this, but I don't know.

qvk.h:
  * Since VK_USE_PLATFORM_* is defined in the CMakeLists.txt file, for
  now anyways, use them to wrap the correct platform headers instead of
  defining them here.

sdl_vkimp.cpp:
  * Some debug printing changes, from GL to Vulkan, since this is for
  the Vulkan API.
This commit is contained in:
Eric Womer 2020-01-01 14:31:28 -05:00
parent 4f38ce0633
commit 596fbb18ca
5 changed files with 75 additions and 16 deletions

View file

@ -150,7 +150,7 @@ struct vulkanContext_t
{
// Eric: If on linux, use this to pass SDL_Window pointer to the SDL_Vulkan_* methods not in sdl_vkimp.cpp file.
#if defined(__linux__)
SDL_Window* vkwindow = nullptr;
SDL_Window* sdlWindow = nullptr;
#endif
uint64 frameCounter;
uint32 frameParity;

View file

@ -567,7 +567,8 @@ void idImage::AllocImage()
ID_VK_CHECK( vkBindImageMemory( vkcontext.device, image, allocation.deviceMemory, allocation.offset ) );
#endif
idLib::Printf( "Vulkan Image alloc '%s': %p\n", GetName(), image );
// Eric: disable for now to clean the terminal output
// idLib::Printf( "Vulkan Image alloc '%s': %p\n", GetName(), image );
// Create Image View
VkImageViewCreateInfo viewCreateInfo = {};

View file

@ -254,7 +254,7 @@ static void CreateVulkanInstance()
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
const bool enableLayers = true; // r_vkEnableValidationLayers.GetBool(); EW: Testing
const bool enableLayers = r_vkEnableValidationLayers.GetBool();
vkcontext.instanceExtensions.Clear();
vkcontext.deviceExtensions.Clear();
@ -440,7 +440,7 @@ static void CreateSurface()
#else
#if defined(__linux__)
if(!SDL_Vulkan_CreateSurface(vkcontext.vkwindow, vkcontext.instance, &vkcontext.surface)) {
if(!SDL_Vulkan_CreateSurface(vkcontext.sdlWindow, vkcontext.instance, &vkcontext.surface)) {
idLib::FatalError("Error while creating Vulkan surface: %s", SDL_GetError());
}
#else
@ -724,7 +724,7 @@ static VkExtent2D ChooseSurfaceExtent( VkSurfaceCapabilitiesKHR& caps )
int width;
int height;
SDL_Vulkan_GetDrawableSize(vkcontext.vkwindow, &width, &height);
SDL_Vulkan_GetDrawableSize(vkcontext.sdlWindow, &width, &height);
width = CLAMP(width, caps.minImageExtent.width, caps.maxImageExtent.width);
height = CLAMP(height, caps.minImageExtent.height, caps.maxImageExtent.height);
@ -825,7 +825,8 @@ DestroySwapChain
*/
static void DestroySwapChain()
{
for( uint32 i = 0; i < NUM_FRAME_DATA; ++i )
for( uint32 i = 0; i < NUM_FRAME_DATA; ++i )
{
vkDestroyImageView( vkcontext.device, vkcontext.swapchainViews[ i ], NULL );
}
@ -984,11 +985,21 @@ static void CreateRenderTargets()
VK_IMAGE_TILING_OPTIMAL,
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT );
}
idImageOpts depthOptions;
depthOptions.format = FMT_DEPTH;
idImageOpts depthOptions;
depthOptions.format = FMT_DEPTH;
depthOptions.width = renderSystem->GetWidth();
// Eric: See if this fixes resizing
#if defined(__linux__)
gpuInfo_t& gpu = *vkcontext.gpu;
VkExtent2D extent = ChooseSurfaceExtent( gpu.surfaceCaps );
depthOptions.width = extent.width;
depthOptions.height = extent.height;
#else
depthOptions.width = renderSystem->GetWidth();
depthOptions.height = renderSystem->GetHeight();
#endif
depthOptions.numLevels = 1;
depthOptions.samples = static_cast< textureSamples_t >( vkcontext.sampleCount );
@ -1736,7 +1747,24 @@ idRenderBackend::GL_StartFrame
*/
void idRenderBackend::GL_StartFrame()
{
ID_VK_CHECK( vkAcquireNextImageKHR( vkcontext.device, vkcontext.swapchain, UINT64_MAX, vkcontext.acquireSemaphores[ vkcontext.frameParity ], VK_NULL_HANDLE, &vkcontext.currentSwapIndex ) );
// Eric: Since VK_SUBOPTIMAL_KHR is not a hard fault and VK_ERROR_OUT_OF_DATE_KHR means the window is being resized (or other stuff) handle them instead of killing the app.
VkResult result = vkAcquireNextImageKHR( vkcontext.device, vkcontext.swapchain, UINT64_MAX, vkcontext.acquireSemaphores[ vkcontext.frameParity ], VK_NULL_HANDLE, &vkcontext.currentSwapIndex );
switch (result) {
case VK_SUCCESS:
case VK_SUBOPTIMAL_KHR:
break;
case VK_ERROR_OUT_OF_DATE_KHR:
DestroySwapChain();
CreateSwapChain();
return;
// return on_window_size_changed();
break;
default:
idLib::FatalError("VK: %s - %s", VK_ErrorToString(result),
"vkAcquireNextImageKHR( vkcontext.device, vkcontext.swapchain, UINT64_MAX, vkcontext.acquireSemaphores[ vkcontext.frameParity ], VK_NULL_HANDLE, &vkcontext.currentSwapIndex )");
return;
}
// ID_VK_CHECK( vkAcquireNextImageKHR( vkcontext.device, vkcontext.swapchain, UINT64_MAX, vkcontext.acquireSemaphores[ vkcontext.frameParity ], VK_NULL_HANDLE, &vkcontext.currentSwapIndex ) );
idImage::EmptyGarbage();
@ -1857,7 +1885,26 @@ void idRenderBackend::GL_BlockingSwapBuffers()
presentInfo.pSwapchains = &vkcontext.swapchain;
presentInfo.pImageIndices = &vkcontext.currentSwapIndex;
ID_VK_CHECK( vkQueuePresentKHR( vkcontext.presentQueue, &presentInfo ) );
// Eric: // Eric: Since VK_SUBOPTIMAL_KHR and VK_ERROR_OUT_OF_DATE_KHR here means
// the window is being resized (or other stuff) handle them instead of killing the app.
VkResult result = vkQueuePresentKHR( vkcontext.presentQueue, &presentInfo );
switch (result) {
case VK_SUCCESS:
break;
case VK_ERROR_OUT_OF_DATE_KHR:
case VK_SUBOPTIMAL_KHR:
// return on_window_size_changed(); Eric: Handle resizing the window.
DestroySwapChain();
CreateSwapChain();
return;
break;
default:
idLib::FatalError("VK: %s - %s", VK_ErrorToString(result),
"vkQueuePresentKHR( vkcontext.presentQueue, &presentInfo )");
return;
}
// ID_VK_CHECK( vkQueuePresentKHR( vkcontext.presentQueue, &presentInfo ) );
// RB: at this time the image is presented on the screen

View file

@ -32,9 +32,20 @@ If you have questions concerning this license or the applicable additional terms
#if defined( USE_VULKAN )
// #define VK_USE_PLATFORM_XLIB_KHR
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#include <Windows.h>
#elif defined(VK_USE_PLATFORM_XCB_KHR)
#include <xcb/xcb.h>
#include <dlfcn.h>
#include <cstdlib>
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <dlfcn.h>
#include <cstdlib>
#endif
#define VK_USE_PLATFORM_XCB_KHR
#define USE_AMD_ALLOCATOR
#include <vulkan/vulkan.h>

View file

@ -265,11 +265,11 @@ bool VKimp_Init( glimpParms_t parms )
if( !window )
{
common->DPrintf( "Couldn't set GL mode %d/%d/%d: %s",
common->DPrintf( "Couldn't set Vulkan mode %d/%d/%d: %s",
channelcolorbits, tdepthbits, tstencilbits, SDL_GetError() );
continue;
}
vkcontext.vkwindow = window;
vkcontext.sdlWindow = window;
// RB begin
SDL_GetWindowSize( window, &glConfig.nativeScreenWidth, &glConfig.nativeScreenHeight );
// RB end
@ -298,7 +298,7 @@ bool VKimp_Init( glimpParms_t parms )
if( !window )
{
common->Printf( "No usable GL mode found: %s", SDL_GetError() );
common->Printf( "No usable VK mode found: %s", SDL_GetError() );
return false;
}