From 1b865406c0b4356846238e40af1d61b3027e1098 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 6 Jan 2022 15:31:02 -0500 Subject: [PATCH] Add support for Apple GPUs (e.g. M1) and fill-in gfxInfo data for Vulkan renderer (cherry picked from commit 22f38cef0bbc3997c24990b5ee0f16c05e10de53) --- neo/renderer/OpenGL/RenderBackend_GL.cpp | 5 +++ neo/renderer/RenderSystem.h | 3 +- neo/renderer/Vulkan/RenderBackend_VK.cpp | 47 ++++++++++++++++++++---- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/neo/renderer/OpenGL/RenderBackend_GL.cpp b/neo/renderer/OpenGL/RenderBackend_GL.cpp index 6ce158e2..6d17ea7c 100644 --- a/neo/renderer/OpenGL/RenderBackend_GL.cpp +++ b/neo/renderer/OpenGL/RenderBackend_GL.cpp @@ -206,6 +206,11 @@ static void R_CheckPortableExtensions() { glConfig.vendor = VENDOR_INTEL; } + // SRS - Added support for Apple GPUs + else if( idStr::Icmpn( glConfig.renderer_string, "Apple", 5 ) == 0 ) + { + glConfig.vendor = VENDOR_APPLE; + } // RB: Mesa support if( idStr::Icmpn( glConfig.renderer_string, "Mesa", 4 ) == 0 || idStr::Icmpn( glConfig.renderer_string, "X.org", 5 ) == 0 || idStr::Icmpn( glConfig.renderer_string, "Gallium", 7 ) == 0 || diff --git a/neo/renderer/RenderSystem.h b/neo/renderer/RenderSystem.h index 88fcfa18..a1611602 100644 --- a/neo/renderer/RenderSystem.h +++ b/neo/renderer/RenderSystem.h @@ -83,7 +83,8 @@ enum graphicsVendor_t { VENDOR_NVIDIA, VENDOR_AMD, - VENDOR_INTEL + VENDOR_INTEL, + VENDOR_APPLE // SRS - Added support for Apple GPUs }; // RB: similar to Q3A - allow separate codepaths between OpenGL 3.x, OpenGL ES versions diff --git a/neo/renderer/Vulkan/RenderBackend_VK.cpp b/neo/renderer/Vulkan/RenderBackend_VK.cpp index b858bc46..29b122be 100644 --- a/neo/renderer/Vulkan/RenderBackend_VK.cpp +++ b/neo/renderer/Vulkan/RenderBackend_VK.cpp @@ -418,6 +418,11 @@ static void EnumeratePhysicalDevices() idLib::Printf( "Found device[%i] Vendor: AMD\n", i ); break; + // SRS - Added support for Apple GPUs + case 0x106B: + idLib::Printf( "Found device[%i] Vendor: Apple\n", i ); + break; + default: idLib::Printf( "Found device[%i] Vendor: Unknown (0x%x)\n", i, gpu.props.vendorID ); } @@ -661,24 +666,49 @@ static void SelectPhysicalDevice() switch( gpu.props.vendorID ) { case 0x8086: - idLib::Printf( "Device[%i] : Vendor: Intel \n", i ); + idLib::Printf( "Device[%i] : Vendor: Intel\n", i ); glConfig.vendor = VENDOR_INTEL; + glConfig.vendor_string = "Intel Inc."; break; case 0x10DE: idLib::Printf( "Device[%i] : Vendor: NVIDIA\n", i ); glConfig.vendor = VENDOR_NVIDIA; + glConfig.vendor_string = "NVIDIA Corporation"; break; case 0x1002: idLib::Printf( "Device[%i] : Vendor: AMD\n", i ); glConfig.vendor = VENDOR_AMD; + glConfig.vendor_string = "ATI Technologies Inc."; break; + // SRS - Added support for Apple GPUs + case 0x106B: + idLib::Printf( "Found device[%i] Vendor: Apple\n", i ); + glConfig.vendor = VENDOR_APPLE; + glConfig.vendor_string = "Apple"; + break; + default: idLib::Printf( "Device[%i] : Vendor: Unknown (0x%x)\n", i, gpu.props.vendorID ); } + glConfig.renderer_string = gpu.props.deviceName; + + static char version_string[24]; + sprintf( version_string, "Vulkan %i.%i.%i", VK_API_VERSION_MAJOR(gpu.props.apiVersion), VK_API_VERSION_MINOR(gpu.props.apiVersion), VK_API_VERSION_PATCH(gpu.props.apiVersion) ); + glConfig.version_string = version_string; + + static idStr extensions_string; + extensions_string.Clear(); + for( int i = 0; i < gpu.extensionProps.Num(); i++ ) + { + extensions_string.Append( gpu.extensionProps[i].extensionName ); + extensions_string.Append( ' ' ); + } + glConfig.extensions_string = extensions_string.c_str(); + return; } } @@ -1990,7 +2020,14 @@ void idRenderBackend::GL_StartFrame() { vkGetQueryPoolResults( vkcontext.device, queryPool, MRB_GPU_TIME, numQueries, results.ByteSize(), results.Ptr(), sizeof( uint64 ), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT ); - +#if defined(__APPLE__) + // SRS - When using Metal-derived timestamps on OSX, update timestampPeriod every frame based on ongoing calibration within MoltenVK + // Only need to do this for non-Apple GPUs, for Apple GPUs timestampPeriod = 1 and ongoing calibration within MoltenVK is skipped + if( vkcontext.gpu->props.vendorID != 0x106B ) + { + vkGetPhysicalDeviceProperties( vkcontext.gpu->device, &vkcontext.gpu->props ); + } +#endif const uint64 gpuStart = results[ assignedIndex[ MRB_GPU_TIME * 2 + 0 ] ]; const uint64 gpuEnd = results[ assignedIndex[ MRB_GPU_TIME * 2 + 1 ] ]; const uint64 tick = ( 1000 * 1000 * 1000 ) / vkcontext.gpu->props.limits.timestampPeriod; @@ -2000,7 +2037,6 @@ void idRenderBackend::GL_StartFrame() { const uint64 gpuStart = results[ assignedIndex[ MRB_FILL_DEPTH_BUFFER * 2 + 0 ] ]; const uint64 gpuEnd = results[ assignedIndex[ MRB_FILL_DEPTH_BUFFER * 2 + 1 ] ]; - const uint64 tick = ( 1000 * 1000 * 1000 ) / vkcontext.gpu->props.limits.timestampPeriod; pc.gpuDepthMicroSec = ( ( gpuEnd - gpuStart ) * 1000 * 1000 ) / tick; } @@ -2008,7 +2044,6 @@ void idRenderBackend::GL_StartFrame() { const uint64 gpuStart = results[ assignedIndex[ MRB_SSAO_PASS * 2 + 0 ] ]; const uint64 gpuEnd = results[ assignedIndex[ MRB_SSAO_PASS * 2 + 1 ] ]; - const uint64 tick = ( 1000 * 1000 * 1000 ) / vkcontext.gpu->props.limits.timestampPeriod; pc.gpuScreenSpaceAmbientOcclusionMicroSec = ( ( gpuEnd - gpuStart ) * 1000 * 1000 ) / tick; } @@ -2016,7 +2051,6 @@ void idRenderBackend::GL_StartFrame() { const uint64 gpuStart = results[ assignedIndex[ MRB_AMBIENT_PASS * 2 + 0 ] ]; const uint64 gpuEnd = results[ assignedIndex[ MRB_AMBIENT_PASS * 2 + 1 ] ]; - const uint64 tick = ( 1000 * 1000 * 1000 ) / vkcontext.gpu->props.limits.timestampPeriod; pc.gpuAmbientPassMicroSec = ( ( gpuEnd - gpuStart ) * 1000 * 1000 ) / tick; } @@ -2024,7 +2058,6 @@ void idRenderBackend::GL_StartFrame() { const uint64 gpuStart = results[ assignedIndex[ MRB_DRAW_INTERACTIONS * 2 + 0 ] ]; const uint64 gpuEnd = results[ assignedIndex[ MRB_DRAW_INTERACTIONS * 2 + 1 ] ]; - const uint64 tick = ( 1000 * 1000 * 1000 ) / vkcontext.gpu->props.limits.timestampPeriod; pc.gpuInteractionsMicroSec = ( ( gpuEnd - gpuStart ) * 1000 * 1000 ) / tick; } @@ -2032,7 +2065,6 @@ void idRenderBackend::GL_StartFrame() { const uint64 gpuStart = results[ assignedIndex[ MRB_DRAW_SHADER_PASSES * 2 + 0 ] ]; const uint64 gpuEnd = results[ assignedIndex[ MRB_DRAW_SHADER_PASSES * 2 + 1 ] ]; - const uint64 tick = ( 1000 * 1000 * 1000 ) / vkcontext.gpu->props.limits.timestampPeriod; pc.gpuShaderPassMicroSec = ( ( gpuEnd - gpuStart ) * 1000 * 1000 ) / tick; } @@ -2040,7 +2072,6 @@ void idRenderBackend::GL_StartFrame() { const uint64 gpuStart = results[ assignedIndex[ MRB_POSTPROCESS * 2 + 0 ] ]; const uint64 gpuEnd = results[ assignedIndex[ MRB_POSTPROCESS * 2 + 1 ] ]; - const uint64 tick = ( 1000 * 1000 * 1000 ) / vkcontext.gpu->props.limits.timestampPeriod; pc.gpuPostProcessingMicroSec = ( ( gpuEnd - gpuStart ) * 1000 * 1000 ) / tick; } }