system update: way to create graphics device is now reorganized; added command line arguments support

This commit is contained in:
turanszkij
2018-04-19 18:05:31 +01:00
parent 8e87616bf0
commit 5649fd3d70
26 changed files with 165 additions and 66 deletions
+2
View File
@@ -41,6 +41,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
// TODO: Place code here.
wiStartupArguments::Parse(lpCmdLine); // if you wish to use command line arguments, here is a good place to parse them...
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_WICKEDENGINEGAME, szWindowClass, MAX_LOADSTRING);
+4
View File
@@ -28,6 +28,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
// TODO: Place code here.
wiStartupArguments::Parse(lpCmdLine); // if you wish to use command line arguments, here is a good place to parse them...
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_TEMPLATEWINDOWS, szWindowClass, MAX_LOADSTRING);
@@ -117,8 +119,10 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
main.SetWindow(hWnd, hInst); // assign window handle (mandatory)
return TRUE;
}
+2
View File
@@ -32,6 +32,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
// TODO: Place code here.
wiStartupArguments::Parse(lpCmdLine); // if you wish to use command line arguments, here is a good place to parse them...
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_WICKEDENGINETESTS, szWindowClass, MAX_LOADSTRING);
+1 -1
View File
@@ -24,7 +24,7 @@ void DeferredRenderableComponent::ResizeBuffers()
{
Renderable3DComponent::ResizeBuffers();
FORMAT defaultTextureFormat = GraphicsDevice::GetBackBufferFormat();
FORMAT defaultTextureFormat = wiRenderer::GetDevice()->GetBackBufferFormat();
// Protect against multiple buffer resizes when there is no change!
static UINT lastBufferResWidth = 0, lastBufferResHeight = 0, lastBufferMSAA = 0;
+1 -1
View File
@@ -27,7 +27,7 @@ void ForwardRenderableComponent::ResizeBuffers()
{
Renderable3DComponent::ResizeBuffers();
FORMAT defaultTextureFormat = GraphicsDevice::GetBackBufferFormat();
FORMAT defaultTextureFormat = wiRenderer::GetDevice()->GetBackBufferFormat();
// Protect against multiple buffer resizes when there is no change!
static UINT lastBufferResWidth = 0, lastBufferResHeight = 0, lastBufferMSAA = 0;
+57 -5
View File
@@ -13,8 +13,15 @@
#include "wiFrameRate.h"
#include "wiProfiler.h"
#include "wiInitializer.h"
#include "wiStartupArguments.h"
#include "wiGraphicsDevice_DX11.h"
#include "wiGraphicsDevice_DX12.h"
#include "wiGraphicsDevice_Vulkan.h"
using namespace std;
using namespace wiGraphicsTypes;
MainComponent::MainComponent()
{
@@ -50,6 +57,38 @@ MainComponent::~MainComponent()
void MainComponent::Initialize()
{
// User can also create a graphics device if custom logic is desired, but he must do before this function!
if (wiRenderer::graphicsDevice == nullptr)
{
bool debugdevice = wiStartupArguments::HasArgument("debugdevice");
if (wiStartupArguments::HasArgument("vulkan"))
{
#ifdef WICKEDENGINE_BUILD_VULKAN
wiRenderer::SHADERPATH += "spirv/";
wiRenderer::graphicsDevice = new GraphicsDevice_Vulkan(window, fullscreen, debugdevice);
#else
wiHelper::messageBox("Vulkan SDK not found during building the application! Vulkan API disabled!", "Error");
#endif
}
else if (wiStartupArguments::HasArgument("dx12"))
{
if (wiStartupArguments::HasArgument("hlsl6"))
{
wiRenderer::SHADERPATH += "hlsl6/";
}
wiRenderer::graphicsDevice = new GraphicsDevice_DX12(window, fullscreen, debugdevice);
}
else
{
wiRenderer::graphicsDevice = new GraphicsDevice_DX11(window, fullscreen, debugdevice);
}
}
wiInitializer::InitializeComponents();
wiLua::GetGlobal()->RegisterObject(MainComponent_BindLua::className, "main", new MainComponent_BindLua(this));
@@ -192,9 +231,25 @@ void MainComponent::Compose()
stringstream ss("");
if (infoDisplay.watermark)
{
ss << string("Wicked Engine ") + wiVersion::GetVersionString();
ss << string("Wicked Engine ") + wiVersion::GetVersionString() + " ";
if (dynamic_cast<GraphicsDevice_DX11*>(wiRenderer::GetDevice()))
{
ss << "[DX11]";
}
else if (dynamic_cast<GraphicsDevice_DX12*>(wiRenderer::GetDevice()))
{
ss << "[DX12]";
}
#ifdef WICKEDENGINE_BUILD_VULKAN
else if (dynamic_cast<GraphicsDevice_Vulkan*>(wiRenderer::GetDevice()))
{
ss << "[Vulkan]";
}
#endif
#ifdef _DEBUG
ss << " [DEBUG]";
ss << "[DEBUG]";
#endif
ss << endl;
}
@@ -252,8 +307,6 @@ bool MainComponent::SetWindow(wiWindowRegistration::window_type window, HINSTANC
screenH = rect.bottom - rect.top;
}
wiRenderer::InitDevice(window, fullscreen);
wiWindowRegistration::GetInstance()->RegisterWindow(window);
return true;
@@ -263,7 +316,6 @@ bool MainComponent::SetWindow(wiWindowRegistration::window_type window)
{
screenW = (int)window->Bounds.Width;
screenH = (int)window->Bounds.Height;
wiRenderer::InitDevice(window, fullscreen);
this->window = window;
+1 -1
View File
@@ -22,7 +22,7 @@ Renderable2DComponent::~Renderable2DComponent()
wiRenderTarget Renderable2DComponent::rtFinal;
void Renderable2DComponent::ResizeBuffers()
{
FORMAT defaultTextureFormat = GraphicsDevice::GetBackBufferFormat();
FORMAT defaultTextureFormat = wiRenderer::GetDevice()->GetBackBufferFormat();
// Protect against multiple buffer resizes when there is no change!
static UINT lastBufferResWidth = 0, lastBufferResHeight = 0, lastBufferMSAA = 0;
+1 -1
View File
@@ -41,7 +41,7 @@ void Renderable3DComponent::ResizeBuffers()
{
Renderable2DComponent::ResizeBuffers();
FORMAT defaultTextureFormat = GraphicsDevice::GetBackBufferFormat();
FORMAT defaultTextureFormat = wiRenderer::GetDevice()->GetBackBufferFormat();
// Protect against multiple buffer resizes when there is no change!
static UINT lastBufferResWidth = 0, lastBufferResHeight = 0, lastBufferMSAA = 0;
+5
View File
@@ -57,6 +57,7 @@
#include "wiRectPacker.h"
#include "wiProfiler.h"
#include "wiOcean.h"
#include "wiStartupArguments.h"
#include "RenderableComponent.h"
#include "Renderable2DComponent.h"
@@ -68,6 +69,10 @@
#include "LoadingScreenComponent.h"
#include "MainComponent.h"
#include "wiGraphicsDevice_DX11.h"
#include "wiGraphicsDevice_DX12.h"
#include "wiGraphicsDevice_Vulkan.h"
#ifdef _WIN32
#ifdef WINSTORE_SUPPORT
@@ -369,6 +369,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiSprite.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiSprite_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiSPTree.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiStartupArguments.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiTaskThread.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiTextureHelper.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiTGATextureLoader.h" />
@@ -715,6 +716,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiSprite.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiSprite_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiSPTree.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiStartupArguments.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiTextureHelper.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiTGATextureLoader.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiThreadSafeManager.cpp" />
@@ -1164,6 +1164,9 @@
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\nv_dds.h">
<Filter>UTILITY</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiStartupArguments.h">
<Filter>ENGINE\Helpers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)LUA\lapi.c">
@@ -1979,6 +1982,9 @@
<ClCompile Include="$(MSBuildThisFileDirectory)Utility\nv_dds.cpp">
<Filter>UTILITY</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiStartupArguments.cpp">
<Filter>ENGINE\Helpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="$(MSBuildThisFileDirectory)fonts\default_font.dds">
+1 -1
View File
@@ -147,7 +147,7 @@ void wiFont::LoadShaders()
desc.rs = rasterizerState;
desc.dss = depthStencilState;
desc.numRTs = 1;
desc.RTFormats[0] = GraphicsDevice::GetBackBufferFormat();
desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat();
SAFE_DELETE(PSO);
PSO = new GraphicsPSO;
wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, PSO);
-9
View File
@@ -2,15 +2,6 @@
using namespace wiGraphicsTypes;
//FORMAT GraphicsDevice::BACKBUFFER_FORMAT = FORMAT::FORMAT_R8G8B8A8_UNORM;
//FORMAT GraphicsDevice::BACKBUFFER_FORMAT = FORMAT::FORMAT_B8G8R8A8_UNORM; // this is compliant with vulkan, dx11, dx12
FORMAT GraphicsDevice::BACKBUFFER_FORMAT = FORMAT::FORMAT_R10G10B10A2_UNORM;
FORMAT GraphicsDevice::GetBackBufferFormat()
{
return BACKBUFFER_FORMAT;
}
bool GraphicsDevice::CheckCapability(GRAPHICSDEVICE_CAPABILITY capability)
{
switch (capability)
+3 -3
View File
@@ -18,12 +18,12 @@ namespace wiGraphicsTypes
int SCREENWIDTH, SCREENHEIGHT;
bool FULLSCREEN;
bool RESOLUTIONCHANGED;
static FORMAT BACKBUFFER_FORMAT;
FORMAT BACKBUFFER_FORMAT;
static const UINT BACKBUFFER_COUNT = 2;
bool TESSELLATION, MULTITHREADED_RENDERING, CONSERVATIVE_RASTERIZATION, RASTERIZER_ORDERED_VIEWS, UNORDEREDACCESSTEXTURE_LOAD_EXT;
public:
GraphicsDevice()
:FRAMECOUNT(0), VSYNC(true), SCREENWIDTH(0), SCREENHEIGHT(0), FULLSCREEN(false), RESOLUTIONCHANGED(false),
:FRAMECOUNT(0), VSYNC(true), SCREENWIDTH(0), SCREENHEIGHT(0), FULLSCREEN(false), RESOLUTIONCHANGED(false), BACKBUFFER_FORMAT(FORMAT_R10G10B10A2_UNORM),
TESSELLATION(false), MULTITHREADED_RENDERING(false), CONSERVATIVE_RASTERIZATION(false),RASTERIZER_ORDERED_VIEWS(false), UNORDEREDACCESSTEXTURE_LOAD_EXT(false)
{}
@@ -83,7 +83,7 @@ namespace wiGraphicsTypes
{
return XMMatrixOrthographicOffCenterLH(0, (float)GetScreenWidth(), (float)GetScreenHeight(), 0, -1, 1);
}
static FORMAT GetBackBufferFormat();
FORMAT GetBackBufferFormat() { return BACKBUFFER_FORMAT; }
static UINT GetBackBufferCount() { return BACKBUFFER_COUNT; }
+6 -2
View File
@@ -1382,7 +1382,7 @@ const void* const __nullBlob[1024] = {}; // this is initialized to nullptrs!
// Engine functions
GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type window, bool fullscreen) : GraphicsDevice()
GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type window, bool fullscreen, bool debuglayer) : GraphicsDevice()
{
FULLSCREEN = fullscreen;
@@ -1407,7 +1407,11 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo
}
UINT createDeviceFlags = 0;
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
if (debuglayer)
{
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
}
D3D_DRIVER_TYPE driverTypes[] =
{
+1 -1
View File
@@ -48,7 +48,7 @@ namespace wiGraphicsTypes
PRIMITIVETOPOLOGY prev_pt[GRAPHICSTHREAD_COUNT] = {};
public:
GraphicsDevice_DX11(wiWindowRegistration::window_type window, bool fullscreen = false);
GraphicsDevice_DX11(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false);
~GraphicsDevice_DX11();
+16 -13
View File
@@ -1452,7 +1452,7 @@ namespace wiGraphicsTypes
// Engine functions
ID3D12GraphicsCommandList* GraphicsDevice_DX12::GetDirectCommandList(GRAPHICSTHREAD threadID) { return static_cast<ID3D12GraphicsCommandList*>(GetFrameResources().commandLists[threadID]); }
GraphicsDevice_DX12::GraphicsDevice_DX12(wiWindowRegistration::window_type window, bool fullscreen) : GraphicsDevice()
GraphicsDevice_DX12::GraphicsDevice_DX12(wiWindowRegistration::window_type window, bool fullscreen, bool debuglayer) : GraphicsDevice()
{
FULLSCREEN = fullscreen;
@@ -1468,20 +1468,23 @@ namespace wiGraphicsTypes
HRESULT hr = E_FAIL;
#if defined(_DEBUG) && !defined(WINSTORE_SUPPORT)
// Enable the debug layer.
HMODULE dx12 = LoadLibraryEx(L"d3d12.dll",
nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
auto pD3D12GetDebugInterface =
reinterpret_cast<PFN_D3D12_GET_DEBUG_INTERFACE>(
GetProcAddress(dx12, "D3D12GetDebugInterface"));
if (pD3D12GetDebugInterface)
#if !defined(WINSTORE_SUPPORT)
if (debuglayer)
{
ID3D12Debug* debugController;
if (SUCCEEDED(pD3D12GetDebugInterface(
IID_PPV_ARGS(&debugController))))
// Enable the debug layer.
HMODULE dx12 = LoadLibraryEx(L"d3d12.dll",
nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
auto pD3D12GetDebugInterface =
reinterpret_cast<PFN_D3D12_GET_DEBUG_INTERFACE>(
GetProcAddress(dx12, "D3D12GetDebugInterface"));
if (pD3D12GetDebugInterface)
{
debugController->EnableDebugLayer();
ID3D12Debug* debugController;
if (SUCCEEDED(pD3D12GetDebugInterface(
IID_PPV_ARGS(&debugController))))
{
debugController->EnableDebugLayer();
}
}
}
#endif
+1 -1
View File
@@ -140,7 +140,7 @@ namespace wiGraphicsTypes
public:
GraphicsDevice_DX12(wiWindowRegistration::window_type window, bool fullscreen = false);
GraphicsDevice_DX12(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false);
~GraphicsDevice_DX12();
+6 -6
View File
@@ -25,11 +25,6 @@ namespace wiGraphicsTypes
const std::vector<const char*> validationLayers = {
"VK_LAYER_LUNARG_standard_validation"
};
#ifdef NDEBUG
bool enableValidationLayers = false;
#else
bool enableValidationLayers = true;
#endif
bool checkValidationLayerSupport() {
uint32_t layerCount;
vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
@@ -1384,8 +1379,10 @@ namespace wiGraphicsTypes
// Engine functions
VkCommandBuffer GraphicsDevice_Vulkan::GetDirectCommandList(GRAPHICSTHREAD threadID) { return GetFrameResources().commandBuffers[threadID]; }
GraphicsDevice_Vulkan::GraphicsDevice_Vulkan(wiWindowRegistration::window_type window, bool fullscreen) : GraphicsDevice()
GraphicsDevice_Vulkan::GraphicsDevice_Vulkan(wiWindowRegistration::window_type window, bool fullscreen, bool debuglayer) : GraphicsDevice()
{
BACKBUFFER_FORMAT = FORMAT::FORMAT_B8G8R8A8_UNORM;
FULLSCREEN = fullscreen;
RECT rect = RECT();
@@ -1417,6 +1414,9 @@ namespace wiGraphicsTypes
//}
extensionNames.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
extensionNames.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
bool enableValidationLayers = debuglayer;
if (enableValidationLayers && !checkValidationLayerSupport()) {
//throw std::runtime_error("validation layers requested, but not available!");
+1 -1
View File
@@ -162,7 +162,7 @@ namespace wiGraphicsTypes
public:
GraphicsDevice_Vulkan(wiWindowRegistration::window_type window, bool fullscreen = false);
GraphicsDevice_Vulkan(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false);
~GraphicsDevice_Vulkan();
+3 -3
View File
@@ -129,7 +129,7 @@ void wiImage::LoadShaders()
desc.numRTs = 1;
desc.RTFormats[0] = GraphicsDevice::GetBackBufferFormat();
desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat();
device->CreateGraphicsPSO(&desc, &imagePSO[i][j][k][0]);
desc.RTFormats[0] = wiRenderer::RTFormat_hdr;
@@ -176,13 +176,13 @@ void wiImage::LoadShaders()
else if (i == POSTPROCESS_TONEMAP)
{
desc.numRTs = 1;
desc.RTFormats[0] = GraphicsDevice::GetBackBufferFormat();
desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat();
}
else if (i == POSTPROCESS_BLOOMSEPARATE || i == POSTPROCESS_BLUR_H || POSTPROCESS_BLUR_V)
{
// todo: bloom and DoF blur should really be HDR lol...
desc.numRTs = 1;
desc.RTFormats[0] = GraphicsDevice::GetBackBufferFormat();
desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat();
}
else
{
-14
View File
@@ -19,9 +19,6 @@
#include "wiEnums.h"
#include "wiRandom.h"
#include "wiFont.h"
#include "wiGraphicsDevice_DX11.h"
#include "wiGraphicsDevice_DX12.h"
#include "wiGraphicsDevice_Vulkan.h"
#include "wiTranslator.h"
#include "wiRectPacker.h"
#include "wiBackLog.h"
@@ -124,17 +121,6 @@ wiRenderer::wiRenderer()
{
}
void wiRenderer::InitDevice(wiWindowRegistration::window_type window, bool fullscreen)
{
SAFE_DELETE(graphicsDevice);
#ifdef WICKEDENGINE_BUILD_VULKAN
graphicsDevice = new GraphicsDevice_Vulkan(window, fullscreen);
#else
graphicsDevice = new GraphicsDevice_DX11(window, fullscreen);
//graphicsDevice = new GraphicsDevice_DX12(window, fullscreen);
#endif
}
void wiRenderer::Present(function<void()> drawToScreen1,function<void()> drawToScreen2,function<void()> drawToScreen3)
{
GetDevice()->PresentBegin();
+1 -2
View File
@@ -52,10 +52,9 @@ class wiRenderer
{
public:
static wiGraphicsTypes::GraphicsDevice* graphicsDevice;
static wiGraphicsTypes::GraphicsDevice* GetDevice() { return graphicsDevice; }
static wiGraphicsTypes::GraphicsDevice* GetDevice() { assert(graphicsDevice != nullptr); return graphicsDevice; }
static void InitDevice(wiWindowRegistration::window_type window, bool fullscreen = false);
static void Present(std::function<void()> drawToScreen1=nullptr, std::function<void()> drawToScreen2=nullptr, std::function<void()> drawToScreen3=nullptr);
+29
View File
@@ -0,0 +1,29 @@
#include "wiStartupArguments.h"
#include <vector>
#include <sstream>
#include <iterator>
using namespace std;
set<string> wiStartupArguments::params;
void wiStartupArguments::Parse(const wchar_t* args)
{
wstring tmp = args;
string tmp1(tmp.begin(), tmp.end());
istringstream iss(tmp1);
params =
{
istream_iterator<string>{iss},
istream_iterator<string>{}
};
}
bool wiStartupArguments::HasArgument(const std::string& value)
{
return params.find(value) != params.end();
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <string>
#include <set>
class wiStartupArguments
{
public:
static std::set<std::string> params;
static void Parse(const wchar_t* args);
static bool HasArgument(const std::string& value);
};
+1 -1
View File
@@ -216,7 +216,7 @@ void wiWidget::LoadShaders()
desc.bs = wiRenderer::blendStates[BSTYPE_OPAQUE];
desc.rs = wiRenderer::rasterizers[RSTYPE_DOUBLESIDED];
desc.numRTs = 1;
desc.RTFormats[0] = GraphicsDevice::GetBackBufferFormat();
desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat();
desc.pt = TRIANGLESTRIP;
RECREATE(PSO_colorpicker);
HRESULT hr = wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, PSO_colorpicker);