Refactored DeviceManager_DX12 members for better diffing with orig Donut sample

This commit is contained in:
Robert Beckebans 2023-03-06 17:05:43 +01:00
parent d765afa278
commit b4b025979d
6 changed files with 164 additions and 188 deletions

View file

@ -363,7 +363,7 @@ void idImage::AllocImage()
case FMT_DEPTH_STENCIL:
// SRS - Check if D24S8 is supported, otherwise fall back to D32S8
if( deviceManager->deviceParms.enableImageFormatD24S8 )
if( deviceManager->m_DeviceParams.enableImageFormatD24S8 )
{
format = nvrhi::Format::D24S8;
}

View file

@ -30,8 +30,8 @@ DeviceManager* DeviceManager::Create( nvrhi::GraphicsAPI api )
void DeviceManager::GetWindowDimensions( int& width, int& height )
{
width = deviceParms.backBufferWidth;
height = deviceParms.backBufferHeight;
width = m_DeviceParams.backBufferWidth;
height = m_DeviceParams.backBufferHeight;
}
void DeviceManager::BackBufferResizing()
@ -49,7 +49,7 @@ void DeviceManager::BackBufferResized()
const DeviceCreationParameters& DeviceManager::GetDeviceParams()
{
return deviceParms;
return m_DeviceParams;
}
nvrhi::IFramebuffer* DeviceManager::GetCurrentFramebuffer()
@ -67,18 +67,6 @@ nvrhi::IFramebuffer* DeviceManager::GetFramebuffer( uint32_t index )
return nullptr;
}
void DeviceManager::AddRenderPassToBack( IRenderPass* pRenderPass )
{
renderPasses.Remove( pRenderPass );
renderPasses.Append( pRenderPass );
pRenderPass->BackBufferResizing();
pRenderPass->BackBufferResized(
deviceParms.backBufferWidth,
deviceParms.backBufferHeight,
deviceParms.swapChainSampleCount );
}
DeviceManager* DeviceManager::CreateD3D11()
{
return nullptr;

View file

@ -1,30 +1,23 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2022 Stephen Pridham
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
* Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved.
*
* 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 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.
*/
#ifndef SYS_DEVICE_MANAGER_H_
@ -122,7 +115,6 @@ struct DefaultMessageCallback : public nvrhi::IMessageCallback
void message( nvrhi::MessageSeverity severity, const char* messageText ) override;
};
class IRenderPass;
class idRenderBackend;
@ -145,8 +137,8 @@ public:
// returns the screen coordinate to pixel coordinate scale factor
void GetDPIScaleInfo( float& x, float& y ) const
{
x = dpiScaleFactorX;
y = dpiScaleFactorY;
x = m_DPIScaleFactorX;
y = m_DPIScaleFactorY;
}
void UpdateWindowSize( const glimpParms_t& params );
@ -157,19 +149,17 @@ protected:
void* windowInstance;
void* windowHandle;
bool windowVisible = false;
bool m_windowVisible = false;
bool isNvidia = false;
DeviceCreationParameters deviceParms;
DeviceCreationParameters m_DeviceParams;
float dpiScaleFactorX = 1.f;
float dpiScaleFactorY = 1.f;
bool requestedVSync = false;
float m_DPIScaleFactorX = 1.f;
float m_DPIScaleFactorY = 1.f;
bool m_RequestedVSync = false;
uint32_t m_FrameIndex = 0;
idList<IRenderPass*> renderPasses;
DeviceManager() = default;
void BackBufferResizing();
@ -191,7 +181,7 @@ public:
const DeviceCreationParameters& GetDeviceParams();
virtual void SetVsyncEnabled( bool enabled )
{
requestedVSync = enabled; /* will be processed later */
m_RequestedVSync = enabled; /* will be processed later */
}
virtual void ReportLiveObjects() {}
@ -208,8 +198,6 @@ public:
nvrhi::IFramebuffer* GetCurrentFramebuffer();
nvrhi::IFramebuffer* GetFramebuffer( uint32_t index );
void AddRenderPassToBack( IRenderPass* pRenderPass );
void Shutdown();
virtual ~DeviceManager() = default;

View file

