summaryrefslogtreecommitdiffstats
path: root/Projects
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-07-04 03:39:01 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-07-04 03:39:01 +0000
commitba9f944ce423c4ee7d343bc4db1041c5d8214e8f (patch)
tree2bc4d86db771aa703a4c0f93efba5a4e74e43c4d /Projects
parentUpdated Math lib tests and render target test (diff)
downloadDiligentEngine-ba9f944ce423c4ee7d343bc4db1041c5d8214e8f.tar.gz
DiligentEngine-ba9f944ce423c4ee7d343bc4db1041c5d8214e8f.zip
Enabled Vulkan mode in asteroids demo
Diffstat (limited to 'Projects')
-rw-r--r--Projects/Asteroids/CMakeLists.txt1
-rw-r--r--Projects/Asteroids/DiligentVk.ddsbin0 -> 28128 bytes
-rw-r--r--Projects/Asteroids/src/WinWrapper.cpp24
-rw-r--r--Projects/Asteroids/src/asteroids_DE.cpp36
-rw-r--r--Projects/Asteroids/src/settings.h2
5 files changed, 46 insertions, 17 deletions
diff --git a/Projects/Asteroids/CMakeLists.txt b/Projects/Asteroids/CMakeLists.txt
index fba17bc..6aa9866 100644
--- a/Projects/Asteroids/CMakeLists.txt
+++ b/Projects/Asteroids/CMakeLists.txt
@@ -111,6 +111,7 @@ PRIVATE
GraphicsEngineD3D11-shared
GraphicsEngineD3D12-shared
GraphicsEngineOpenGL-shared
+ GraphicsEngineVk-shared
TargetPlatform
TextureLoader
Common
diff --git a/Projects/Asteroids/DiligentVk.dds b/Projects/Asteroids/DiligentVk.dds
new file mode 100644
index 0000000..6bea262
--- /dev/null
+++ b/Projects/Asteroids/DiligentVk.dds
Binary files differ
diff --git a/Projects/Asteroids/src/WinWrapper.cpp b/Projects/Asteroids/src/WinWrapper.cpp
index 1da3a20..0e399fa 100644
--- a/Projects/Asteroids/src/WinWrapper.cpp
+++ b/Projects/Asteroids/src/WinWrapper.cpp
@@ -41,6 +41,7 @@ AsteroidsD3D12::Asteroids* gWorkloadD3D12 = nullptr;
AsteroidsDE::Asteroids* gWorkloadDE = nullptr;
bool gd3d11Available = false;
bool gd3d12Available = false;
+bool gVulkanAvailable = false;
Settings::RenderMode gLastFrameRenderMode = static_cast<Settings::RenderMode>(-1);
GUI gGUI;
@@ -164,7 +165,7 @@ LRESULT CALLBACK WindowProc(
case Settings::RenderMode::DiligentD3D11:
case Settings::RenderMode::DiligentD3D12:
- case Settings::RenderMode::DiligentGL:
+ case Settings::RenderMode::DiligentVulkan:
if(gWorkloadDE)
gWorkloadDE->ResizeSwapChain(hWnd, gSettings.renderWidth, gSettings.renderHeight);
break;
@@ -223,7 +224,7 @@ LRESULT CALLBACK WindowProc(
case '2': gSettings.mode = gd3d12Available ? Settings::RenderMode::NativeD3D12 : gSettings.mode; return 0;
case '3': gSettings.mode = gd3d11Available ? Settings::RenderMode::DiligentD3D11 : gSettings.mode; return 0;
case '4': gSettings.mode = gd3d12Available ? Settings::RenderMode::DiligentD3D12 : gSettings.mode; return 0;
- // '5': gSettings.mode = Settings::RenderMode::DiligentGL; return 0;
+ //case '5': gSettings.mode = gVulkanAvailable ? Settings::RenderMode::DiligentVulkan : gSettings.mode; return 0;
case VK_ESCAPE:
SendMessage(hWnd, WM_CLOSE, 0, 0);
@@ -338,8 +339,8 @@ int InitWorkload(HWND hWnd, AsteroidsSimulation &asteroids)
gWorkloadDE = new AsteroidsDE::Asteroids(gSettings, &asteroids, &gGUI, hWnd, Diligent::DeviceType::D3D12);
break;
- case Settings::RenderMode::DiligentGL:
- gWorkloadDE = new AsteroidsDE::Asteroids(gSettings, &asteroids, &gGUI, hWnd, Diligent::DeviceType::OpenGL);
+ case Settings::RenderMode::DiligentVulkan:
+ gWorkloadDE = new AsteroidsDE::Asteroids(gSettings, &asteroids, &gGUI, hWnd, Diligent::DeviceType::Vulkan);
break;
}
@@ -354,6 +355,7 @@ int main(int argc, char** argv)
gd3d11Available = CheckDll("d3d11.dll");
gd3d12Available = CheckDll("d3d12.dll");
+ gVulkanAvailable = CheckDll("vulkan-1.dll");
// Must be done before any windowing-system-like things or else virtualization will kick in
auto dpi = SetupDPI();
@@ -425,8 +427,12 @@ int main(int argc, char** argv)
AsteroidsSimulation asteroids(1337, NUM_ASTEROIDS, NUM_UNIQUE_MESHES, MESH_MAX_SUBDIV_LEVELS, NUM_UNIQUE_TEXTURES);
-
- gSettings.mode = Settings::RenderMode::DiligentD3D12;
+ if (gVulkanAvailable)
+ gSettings.mode = Settings::RenderMode::DiligentVulkan;
+ else if (gd3d12Available)
+ gSettings.mode = Settings::RenderMode::DiligentD3D12;
+ else
+ gSettings.mode = Settings::RenderMode::DiligentD3D11;
// init window class
@@ -559,8 +565,8 @@ int main(int argc, char** argv)
}
break;
- case Settings::RenderMode::DiligentGL:
- ModeStr = "Diligent GL";
+ case Settings::RenderMode::DiligentVulkan:
+ ModeStr = "Diligent Vulkan";
gWorkloadDE->GetPerfCounters(updateTime, renderTime);
break;
}
@@ -598,7 +604,7 @@ int main(int argc, char** argv)
case Settings::RenderMode::DiligentD3D11:
case Settings::RenderMode::DiligentD3D12:
- case Settings::RenderMode::DiligentGL:
+ case Settings::RenderMode::DiligentVulkan:
if(gWorkloadDE)
gWorkloadDE->Render((float)frameTime, gCamera, gSettings);
break;
diff --git a/Projects/Asteroids/src/asteroids_DE.cpp b/Projects/Asteroids/src/asteroids_DE.cpp
index 45e52f5..f284cbf 100644
--- a/Projects/Asteroids/src/asteroids_DE.cpp
+++ b/Projects/Asteroids/src/asteroids_DE.cpp
@@ -24,6 +24,7 @@
#include "RenderDeviceFactoryD3D11.h"
#include "RenderDeviceFactoryD3D12.h"
#include "RenderDeviceFactoryOpenGL.h"
+#include "RenderDeviceFactoryVk.h"
#include "BasicShaderSourceStreamFactory.h"
#include "MapHelper.h"
@@ -42,6 +43,7 @@ namespace Diligent
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = nullptr;
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = nullptr;
GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = nullptr;
+ GetEngineFactoryVkType GetEngineFactoryVulkan = nullptr;
#endif
}
@@ -59,6 +61,7 @@ void Asteroids::InitDevice(HWND hWnd, DeviceType DevType)
SwapChainDesc.DefaultDepthValue = 0.f;
switch (DevType)
{
+ case DeviceType::Vulkan:
case DeviceType::D3D12:
case DeviceType::D3D11:
{
@@ -77,7 +80,7 @@ void Asteroids::InitDevice(HWND hWnd, DeviceType DevType)
pFactoryD3D11->CreateDeviceAndContextsD3D11( DeviceAttribs, &mDevice, ppContexts.data(), mNumSubsets-1 );
pFactoryD3D11->CreateSwapChainD3D11( mDevice, ppContexts[0], SwapChainDesc, FullScreenModeDesc{}, hWnd, &mSwapChain );
}
- else
+ else if(DevType == DeviceType::D3D12)
{
EngineD3D12Attribs Attribs;
Attribs.GPUDescriptorHeapDynamicSize[0] = 65536*4;
@@ -94,6 +97,23 @@ void Asteroids::InitDevice(HWND hWnd, DeviceType DevType)
pFactoryD3D12->CreateDeviceAndContextsD3D12( Attribs, &mDevice, ppContexts.data(), mNumSubsets-1 );
pFactoryD3D12->CreateSwapChainD3D12( mDevice, ppContexts[0], SwapChainDesc, FullScreenModeDesc{}, hWnd, &mSwapChain );
}
+ else if(DevType == DeviceType::Vulkan)
+ {
+ EngineVkAttribs Attribs;
+ Attribs.DynamicHeapSize = 32 << 20;
+#if ENGINE_DLL
+ if(!GetEngineFactoryVulkan)
+ LoadGraphicsEngineVk(GetEngineFactoryVulkan);
+#endif
+ auto *pFactoryVk = GetEngineFactoryVulkan();
+ pFactoryVk->CreateDeviceAndContextsVk( Attribs, &mDevice, ppContexts.data(), mNumSubsets-1 );
+ pFactoryVk->CreateSwapChainVk( mDevice, ppContexts[0], SwapChainDesc, hWnd, &mSwapChain );
+ }
+ else
+ {
+ UNEXPECTED("Unexpected device type");
+ }
+
mDeviceCtxt.Attach(ppContexts[0]);
mDeferredCtxt.resize(mNumSubsets-1);
@@ -149,6 +169,8 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G
case DeviceType::D3D11: spriteFile = "DiligentD3D11.dds"; break;
case DeviceType::D3D12: spriteFile = "DiligentD3D12.dds"; break;
case DeviceType::OpenGL: spriteFile = "DiligentGL.dds"; break;
+ case DeviceType::Vulkan: spriteFile = "DiligentVk.dds"; break;
+ default: UNEXPECTED("Unexpected device type");
}
mSprite.reset( new GUISprite(5, 10, 140, 50, spriteFile) );
@@ -222,9 +244,9 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G
mDevice->CreateShader(attribs, &ps);
}
- PSODesc.GraphicsPipeline.RTVFormats[0] = TEX_FORMAT_RGBA8_UNORM_SRGB;
+ PSODesc.GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat;
PSODesc.GraphicsPipeline.NumRenderTargets = 1;
- PSODesc.GraphicsPipeline.DSVFormat = TEX_FORMAT_D32_FLOAT;
+ PSODesc.GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat;
PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
PSODesc.Name = "Asteroids PSO";
@@ -321,9 +343,9 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G
PSODesc.GraphicsPipeline.pVS = vs;
PSODesc.GraphicsPipeline.pPS = ps;
- PSODesc.GraphicsPipeline.RTVFormats[0] = TEX_FORMAT_RGBA8_UNORM_SRGB;
+ PSODesc.GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat;
PSODesc.GraphicsPipeline.NumRenderTargets = 1;
- PSODesc.GraphicsPipeline.DSVFormat = TEX_FORMAT_D32_FLOAT;
+ PSODesc.GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat;
PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
mDevice->CreatePipelineState(PSODesc, &mSkyboxPSO);
@@ -369,9 +391,9 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G
PSODesc.GraphicsPipeline.DepthStencilDesc.DepthEnable = false;
- PSODesc.GraphicsPipeline.RTVFormats[0] = TEX_FORMAT_RGBA8_UNORM_SRGB;
+ PSODesc.GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat;
PSODesc.GraphicsPipeline.NumRenderTargets = 1;
- PSODesc.GraphicsPipeline.DSVFormat = TEX_FORMAT_D32_FLOAT;
+ PSODesc.GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat;
PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
RefCntAutoPtr<IShader> sprite_vs, sprite_ps, font_ps;
diff --git a/Projects/Asteroids/src/settings.h b/Projects/Asteroids/src/settings.h
index 5ca7d2a..b55f386 100644
--- a/Projects/Asteroids/src/settings.h
+++ b/Projects/Asteroids/src/settings.h
@@ -73,7 +73,7 @@ struct Settings
NativeD3D12,
DiligentD3D11,
DiligentD3D12,
- DiligentGL
+ DiligentVulkan
}mode = DiligentD3D11;
int resourceBindingMode = 2; // Only for DiligentD3D12 mode