Applying KungFuJesus's patch from

https://github.com/RobertBeckebans/RBDOOM-3-BFG/issues/398#issuecomment-569442019
This commit is contained in:
Eric Womer 2019-12-29 11:12:34 -05:00
parent 9ab2c9a4fd
commit f1e650e2c4
14 changed files with 182 additions and 29 deletions

View file

@ -315,10 +315,10 @@ if(USE_VULKAN)
#option(ENABLE_NV_EXTENSIONS "Enables support of Nvidia-specific extensions" ON)
#option(ENABLE_OPT "Enables spirv-opt capability if present" ON)
set(GLSLANG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/glslang)
add_subdirectory(${GLSLANG_DIR})
#set(GLSLANG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/glslang)
#add_subdirectory(${GLSLANG_DIR})
include_directories(${GLSLANG_DIR}/glslang)
#include_directories(${GLSLANG_DIR}/glslang)
else()
@ -1321,6 +1321,7 @@ if(MSVC)
${Vulkan_LIBRARY}
glslang
SPIRV
xcb
)
if(ENABLE_GLSLANG_BINARIES)

View file

@ -122,11 +122,11 @@ class idDrawVert
public:
idVec3 xyz; // 12 bytes
private:
// RB: don't let the old tools code mess with these values
halfFloat_t st[2]; // 4 bytes
byte normal[4]; // 4 bytes
byte tangent[4]; // 4 bytes -- [3] is texture polarity sign
//private:
// RB: don't let the old tools code mess with these values
public:
byte color[4]; // 4 bytes
byte color2[4]; // 4 bytes -- weights for skinning

View file

@ -113,7 +113,7 @@ const uint32 NUM_FRAME_DATA = 2;
#include "../ui/UserInterface.h"
// RB: required for SWF extensions
#include "rapidjson/document.h"
//#include "rapidjson/document.h"
#include "../swf/SWF.h"

View file

@ -118,9 +118,9 @@ struct idNullPtr
//#endif
// C99 Standard
#ifndef nullptr
#define nullptr idNullPtr()
#endif
//#ifndef nullptr
//#define nullptr idNullPtr()
//#endif
#ifndef BIT
#define BIT( num ) ( 1ULL << ( num ) )

View file

@ -394,7 +394,11 @@ public:
ActuallyLoadImage( true );
}
#ifndef USE_VULKAN
return ( void* )( intptr_t )texnum;
#else
return ( void* )( intptr_t )garbageIndex;
#endif
}
// DG end

View file