@ -53,7 +53,7 @@ class DeviceManager_DX12 : public DeviceManager
RefCountPtr<ID3D12CommandQueue> m_CopyQueue;
RefCountPtr<IDXGISwapChain3> m_SwapChain;
DXGI_SWAP_CHAIN_DESC1 m_SwapChainDesc{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullScreenDesc{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC m_FullScreenDesc{};
RefCountPtr<IDXGIAdapter> m_DxgiAdapter;
bool m_TearingSupported = false;
@ -64,19 +64,19 @@ class DeviceManager_DX12 : public DeviceManager
UINT64 m_FrameCount = 1;
nvrhi::DeviceHandle nvrhiDevice;
nvrhi::DeviceHandle m_NvrhiDevice;
std::string renderString;
std::string m_RendererString;
public:
const char* GetRendererString() const override
{
return renderString.c_str();
return m_RendererString.c_str();
}
nvrhi::IDevice* GetDevice() const override
{
return nvrhiDevice;
return m_NvrhiDevice;
}
void ReportLiveObjects() override;
@ -224,9 +224,9 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
{
RefCountPtr<IDXGIAdapter> targetAdapter;
if( deviceParms.adapter )
if( m_DeviceParams.adapter )
{
targetAdapter = deviceParms.adapter;
targetAdapter = m_DeviceParams.adapter;
}
else
{
@ -237,12 +237,12 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
}
else
{
targetAdapter = FindAdapter( deviceParms.adapterNameSubstring );
targetAdapter = FindAdapter( m_DeviceParams.adapterNameSubstring );
}
if( !targetAdapter )
{
std::wstring adapterNameStr( deviceParms.adapterNameSubstring.begin(), deviceParms.adapterNameSubstring.end() );
std::wstring adapterNameStr( m_DeviceParams.adapterNameSubstring.begin(), m_DeviceParams.adapterNameSubstring.end() );
common->FatalError( "Could not find an adapter matching %s\n", adapterNameStr.c_str() );
return false;
}
@ -261,7 +261,7 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
{
ss << wss.narrow( c, '?' );
}
renderString = ss.str();
m_RendererString = ss.str();
isNvidia = IsNvDeviceID( aDesc.VendorId );
}
@ -269,18 +269,18 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
// SRS - Don't center window here for DX12 only, instead use portable initialization in CreateWindowDeviceAndSwapChain() within win_glimp.cpp
// - Also, calling SetWindowPos() triggers a window mgr event that overwrites r_windowX / r_windowY, which may be undesirable to the user
UINT windowStyle = deviceParms.startFullscreen
UINT windowStyle = m_DeviceParams.startFullscreen
? ( WS_POPUP | WS_SYSMENU | WS_VISIBLE )
: deviceParms.startMaximized
: m_DeviceParams.startMaximized
? ( WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_MAXIMIZE )
: ( WS_OVERLAPPEDWINDOW | WS_VISIBLE );
RECT rect = { 0, 0, LONG( deviceParms.backBufferWidth ), LONG( deviceParms.backBufferHeight ) };
RECT rect = { 0, 0, LONG( m_DeviceParams.backBufferWidth ), LONG( m_DeviceParams.backBufferHeight ) };
AdjustWindowRect( &rect, windowStyle, FALSE );
if( MoveWindowOntoAdapter( targetAdapter, rect ) )
{
SetWindowPos( ( HWND )windowHandle, deviceParms.startFullscreen ? HWND_TOPMOST : HWND_NOTOPMOST,
SetWindowPos( ( HWND )windowHandle, m_DeviceParams.startFullscreen ? HWND_TOPMOST : HWND_NOTOPMOST,
rect.left, rect.top, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE );
}
*/
@ -294,17 +294,17 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
ZeroMemory( &m_SwapChainDesc, sizeof( m_SwapChainDesc ) );
m_SwapChainDesc.Width = width;
m_SwapChainDesc.Height = height;
m_SwapChainDesc.SampleDesc.Count = deviceParms.swapChainSampleCount;
m_SwapChainDesc.SampleDesc.Count = m_DeviceParams.swapChainSampleCount;
m_SwapChainDesc.SampleDesc.Quality = 0;
m_SwapChainDesc.BufferUsage = deviceParms.swapChainUsage;
m_SwapChainDesc.BufferCount = deviceParms.swapChainBufferCount;
m_SwapChainDesc.BufferUsage = m_DeviceParams.swapChainUsage;
m_SwapChainDesc.BufferCount = m_DeviceParams.swapChainBufferCount;
m_SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
m_SwapChainDesc.Flags = deviceParms.allowModeSwitch ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
m_SwapChainDesc.Flags = m_DeviceParams.allowModeSwitch ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
// Special processing for sRGB swap chain formats.
// DXGI will not create a swap chain with an sRGB format, but its contents will be interpreted as sRGB.
// So we need to use a non-sRGB format here, but store the true sRGB format for later framebuffer creation.
switch( deviceParms.swapChainFormat ) // NOLINT(clang-diagnostic-switch-enum)
switch( m_DeviceParams.swapChainFormat ) // NOLINT(clang-diagnostic-switch-enum)
{
case nvrhi::Format::SRGBA8_UNORM:
m_SwapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
@ -313,11 +313,11 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
m_SwapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
break;
default:
m_SwapChainDesc.Format = nvrhi::d3d12::convertFormat( deviceParms.swapChainFormat );
m_SwapChainDesc.Format = nvrhi::d3d12::convertFormat( m_DeviceParams.swapChainFormat );
break;
}
if( deviceParms.enableDebugRuntime )
if( m_DeviceParams.enableDebugRuntime )
{
RefCountPtr<ID3D12Debug> pDebug;
hr = D3D12GetDebugInterface( IID_PPV_ARGS( &pDebug ) );
@ -326,7 +326,7 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
}
RefCountPtr<IDXGIFactory2> pDxgiFactory;
UINT dxgiFactoryFlags = deviceParms.enableDebugRuntime ? DXGI_CREATE_FACTORY_DEBUG : 0;
UINT dxgiFactoryFlags = m_DeviceParams.enableDebugRuntime ? DXGI_CREATE_FACTORY_DEBUG : 0;
hr = CreateDXGIFactory2( dxgiFactoryFlags, IID_PPV_ARGS( &pDxgiFactory ) );
HR_RETURN( hr );
@ -347,11 +347,11 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
hr = D3D12CreateDevice(
targetAdapter,
deviceParms.featureLevel,
m_DeviceParams.featureLevel,
IID_PPV_ARGS( &m_Device12 ) );
HR_RETURN( hr );
if( deviceParms.enableDebugRuntime )
if( m_DeviceParams.enableDebugRuntime )
{
RefCountPtr<ID3D12InfoQueue> pInfoQueue;
m_Device12->QueryInterface( &pInfoQueue );
@ -387,7 +387,7 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
HR_RETURN( hr );
m_GraphicsQueue->SetName( L"Graphics Queue" );
if( deviceParms.enableComputeQueue )
if( m_DeviceParams.enableComputeQueue )
{
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE;
hr = m_Device12->CreateCommandQueue( &queueDesc, IID_PPV_ARGS( &m_ComputeQueue ) );
@ -395,7 +395,7 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
m_ComputeQueue->SetName( L"Compute Queue" );
}
if( deviceParms.enableCopyQueue )
if( m_DeviceParams.enableCopyQueue )
{
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_COPY;
hr = m_Device12->CreateCommandQueue( &queueDesc, IID_PPV_ARGS( &m_CopyQueue ) );
@ -403,15 +403,15 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
m_CopyQueue->SetName( L"Copy Queue" );
}
fullScreenDesc = {};
fullScreenDesc.RefreshRate.Numerator = deviceParms.refreshRate;
fullScreenDesc.RefreshRate.Denominator = 1;
fullScreenDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
fullScreenDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
fullScreenDesc.Windowed = !deviceParms.startFullscreen;
m_FullScreenDesc = {};
m_FullScreenDesc.RefreshRate.Numerator = m_DeviceParams.refreshRate;
m_FullScreenDesc.RefreshRate.Denominator = 1;
m_FullScreenDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
m_FullScreenDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
m_FullScreenDesc.Windowed = !m_DeviceParams.startFullscreen;
RefCountPtr<IDXGISwapChain1> pSwapChain1;
hr = pDxgiFactory->CreateSwapChainForHwnd( m_GraphicsQueue, ( HWND )windowHandle, &m_SwapChainDesc, &fullScreenDesc, nullptr, &pSwapChain1 );
hr = pDxgiFactory->CreateSwapChainForHwnd( m_GraphicsQueue, ( HWND )windowHandle, &m_SwapChainDesc, &m_FullScreenDesc, nullptr, &pSwapChain1 );
HR_RETURN( hr );
hr = pSwapChain1->QueryInterface( IID_PPV_ARGS( &m_SwapChain ) );
@ -424,14 +424,14 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
deviceDesc.pComputeCommandQueue = m_ComputeQueue;
deviceDesc.pCopyCommandQueue = m_CopyQueue;
nvrhiDevice = nvrhi::d3d12::createDevice( deviceDesc );
m_NvrhiDevice = nvrhi::d3d12::createDevice( deviceDesc );
deviceParms.enableNvrhiValidationLayer = r_useValidationLayers.GetInteger() > 0;
deviceParms.enableDebugRuntime = r_useValidationLayers.GetInteger() > 1;
m_DeviceParams.enableNvrhiValidationLayer = r_useValidationLayers.GetInteger() > 0;
m_DeviceParams.enableDebugRuntime = r_useValidationLayers.GetInteger() > 1;
if( deviceParms.enableNvrhiValidationLayer )
if( m_DeviceParams.enableNvrhiValidationLayer )
{
nvrhiDevice = nvrhi::validation::createValidationLayer( nvrhiDevice );
m_NvrhiDevice = nvrhi::validation::createValidationLayer( m_NvrhiDevice );
}
if( !CreateRenderTargets() )
@ -453,11 +453,11 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
void DeviceManager_DX12::DestroyDeviceAndSwapChain()
{
m_RhiSwapChainBuffers.clear();
renderString.clear();
m_RendererString.clear();
ReleaseRenderTargets();
nvrhiDevice = nullptr;
m_NvrhiDevice = nullptr;
for( auto fenceEvent : m_FrameFenceEvents )
{
@ -494,18 +494,18 @@ bool DeviceManager_DX12::CreateRenderTargets()
HR_RETURN( hr );
nvrhi::TextureDesc textureDesc;
textureDesc.width = deviceParms.backBufferWidth;
textureDesc.height = deviceParms.backBufferHeight;
textureDesc.sampleCount = deviceParms.swapChainSampleCount;
textureDesc.sampleQuality = deviceParms.swapChainSampleQuality;
textureDesc.format = deviceParms.swapChainFormat;
textureDesc.width = m_DeviceParams.backBufferWidth;
textureDesc.height = m_DeviceParams.backBufferHeight;
textureDesc.sampleCount = m_DeviceParams.swapChainSampleCount;
textureDesc.sampleQuality = m_DeviceParams.swapChainSampleQuality;
textureDesc.format = m_DeviceParams.swapChainFormat;
textureDesc.debugName = "SwapChainBuffer";
textureDesc.isRenderTarget = true;
textureDesc.isUAV = false;
textureDesc.initialState = nvrhi::ResourceStates::Present;
textureDesc.keepInitialState = true;
m_RhiSwapChainBuffers[n] = nvrhiDevice->createHandleForNativeTexture( nvrhi::ObjectTypes::D3D12_Resource, nvrhi::Object( m_SwapChainBuffers[n] ), textureDesc );
m_RhiSwapChainBuffers[n] = m_NvrhiDevice->createHandleForNativeTexture( nvrhi::ObjectTypes::D3D12_Resource, nvrhi::Object( m_SwapChainBuffers[n] ), textureDesc );
}
return true;
@ -513,16 +513,16 @@ bool DeviceManager_DX12::CreateRenderTargets()
void DeviceManager_DX12::ReleaseRenderTargets()
{
if( !nvrhiDevice )
if( !m_NvrhiDevice )
{
return;
}
// Make sure that all frames have finished rendering
nvrhiDevice->waitForIdle();
m_NvrhiDevice->waitForIdle();
// Release all in-flight references to the render targets
nvrhiDevice->runGarbageCollection();
m_NvrhiDevice->runGarbageCollection();
// Set the events so that WaitForSingleObject in OneFrame will not hang later
for( auto e : m_FrameFenceEvents )
@ -539,7 +539,7 @@ void DeviceManager_DX12::ResizeSwapChain()
{
ReleaseRenderTargets();
if( !nvrhiDevice )
if( !m_NvrhiDevice )
{
return;
}
@ -549,9 +549,9 @@ void DeviceManager_DX12::ResizeSwapChain()
return;
}
const HRESULT hr = m_SwapChain->ResizeBuffers( deviceParms.swapChainBufferCount,
deviceParms.backBufferWidth,
deviceParms.backBufferHeight,
const HRESULT hr = m_SwapChain->ResizeBuffers( m_DeviceParams.swapChainBufferCount,
m_DeviceParams.backBufferWidth,
m_DeviceParams.backBufferHeight,
m_SwapChainDesc.Format,
m_SwapChainDesc.Flags );
@ -569,31 +569,31 @@ void DeviceManager_DX12::ResizeSwapChain()
void DeviceManager_DX12::BeginFrame()
{
/* SRS - This code not needed: framebuffer/swapchain resizing & fullscreen are handled by idRenderBackend::ResizeImages() and DeviceManager::UpdateWindowSize()
DXGI_SWAP_CHAIN_DESC1 newSwapChainDesc;
DXGI_SWAP_CHAIN_FULLSCREEN_DESC newFullScreenDesc;
if( SUCCEEDED( m_SwapChain->GetDesc1( &newSwapChainDesc ) ) && SUCCEEDED( m_SwapChain->GetFullscreenDesc( &newFullScreenDesc ) ) )
//SRS - This code not needed: framebuffer/swapchain resizing & fullscreen are handled by idRenderBackend::ResizeImages() and DeviceManager::UpdateWindowSize()
#if 0
DXGI_SWAP_CHAIN_DESC1 newSwapChainDesc;
DXGI_SWAP_CHAIN_FULLSCREEN_DESC newFullScreenDesc;
if( SUCCEEDED( m_SwapChain->GetDesc1( &newSwapChainDesc ) ) && SUCCEEDED( m_SwapChain->GetFullscreenDesc( &newFullScreenDesc ) ) )
{
if( m_FullScreenDesc.Windowed != newFullScreenDesc.Windowed )
{
if( fullScreenDesc.Windowed != newFullScreenDesc.Windowed )
BackBufferResizing();
m_FullScreenDesc = newFullScreenDesc;
m_SwapChainDesc = newSwapChainDesc;
m_DeviceParams.backBufferWidth = newSwapChainDesc.Width;
m_DeviceParams.backBufferHeight = newSwapChainDesc.Height;
if( newFullScreenDesc.Windowed )
{
BackBufferResizing();
fullScreenDesc = newFullScreenDesc;
m_SwapChainDesc = newSwapChainDesc;
deviceParms.backBufferWidth = newSwapChainDesc.Width;
deviceParms.backBufferHeight = newSwapChainDesc.Height;
if( newFullScreenDesc.Windowed )
{
//glfwSetWindowMonitor( m_Window, nullptr, 50, 50, newSwapChainDesc.Width, newSwapChainDesc.Height, 0 );
}
ResizeSwapChain();
BackBufferResized();
//glfwSetWindowMonitor( m_Window, nullptr, 50, 50, newSwapChainDesc.Width, newSwapChainDesc.Height, 0 );
}
ResizeSwapChain();
BackBufferResized();
}
*/
}
#endif
auto bufferIndex = m_SwapChain->GetCurrentBackBufferIndex();
WaitForSingleObject( m_FrameFenceEvents[bufferIndex], INFINITE );
@ -630,7 +630,7 @@ void DeviceManager_DX12::EndFrame()
void DeviceManager_DX12::Present()
{
if( !windowVisible )
if( !m_windowVisible )
{
return;
}
@ -640,13 +640,13 @@ void DeviceManager_DX12::Present()
UINT presentFlags = 0;
// SRS - DXGI docs say fullscreen must be disabled for unlocked fps/tear, but this does not seem to be true
if( !deviceParms.vsyncEnabled && m_TearingSupported ) //&& !glConfig.isFullscreen )
if( !m_DeviceParams.vsyncEnabled && m_TearingSupported ) //&& !glConfig.isFullscreen )
{
presentFlags |= DXGI_PRESENT_ALLOW_TEARING;
}
// SRS - Don't change deviceParms.vsyncEnabled here, simply test for vsync mode 2 to set DXGI SyncInterval
m_SwapChain->Present( deviceParms.vsyncEnabled && r_swapInterval.GetInteger() == 2 ? 1 : 0, presentFlags );
// SRS - Don't change m_DeviceParams.vsyncEnabled here, simply test for vsync mode 2 to set DXGI SyncInterval
m_SwapChain->Present( m_DeviceParams.vsyncEnabled && r_swapInterval.GetInteger() == 2 ? 1 : 0, presentFlags );
m_FrameFence->SetEventOnCompletion( m_FrameCount, m_FrameFenceEvents[bufferIndex] );
m_GraphicsQueue->Signal( m_FrameFence, m_FrameCount );

View file

@ -294,7 +294,7 @@ private:
if( manager )
{
const auto& ignored = manager->deviceParms.ignoredVulkanValidationMessageLocations;
const auto& ignored = manager->m_DeviceParams.ignoredVulkanValidationMessageLocations;
const auto found = std::find( ignored.begin(), ignored.end(), location );
if( found != ignored.end() )
{
@ -365,21 +365,21 @@ bool DeviceManager_VK::createInstance()
#endif
// add instance extensions requested by the user
for( const std::string& name : deviceParms.requiredVulkanInstanceExtensions )
for( const std::string& name : m_DeviceParams.requiredVulkanInstanceExtensions )
{
enabledExtensions.instance.insert( name );
}
for( const std::string& name : deviceParms.optionalVulkanInstanceExtensions )
for( const std::string& name : m_DeviceParams.optionalVulkanInstanceExtensions )
{
optionalExtensions.instance.insert( name );
}
// add layers requested by the user
for( const std::string& name : deviceParms.requiredVulkanLayers )
for( const std::string& name : m_DeviceParams.requiredVulkanLayers )
{
enabledExtensions.layers.insert( name );
}
for( const std::string& name : deviceParms.optionalVulkanLayers )
for( const std::string& name : m_DeviceParams.optionalVulkanLayers )
{
optionalExtensions.layers.insert( name );
}
@ -498,8 +498,8 @@ void DeviceManager_VK::installDebugCallback()
bool DeviceManager_VK::pickPhysicalDevice()
{
vk::Format requestedFormat = nvrhi::vulkan::convertFormat( deviceParms.swapChainFormat );
vk::Extent2D requestedExtent( deviceParms.backBufferWidth, deviceParms.backBufferHeight );
vk::Format requestedFormat = nvrhi::vulkan::convertFormat( m_DeviceParams.swapChainFormat );
vk::Extent2D requestedExtent( m_DeviceParams.backBufferWidth, m_DeviceParams.backBufferHeight );
auto devices = m_VulkanInstance.enumeratePhysicalDevices();
@ -554,11 +554,11 @@ bool DeviceManager_VK::pickPhysicalDevice()
auto surfaceFmts = dev.getSurfaceFormatsKHR( m_WindowSurface );
auto surfacePModes = dev.getSurfacePresentModesKHR( m_WindowSurface );
if( surfaceCaps.minImageCount > deviceParms.swapChainBufferCount ||
( surfaceCaps.maxImageCount < deviceParms.swapChainBufferCount && surfaceCaps.maxImageCount > 0 ) )
if( surfaceCaps.minImageCount > m_DeviceParams.swapChainBufferCount ||
( surfaceCaps.maxImageCount < m_DeviceParams.swapChainBufferCount && surfaceCaps.maxImageCount > 0 ) )
{
errorStream << std::endl << " - cannot support the requested swap chain image count:";
errorStream << " requested " << deviceParms.swapChainBufferCount << ", available " << surfaceCaps.minImageCount << " - " << surfaceCaps.maxImageCount;
errorStream << " requested " << m_DeviceParams.swapChainBufferCount << ", available " << surfaceCaps.minImageCount << " - " << surfaceCaps.maxImageCount;
deviceIsGood = false;
}
@ -702,8 +702,8 @@ bool DeviceManager_VK::findQueueFamilies( vk::PhysicalDevice physicalDevice, vk:
if( m_GraphicsQueueFamily == -1 ||
m_PresentQueueFamily == -1 ||
( m_ComputeQueueFamily == -1 && deviceParms.enableComputeQueue ) ||
( m_TransferQueueFamily == -1 && deviceParms.enableCopyQueue ) )
( m_ComputeQueueFamily == -1 && m_DeviceParams.enableComputeQueue ) ||
( m_TransferQueueFamily == -1 && m_DeviceParams.enableCopyQueue ) )
{
return false;
}
@ -723,7 +723,7 @@ bool DeviceManager_VK::createDevice()
enabledExtensions.device.insert( name );
}
if( deviceParms.enableRayTracingExtensions && m_RayTracingExtensions.find( name ) != m_RayTracingExtensions.end() )
if( m_DeviceParams.enableRayTracingExtensions && m_RayTracingExtensions.find( name ) != m_RayTracingExtensions.end() )
{
enabledExtensions.device.insert( name );
}
@ -779,12 +779,12 @@ bool DeviceManager_VK::createDevice()
m_PresentQueueFamily
};
if( deviceParms.enableComputeQueue )
if( m_DeviceParams.enableComputeQueue )
{
uniqueQueueFamilies.insert( m_ComputeQueueFamily );
}
if( deviceParms.enableCopyQueue )
if( m_DeviceParams.enableCopyQueue )
{
uniqueQueueFamilies.insert( m_TransferQueueFamily );
}
@ -881,11 +881,11 @@ bool DeviceManager_VK::createDevice()
}
m_VulkanDevice.getQueue( m_GraphicsQueueFamily, 0, &m_GraphicsQueue );
if( deviceParms.enableComputeQueue )
if( m_DeviceParams.enableComputeQueue )
{
m_VulkanDevice.getQueue( m_ComputeQueueFamily, 0, &m_ComputeQueue );
}
if( deviceParms.enableCopyQueue )
if( m_DeviceParams.enableCopyQueue )
{
m_VulkanDevice.getQueue( m_TransferQueueFamily, 0, &m_TransferQueue );
}
@ -901,7 +901,7 @@ bool DeviceManager_VK::createDevice()
vk::ImageUsageFlags( vk::ImageUsageFlagBits::eDepthStencilAttachment ),
vk::ImageCreateFlags( 0 ),
&imageFormatProperties );
deviceParms.enableImageFormatD24S8 = ( ret == vk::Result::eSuccess );
m_DeviceParams.enableImageFormatD24S8 = ( ret == vk::Result::eSuccess );
// SRS - Determine if "smart" (r_swapInterval = 1) vsync mode eFifoRelaxed is supported by device and surface
auto surfacePModes = m_VulkanPhysicalDevice.getSurfacePresentModesKHR( m_WindowSurface );
@ -989,11 +989,11 @@ bool DeviceManager_VK::createSwapChain()
{
m_SwapChainFormat =
{
vk::Format( nvrhi::vulkan::convertFormat( deviceParms.swapChainFormat ) ),
vk::Format( nvrhi::vulkan::convertFormat( m_DeviceParams.swapChainFormat ) ),
vk::ColorSpaceKHR::eSrgbNonlinear
};
vk::Extent2D extent = vk::Extent2D( deviceParms.backBufferWidth, deviceParms.backBufferHeight );
vk::Extent2D extent = vk::Extent2D( m_DeviceParams.backBufferWidth, m_DeviceParams.backBufferHeight );
std::unordered_set<uint32_t> uniqueQueues =
{
@ -1007,7 +1007,7 @@ bool DeviceManager_VK::createSwapChain()
auto desc = vk::SwapchainCreateInfoKHR()
.setSurface( m_WindowSurface )
.setMinImageCount( deviceParms.swapChainBufferCount )
.setMinImageCount( m_DeviceParams.swapChainBufferCount )
.setImageFormat( m_SwapChainFormat.format )
.setImageColorSpace( m_SwapChainFormat.colorSpace )
.setImageExtent( extent )
@ -1018,7 +1018,7 @@ bool DeviceManager_VK::createSwapChain()
.setPQueueFamilyIndices( enableSwapChainSharing ? queues.data() : nullptr )
.setPreTransform( vk::SurfaceTransformFlagBitsKHR::eIdentity )
.setCompositeAlpha( vk::CompositeAlphaFlagBitsKHR::eOpaque )
.setPresentMode( deviceParms.vsyncEnabled ? ( r_swapInterval.GetInteger() == 2 || !enablePModeFifoRelaxed ? vk::PresentModeKHR::eFifo : vk::PresentModeKHR::eFifoRelaxed ) : vk::PresentModeKHR::eImmediate )
.setPresentMode( m_DeviceParams.vsyncEnabled ? ( r_swapInterval.GetInteger() == 2 || !enablePModeFifoRelaxed ? vk::PresentModeKHR::eFifo : vk::PresentModeKHR::eFifoRelaxed ) : vk::PresentModeKHR::eImmediate )
.setClipped( true )
.setOldSwapchain( nullptr );
@ -1037,9 +1037,9 @@ bool DeviceManager_VK::createSwapChain()
sci.image = image;
nvrhi::TextureDesc textureDesc;
textureDesc.width = deviceParms.backBufferWidth;
textureDesc.height = deviceParms.backBufferHeight;
textureDesc.format = deviceParms.swapChainFormat;
textureDesc.width = m_DeviceParams.backBufferWidth;
textureDesc.height = m_DeviceParams.backBufferHeight;
textureDesc.format = m_DeviceParams.swapChainFormat;
textureDesc.debugName = "Swap chain image";
textureDesc.initialState = nvrhi::ResourceStates::Present;
textureDesc.keepInitialState = true;
@ -1057,10 +1057,10 @@ bool DeviceManager_VK::createSwapChain()
bool DeviceManager_VK::CreateDeviceAndSwapChain()
{
// RB: control these through the cmdline
deviceParms.enableNvrhiValidationLayer = r_useValidationLayers.GetInteger() > 0;
deviceParms.enableDebugRuntime = r_useValidationLayers.GetInteger() > 1;
m_DeviceParams.enableNvrhiValidationLayer = r_useValidationLayers.GetInteger() > 0;
m_DeviceParams.enableDebugRuntime = r_useValidationLayers.GetInteger() > 1;
if( deviceParms.enableDebugRuntime )
if( m_DeviceParams.enableDebugRuntime )
{
enabledExtensions.instance.insert( VK_EXT_DEBUG_REPORT_EXTENSION_NAME );
#if defined(__APPLE__) && defined( USE_MoltenVK )
@ -1084,26 +1084,26 @@ bool DeviceManager_VK::CreateDeviceAndSwapChain()
CHECK( createInstance() );
if( deviceParms.enableDebugRuntime )
if( m_DeviceParams.enableDebugRuntime )
{
installDebugCallback();
}
if( deviceParms.swapChainFormat == nvrhi::Format::SRGBA8_UNORM )
if( m_DeviceParams.swapChainFormat == nvrhi::Format::SRGBA8_UNORM )
{
deviceParms.swapChainFormat = nvrhi::Format::SBGRA8_UNORM;
m_DeviceParams.swapChainFormat = nvrhi::Format::SBGRA8_UNORM;
}
else if( deviceParms.swapChainFormat == nvrhi::Format::RGBA8_UNORM )
else if( m_DeviceParams.swapChainFormat == nvrhi::Format::RGBA8_UNORM )
{
deviceParms.swapChainFormat = nvrhi::Format::BGRA8_UNORM;
m_DeviceParams.swapChainFormat = nvrhi::Format::BGRA8_UNORM;
}
// add device extensions requested by the user
for( const std::string& name : deviceParms.requiredVulkanDeviceExtensions )
for( const std::string& name : m_DeviceParams.requiredVulkanDeviceExtensions )
{
enabledExtensions.device.insert( name );
}
for( const std::string& name : deviceParms.optionalVulkanDeviceExtensions )
for( const std::string& name : m_DeviceParams.optionalVulkanDeviceExtensions )
{
optionalExtensions.device.insert( name );
}
@ -1154,12 +1154,12 @@ bool DeviceManager_VK::CreateDeviceAndSwapChain()
deviceDesc.device = m_VulkanDevice;
deviceDesc.graphicsQueue = m_GraphicsQueue;
deviceDesc.graphicsQueueIndex = m_GraphicsQueueFamily;
if( deviceParms.enableComputeQueue )
if( m_DeviceParams.enableComputeQueue )
{
deviceDesc.computeQueue = m_ComputeQueue;
deviceDesc.computeQueueIndex = m_ComputeQueueFamily;
}
if( deviceParms.enableCopyQueue )
if( m_DeviceParams.enableCopyQueue )
{
deviceDesc.transferQueue = m_TransferQueue;
deviceDesc.transferQueueIndex = m_TransferQueueFamily;
@ -1171,7 +1171,7 @@ bool DeviceManager_VK::CreateDeviceAndSwapChain()
m_NvrhiDevice = nvrhi::vulkan::createDevice( deviceDesc );
if( deviceParms.enableNvrhiValidationLayer )
if( m_DeviceParams.enableNvrhiValidationLayer )
{
m_ValidationLayer = nvrhi::validation::createValidationLayer( m_NvrhiDevice );
}
@ -1286,7 +1286,7 @@ void DeviceManager_VK::Present()
const vk::Result res = m_PresentQueue.presentKHR( &info );
assert( res == vk::Result::eSuccess || res == vk::Result::eErrorOutOfDateKHR || res == vk::Result::eSuboptimalKHR );
if( deviceParms.enableDebugRuntime )
if( m_DeviceParams.enableDebugRuntime )
{
// according to vulkan-tutorial.com, "the validation layer implementation expects
// the application to explicitly synchronize with the GPU"
@ -1295,13 +1295,13 @@ void DeviceManager_VK::Present()
else
{
#ifndef _WIN32
if( deviceParms.vsyncEnabled )
if( m_DeviceParams.vsyncEnabled )
{
m_PresentQueue.waitIdle();
}
#endif
while( m_FramesInFlight.size() > deviceParms.maxFramesInFlight )
while( m_FramesInFlight.size() > m_DeviceParams.maxFramesInFlight )
{
auto query = m_FramesInFlight.front();
m_FramesInFlight.pop();

View file

@ -1110,10 +1110,10 @@ bool DeviceManager::CreateWindowDeviceAndSwapChain( const glimpParms_t& parms, c
}
// RB
deviceParms.backBufferWidth = parms.width;
deviceParms.backBufferHeight = parms.height;
deviceParms.backBufferSampleCount = parms.multiSamples;
deviceParms.vsyncEnabled = requestedVSync;
m_DeviceParams.backBufferWidth = parms.width;
m_DeviceParams.backBufferHeight = parms.height;
m_DeviceParams.backBufferSampleCount = parms.multiSamples;
m_DeviceParams.vsyncEnabled = m_RequestedVSync;
if( !CreateDeviceAndSwapChain() )
{
@ -1128,30 +1128,30 @@ bool DeviceManager::CreateWindowDeviceAndSwapChain( const glimpParms_t& parms, c
void DeviceManager::UpdateWindowSize( const glimpParms_t& parms )
{
windowVisible = true;
m_windowVisible = true;
if( int( deviceParms.backBufferWidth ) != parms.width ||
int( deviceParms.backBufferHeight ) != parms.height ||
if( int( m_DeviceParams.backBufferWidth ) != parms.width ||
int( m_DeviceParams.backBufferHeight ) != parms.height ||
#if ID_MSAA
int( deviceParms.backBufferSampleCount ) != parms.multiSamples ||
int( m_DeviceParams.backBufferSampleCount ) != parms.multiSamples ||
#endif
( deviceParms.vsyncEnabled != requestedVSync && GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) )
( m_DeviceParams.vsyncEnabled != m_RequestedVSync && GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) )
{
// window is not minimized, and the size has changed
BackBufferResizing();
deviceParms.backBufferWidth = parms.width;
deviceParms.backBufferHeight = parms.height;
deviceParms.backBufferSampleCount = parms.multiSamples;
deviceParms.vsyncEnabled = requestedVSync;
m_DeviceParams.backBufferWidth = parms.width;
m_DeviceParams.backBufferHeight = parms.height;
m_DeviceParams.backBufferSampleCount = parms.multiSamples;
m_DeviceParams.vsyncEnabled = m_RequestedVSync;
ResizeSwapChain();
BackBufferResized();
}
else
{
deviceParms.vsyncEnabled = requestedVSync;
m_DeviceParams.vsyncEnabled = m_RequestedVSync;
}
}