@ -610,11 +610,11 @@ CONSOLE_COMMAND( Vulkan_PrintHeapInfo, "Print out the heap information for this
{
VkPhysicalDeviceMemoryProperties& props = vkcontext.gpu->memProps;
idLib::Printf( "Heaps %lu\n------------------------\n", props.memoryHeapCount );
idLib::Printf( "Heaps %u\n------------------------\n", props.memoryHeapCount );
for( uint32 i = 0; i < props.memoryHeapCount; ++i )
{
VkMemoryHeap heap = props.memoryHeaps[ i ];
idLib::Printf( "id=%d, size=%llu, flags=", i, heap.size );
idLib::Printf( "id=%d, size=%lu, flags=", i, heap.size );
if( heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT )
{
idLib::Printf( "DEVICE_LOCAL" );
@ -657,11 +657,11 @@ CONSOLE_COMMAND( Vulkan_PrintHeapInfo, "Print out the heap information for this
if( properties.Length() > 0 )
{
idLib::Printf( "memory_type=%lu\n", j );
idLib::Printf( properties.c_str() );
idLib::Printf( "memory_type=%u\n", j );
idLib::Printf( "%s", properties.c_str() );
}
}
idLib::Printf( "\n" );
}
}
}

View file

@ -31,6 +31,10 @@ If you have questions concerning this license or the applicable additional terms
#pragma hdrstop
#include "precompiled.h"
#ifdef __linux__
#include "../../sys/posix/posix_public.h"
#endif
#include "../RenderCommon.h"
#include "../RenderBackend.h"
#include "Staging_VK.h"
@ -53,7 +57,7 @@ static const int g_numInstanceExtensions = 2;
static const char* g_instanceExtensions[ g_numInstanceExtensions ] =
{
VK_KHR_SURFACE_EXTENSION_NAME,
VK_KHR_WIN32_SURFACE_EXTENSION_NAME
VK_KHR_XCB_SURFACE_EXTENSION_NAME
};
static const int g_numDebugInstanceExtensions = 1;
@ -301,6 +305,8 @@ static void EnumeratePhysicalDevices()
uint32 numDevices = 0;
ID_VK_CHECK( vkEnumeratePhysicalDevices( vkcontext.instance, &numDevices, NULL ) );
ID_VK_VALIDATE( numDevices > 0, "vkEnumeratePhysicalDevices returned zero devices." );
idLib::Printf("found %u devices\n", numDevices);
idList< VkPhysicalDevice > devices;
devices.SetNum( numDevices );
@ -312,11 +318,15 @@ static void EnumeratePhysicalDevices()
for( uint32 i = 0; i < numDevices; ++i )
{
idLib::Printf("Iterating over gpu %u\n", i);
gpuInfo_t& gpu = vkcontext.gpus[ i ];
idLib::Printf("have gpuInfo_t ref at %p\n", &vkcontext.gpus[i]);
gpu.device = devices[ i ];
idLib::Printf("set gpu.device\n");
// get Queue family properties
{
idLib::Printf("Getting queue family props...\n");
uint32 numQueues = 0;
vkGetPhysicalDeviceQueueFamilyProperties( gpu.device, &numQueues, NULL );
ID_VK_VALIDATE( numQueues > 0, "vkGetPhysicalDeviceQueueFamilyProperties returned zero queues." );
@ -328,6 +338,7 @@ static void EnumeratePhysicalDevices()
// grab available Vulkan extensions
{
idLib::Printf("Getting available vulkan extensions...\n");
uint32 numExtension;
ID_VK_CHECK( vkEnumerateDeviceExtensionProperties( gpu.device, NULL, &numExtension, NULL ) );
ID_VK_VALIDATE( numExtension > 0, "vkEnumerateDeviceExtensionProperties returned zero extensions." );
@ -422,10 +433,11 @@ static void CreateSurface()
VkXcbSurfaceCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.connection = info.connection;
createInfo.window = info.window;
ID_VK_CHECK( vkCreateXcbSurfaceKHR( info.inst, &createInfo, NULL, &info.surface ) );
ID_VK_CHECK( vkCreateXcbSurfaceKHR( vkcontext.instance, &createInfo, NULL, &vkcontext.surface ) );
#endif // _WIN32
@ -540,22 +552,22 @@ static void SelectPhysicalDevice()
switch( gpu.props.vendorID )
{
case 0x8086:
idLib::Printf( "Vendor: Intel\n", i );
idLib::Printf( "Vendor: Intel\n");
glConfig.vendor = VENDOR_INTEL;
break;
case 0x10DE:
idLib::Printf( "Vendor: NVIDIA\n", i );
idLib::Printf( "Vendor: NVIDIA\n");
glConfig.vendor = VENDOR_NVIDIA;
break;
case 0x1002:
idLib::Printf( "Vendor: AMD\n", i );
idLib::Printf( "Vendor: AMD\n");
glConfig.vendor = VENDOR_AMD;
break;
default:
idLib::Printf( "Vendor: Unknown (0x%x)\n", i, gpu.props.vendorID );
idLib::Printf( "Vendor: Unknown (0x%x)\n", gpu.props.vendorID );
}
return;
@ -1276,30 +1288,38 @@ void idRenderBackend::Init()
glConfig.driverType = GLDRV_VULKAN;
glConfig.gpuSkinningAvailable = true;
idLib::Printf( "Creating Vulkan Instance...\n" );
// create the Vulkan instance and enable validation layers
CreateVulkanInstance();
// create the windowing interface
#ifdef _WIN32
//#ifdef _WIN32
idLib::Printf( "Creating Vulkan Surface...\n" );
CreateSurface();
#endif
//#endif
// Enumerate physical devices and get their properties
idLib::Printf( "Enumerating physical devices and their properties...\n" );
EnumeratePhysicalDevices();
// Find queue family/families supporting graphics and present.
idLib::Printf( "Selecting physical device...\n" );
SelectPhysicalDevice();
// Create logical device and queues
idLib::Printf( "Creating logical device and queues...\n" );
CreateLogicalDeviceAndQueues();
// Create semaphores for image acquisition and rendering completion
idLib::Printf( "Creating semaphores...\n" );
CreateSemaphores();
// Create Command Pool
idLib::Printf( "Creating command pool...\n" );
CreateCommandPool();
// Create Command Buffer
idLib::Printf( "Creating command buffer...\n" );
CreateCommandBuffer();
// setup the allocator
@ -1319,21 +1339,27 @@ void idRenderBackend::Init()
#endif
// Start the Staging Manager
idLib::Printf( "Creating staging manager...\n" );
stagingManager.Init();
// Create Swap Chain
idLib::Printf( "Creating swapchain...\n" );
CreateSwapChain();
// Create Render Targets
idLib::Printf( "Creating render targets...\n" );
CreateRenderTargets();
// Create Render Pass
idLib::Printf( "Creating render pass...\n" );
CreateRenderPass();
// Create Pipeline Cache
idLib::Printf( "Creating pipeline cache...\n" );
CreatePipelineCache();
// Create Frame Buffers
idLib::Printf( "Creating frame buffers...\n" );
CreateFrameBuffers();
// init RenderProg Manager
@ -2355,4 +2381,11 @@ void Framebuffer::Check()
void Framebuffer::CheckFramebuffers()
{
// TODO
}
}
void idRenderBackend::ImGui_RenderDrawLists( ImDrawData* draw_data )
{
// TODO
renderProgManager.Unbind();
}

View file

@ -343,8 +343,8 @@ CompileGLSLtoSPIRV
#include <glslang/public/ShaderLang.h>
#include <glslang/Include/ResourceLimits.h>
#include <SPIRV/GlslangToSpv.h>
#include <StandAlone/DirStackFileIncluder.h>
#include <glslang/SPIRV/GlslangToSpv.h>
//#include <glslang/StandAlone/DirStackFileIncluder.h>
namespace glslang
{
@ -352,7 +352,7 @@ namespace glslang
// These are the default resources for TBuiltInResources, used for both
// - parsing this string for the case where the user didn't supply one,
// - dumping out a template for user construction of a config file.
#if 0
#if 1
extern const TBuiltInResource DefaultTBuiltInResource;
#else
const TBuiltInResource DefaultTBuiltInResource =

View file

@ -32,7 +32,8 @@ If you have questions concerning this license or the applicable additional terms
#if defined( USE_VULKAN )
#define VK_USE_PLATFORM_WIN32_KHR
//#define VK_USE_PLATFORM_XLIB_KHR
#define VK_USE_PLATFORM_XCB_KHR
#define USE_AMD_ALLOCATOR
#include <vulkan/vulkan.h>
@ -64,4 +65,4 @@ static const int MAX_UBO_PARMS = 2;
#endif
#endif
#endif

View file

@ -766,6 +766,7 @@ remove them if not needed.
#include <cassert> // for assert
#include <algorithm> // for min, max
#include <mutex> // for std::mutex
#include <string.h>
#if !defined(_WIN32)
#include <malloc.h> // for aligned_alloc()

View file

@ -29,6 +29,9 @@ If you have questions concerning this license or the applicable additional terms
#ifndef __SWF_SPRITES_H__
#define __SWF_SPRITES_H__
#undef Bool
#include "rapidjson/document.h"
/*
================================================
What the swf file format calls a "sprite" is known as a "movie clip" in Flash

View file

@ -49,6 +49,10 @@ static int cmdargc = 0;
#include <mcheck.h>
#endif
#ifdef USE_VULKAN
#include <xcb/xcb.h>
#endif
/*
==============
Sys_EXEPath
@ -509,6 +513,61 @@ void Sys_ReLaunch()
// DG end
}
#ifdef USE_VULKAN
/* Declare the global posixInfo */
posixInfo info;
static void createWindow(size_t winWidth, size_t winHeight)
{
/* establish the connection with DISPLAYNAME as NULL,
* this will leverage the DISPLAY env var */
int screenp = 0; /* which "screen" to use */
info.connection = xcb_connect(NULL, &screenp);
/* Check for errors */
int xcbErr = xcb_connection_has_error(info.connection);
if (xcbErr) {
common->Printf("Failed to connect to X server using XCB.");
exit(-1);
}
/* Setup the window, iterating through screens */
const struct xcb_setup_t *xcbSetup = NULL;
xcbSetup = xcb_get_setup(info.connection);
xcb_screen_iterator_t scrIter = xcb_setup_roots_iterator(xcbSetup);
for (int screen = screenp; screen > 0; --screen) {
xcb_screen_next(&scrIter);
}
info.screen = scrIter.data;
/* Now generate the xid used for our window */
info.window = xcb_generate_id(info.connection);
/* Register events, creating background pixel */
uint32_t eventMask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
uint32_t valueList[] = { info.screen->black_pixel, 0 };
/* Create the window, finally */
xcb_create_window(info.connection, XCB_COPY_FROM_PARENT, info.window,
info.screen->root, 0, 0, winWidth, winHeight, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, info.screen->root_visual,
eventMask, valueList);
/* Set some properties, such as the window name, maybe? */
xcb_change_property(info.connection, XCB_PROP_MODE_REPLACE,
info.window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING,
8, 7, "vkDOOM3");
/* map the window to the screen and flush the stream to the server */
xcb_map_window(info.connection, info.window);
xcb_flush(info.connection);
}
#endif
/*
===============
main
@ -525,7 +584,14 @@ int main( int argc, const char** argv )
mcheck( abrt_func );
Sys_Printf( "memory consistency checking enabled\n" );
#endif
#ifdef USE_VULKAN
/* Create the window if using Vulkan */
xcb_generic_event_t *event;
xcb_client_message_event_t *cm;
createWindow(1920, 1080);
#endif
Posix_EarlyInit( );
if( argc > 1 )
@ -538,9 +604,17 @@ int main( int argc, const char** argv )
}
Posix_LateInit( );
while( 1 )
{
#ifdef USE_VULKAN
/* I'm not 100% sure if intercepting these xcb events interferes with
* SDL's input handling or not, but I suspect that it's necessary
* to pump some event loop. We'll see */
/*event = xcb_wait_for_event(info.connection);
free(event); */
#endif
common->Frame();
}
}

View file

@ -31,6 +31,10 @@ If you have questions concerning this license or the applicable additional terms
#include <signal.h>
#ifdef USE_VULKAN
#include <xcb/xcb.h>
#endif
void Posix_QueEvent( sysEventType_t type, int value, int value2, int ptrLength, void* ptr );
const char* Posix_Cwd();
@ -66,5 +70,19 @@ enum clk_id_t { CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW };
int clock_gettime( clk_id_t clock, struct timespec* tp );
#endif
#ifdef USE_VULKAN
/* Struct that holds global xcb state for vulkan */
typedef struct _posixInfo {
xcb_connection_t *connection;
xcb_window_t window;
xcb_screen_t *screen;
xcb_atom_t wmProtocols;
xcb_atom_t wmDeleteWin;
} posixInfo;
extern posixInfo info;
#endif
#endif

View file

@ -30,6 +30,7 @@ If you have questions concerning this license or the applicable additional terms
*/
#include "../../idlib/precompiled.h"
#include <GL/glew.h>
// DG: SDL.h somehow needs the following functions, so #undef those silly
// "don't use" #defines from Str.h
@ -98,6 +99,10 @@ GLimp_Init
*/
bool GLimp_Init( glimpParms_t parms )
{
#ifdef USE_VULKAN
return true;
#endif
common->Printf( "Initializing OpenGL subsystem\n" );
GLimp_PreInit(); // DG: make sure SDL is initialized
@ -439,6 +444,10 @@ GLimp_SetScreenParms
*/
bool GLimp_SetScreenParms( glimpParms_t parms )
{
#ifdef USE_VULKAN
return true;
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( parms.fullScreen > 0 || parms.fullScreen == -2 )
{
@ -506,7 +515,12 @@ GLimp_Shutdown
*/
void GLimp_Shutdown()
{
#ifdef USE_VULKAN
common->Printf( "Shutting down Vulkan subsystem\n" );
return;
#else
common->Printf( "Shutting down OpenGL subsystem\n" );
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( context )
@ -528,6 +542,7 @@ void GLimp_Shutdown()
GLimp_SwapBuffers
===================
*/
#ifndef USE_VULKAN
void GLimp_SwapBuffers()
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
@ -536,6 +551,7 @@ void GLimp_SwapBuffers()
SDL_GL_SwapBuffers();
#endif
}
#endif
/*
=================
@ -544,6 +560,7 @@ GLimp_SetGamma
*/
void GLimp_SetGamma( unsigned short red[256], unsigned short green[256], unsigned short blue[256] )
{
#ifndef USE_VULKAN
if( !window )
{
common->Warning( "GLimp_SetGamma called without window" );
@ -556,6 +573,7 @@ void GLimp_SetGamma( unsigned short red[256], unsigned short green[256], unsigne
if( SDL_SetGammaRamp( red, green, blue ) )
#endif
common->Warning( "Couldn't set gamma ramp: %s", SDL_GetError() );
#endif
}
/*