diff options
Diffstat (limited to 'Tests/TestApp/src/TestApp.cpp')
| -rw-r--r-- | Tests/TestApp/src/TestApp.cpp | 588 |
1 files changed, 0 insertions, 588 deletions
diff --git a/Tests/TestApp/src/TestApp.cpp b/Tests/TestApp/src/TestApp.cpp deleted file mode 100644 index 36d42e4..0000000 --- a/Tests/TestApp/src/TestApp.cpp +++ /dev/null @@ -1,588 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* 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 OF ANY PROPRIETARY RIGHTS. -* -* In no event and under no legal theory, whether in tort (including negligence), -* contract, or otherwise, unless required by applicable law (such as deliberate -* and grossly negligent acts) or agreed to in writing, shall any Contributor be -* liable for any damages, including any direct, indirect, special, incidental, -* or consequential damages of any character arising as a result of this License or -* out of the use or inability to use the software (including but not limited to damages -* for loss of goodwill, work stoppage, computer failure or malfunction, or any and -* all other commercial damages or losses), even if such Contributor has been advised -* of the possibility of such damages. -*/ - -#include <sstream> -#include <math.h> -#include <iomanip> - -#include <cstdlib> - -#include "PlatformDefinitions.h" -#include "TestApp.h" -#include "Errors.h" -#include "StringTools.h" - -#if D3D11_SUPPORTED -# include "EngineFactoryD3D11.h" -#endif - -#if D3D12_SUPPORTED -# include "EngineFactoryD3D12.h" -#endif - -#if GL_SUPPORTED || GLES_SUPPORTED -# include "EngineFactoryOpenGL.h" -#endif - -#if VULKAN_SUPPORTED -# include "EngineFactoryVk.h" -#endif - -#if METAL_SUPPORTED -# include "EngineFactoryMtl.h" -#endif - -#include "FileSystem.h" -#include "MapHelper.h" -#include "Errors.h" -#include "TestVPAndSR.h" -#include "TestCopyTexData.h" -#include "PlatformMisc.h" -#include "StringTools.h" - -namespace Diligent -{ - -TestApp::TestApp() : - m_AppTitle("Test app") -{ -} - -TestApp::~TestApp() -{ -} - - -void TestApp::InitializeDiligentEngine( -#if PLATFORM_LINUX - void *display, -#endif - void *NativeWindowHandle - ) -{ - SwapChainDesc SCDesc; - Uint32 NumDeferredCtx = 0; - std::vector<IDeviceContext*> ppContexts; - std::vector<AdapterAttribs> Adapters; - std::vector<std::vector<DisplayModeAttribs>> AdapterDisplayModes; - switch (m_DeviceType) - { -#if D3D11_SUPPORTED - case DeviceType::D3D11: - { - EngineD3D11CreateInfo DeviceAttribs; -#if ENGINE_DLL - GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = nullptr; - // Load the dll and import GetEngineFactoryD3D11() function - LoadGraphicsEngineD3D11(GetEngineFactoryD3D11); -#endif -#ifdef _DEBUG - DeviceAttribs.DebugFlags = D3D11_DEBUG_FLAG_CREATE_DEBUG_DEVICE | - D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE | - D3D11_DEBUG_FLAG_VERIFY_COMMITTED_SHADER_RESOURCES; -#endif - auto *pFactoryD3D11 = GetEngineFactoryD3D11(); - Uint32 NumAdapters = 0; - pFactoryD3D11->EnumerateAdapters(DIRECT3D_FEATURE_LEVEL_11_0, NumAdapters, 0); - Adapters.resize(NumAdapters); - pFactoryD3D11->EnumerateAdapters(DIRECT3D_FEATURE_LEVEL_11_0, NumAdapters, Adapters.data()); - - for(Uint32 i=0; i < Adapters.size(); ++i) - { - Uint32 NumDisplayModes = 0; - std::vector<DisplayModeAttribs> DisplayModes; - pFactoryD3D11->EnumerateDisplayModes(DIRECT3D_FEATURE_LEVEL_11_0, i, 0, TEX_FORMAT_RGBA8_UNORM, NumDisplayModes, nullptr); - DisplayModes.resize(NumDisplayModes); - pFactoryD3D11->EnumerateDisplayModes(DIRECT3D_FEATURE_LEVEL_11_0, i, 0, TEX_FORMAT_RGBA8_UNORM, NumDisplayModes, DisplayModes.data()); - AdapterDisplayModes.emplace_back(std::move(DisplayModes)); - } - - DeviceAttribs.NumDeferredContexts = NumDeferredCtx; - ppContexts.resize(1 + NumDeferredCtx); - pFactoryD3D11->CreateDeviceAndContextsD3D11(DeviceAttribs, &m_pDevice, ppContexts.data()); - - if(NativeWindowHandle != nullptr) - pFactoryD3D11->CreateSwapChainD3D11(m_pDevice, ppContexts[0], SCDesc, FullScreenModeDesc{}, NativeWindowHandle, &m_pSwapChain); - } - break; -#endif - -#if D3D12_SUPPORTED - case DeviceType::D3D12: - { -#if ENGINE_DLL - GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = nullptr; - // Load the dll and import GetEngineFactoryD3D12() function - LoadGraphicsEngineD3D12(GetEngineFactoryD3D12); -#endif - auto *pFactoryD3D12 = GetEngineFactoryD3D12(); - Uint32 NumAdapters = 0; - pFactoryD3D12->EnumerateAdapters(DIRECT3D_FEATURE_LEVEL_11_0, NumAdapters, 0); - Adapters.resize(NumAdapters); - pFactoryD3D12->EnumerateAdapters(DIRECT3D_FEATURE_LEVEL_11_0, NumAdapters, Adapters.data()); - - for (Uint32 i = 0; i < Adapters.size(); ++i) - { - Uint32 NumDisplayModes = 0; - std::vector<DisplayModeAttribs> DisplayModes; - pFactoryD3D12->EnumerateDisplayModes(DIRECT3D_FEATURE_LEVEL_11_0, i, 0, TEX_FORMAT_RGBA8_UNORM, NumDisplayModes, nullptr); - DisplayModes.resize(NumDisplayModes); - pFactoryD3D12->EnumerateDisplayModes(DIRECT3D_FEATURE_LEVEL_11_0, i, 0, TEX_FORMAT_RGBA8_UNORM, NumDisplayModes, DisplayModes.data()); - AdapterDisplayModes.emplace_back(std::move(DisplayModes)); - } - - EngineD3D12CreateInfo EngD3D12Attribs; - EngD3D12Attribs.EnableDebugLayer = true; - //EngD3D12Attribs.EnableGPUBasedValidation = true; - EngD3D12Attribs.CPUDescriptorHeapAllocationSize[0] = 64; // D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV - EngD3D12Attribs.CPUDescriptorHeapAllocationSize[1] = 32; // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER - EngD3D12Attribs.CPUDescriptorHeapAllocationSize[2] = 16; // D3D12_DESCRIPTOR_HEAP_TYPE_RTV - EngD3D12Attribs.CPUDescriptorHeapAllocationSize[3] = 16; // D3D12_DESCRIPTOR_HEAP_TYPE_DSV - EngD3D12Attribs.DynamicDescriptorAllocationChunkSize[0] = 8; // D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV - EngD3D12Attribs.DynamicDescriptorAllocationChunkSize[1] = 8; // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER - ppContexts.resize(1 + NumDeferredCtx); - - EngD3D12Attribs.NumDeferredContexts = NumDeferredCtx; - pFactoryD3D12->CreateDeviceAndContextsD3D12(EngD3D12Attribs, &m_pDevice, ppContexts.data()); - - if (!m_pSwapChain && NativeWindowHandle != nullptr) - pFactoryD3D12->CreateSwapChainD3D12(m_pDevice, ppContexts[0], SCDesc, FullScreenModeDesc{}, NativeWindowHandle, &m_pSwapChain); - } - break; -#endif - -#if GL_SUPPORTED || GLES_SUPPORTED - case DeviceType::OpenGL: - case DeviceType::OpenGLES: - { -#if !PLATFORM_MACOS - VERIFY_EXPR(NativeWindowHandle != nullptr); -#endif -#if EXPLICITLY_LOAD_ENGINE_GL_DLL - // Declare function pointer - GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = nullptr; - // Load the dll and import GetEngineFactoryOpenGL() function - LoadGraphicsEngineOpenGL(GetEngineFactoryOpenGL); -#endif - auto* pFactoryOpenGL = GetEngineFactoryOpenGL(); - EngineGLCreateInfo CreationAttribs; - CreationAttribs.pNativeWndHandle = NativeWindowHandle; -#if PLATFORM_LINUX - CreationAttribs.pDisplay = display; -#endif - if (NumDeferredCtx != 0) - { - LOG_ERROR_MESSAGE("Deferred contexts are not supported in OpenGL mode"); - NumDeferredCtx = 0; - } - ppContexts.resize(1 + NumDeferredCtx); - pFactoryOpenGL->CreateDeviceAndSwapChainGL( - CreationAttribs, &m_pDevice, ppContexts.data(), SCDesc, &m_pSwapChain); - } - break; -#endif - -#if VULKAN_SUPPORTED - case DeviceType::Vulkan: - { -#if EXPLICITLY_LOAD_ENGINE_VK_DLL - GetEngineFactoryVkType GetEngineFactoryVk = nullptr; - // Load the dll and import GetEngineFactoryVk() function - LoadGraphicsEngineVk(GetEngineFactoryVk); -#endif - EngineVkCreateInfo EngVkAttribs; - - EngVkAttribs.EnableValidation = true; - EngVkAttribs.MainDescriptorPoolSize = EngineVkCreateInfo::DescriptorPoolSize{ 64, 64, 256, 256, 64, 32, 32, 32, 32 }; - EngVkAttribs.DynamicDescriptorPoolSize = EngineVkCreateInfo::DescriptorPoolSize{ 64, 64, 256, 256, 64, 32, 32, 32, 32 }; - EngVkAttribs.UploadHeapPageSize = 32*1024; - //EngVkAttribs.DeviceLocalMemoryReserveSize = 32 << 20; - //EngVkAttribs.HostVisibleMemoryReserveSize = 48 << 20; - - auto& Features = EngVkAttribs.EnabledFeatures; - Features.depthBiasClamp = true; - Features.fillModeNonSolid = true; - Features.depthClamp = true; - Features.independentBlend = true; - Features.samplerAnisotropy = true; - Features.geometryShader = true; - Features.tessellationShader = true; - Features.dualSrcBlend = true; - Features.multiViewport = true; - Features.imageCubeArray = true; - Features.textureCompressionBC = true; - Features.vertexPipelineStoresAndAtomics = true; - Features.fragmentStoresAndAtomics = true; - - EngVkAttribs.NumDeferredContexts = NumDeferredCtx; - ppContexts.resize(1 + NumDeferredCtx); - auto* pFactoryVk = GetEngineFactoryVk(); - pFactoryVk->CreateDeviceAndContextsVk(EngVkAttribs, &m_pDevice, ppContexts.data()); - - if (!m_pSwapChain && NativeWindowHandle != nullptr) - pFactoryVk->CreateSwapChainVk(m_pDevice, ppContexts[0], SCDesc, NativeWindowHandle, &m_pSwapChain); - } - break; -#endif - -#if METAL_SUPPORTED - case DeviceType::Metal: - { - EngineMtlCreateInfo MtlAttribs; - - MtlAttribs.NumDeferredContexts = NumDeferredCtx; - ppContexts.resize(1 + NumDeferredCtx); - auto *pFactoryMtl = GetEngineFactoryMtl(); - pFactoryMtl->CreateDeviceAndContextsMtl(MtlAttribs, &m_pDevice, ppContexts.data()); - - if (!m_pSwapChain && NativeWindowHandle != nullptr) - pFactoryMtl->CreateSwapChainMtl(m_pDevice, ppContexts[0], SCDesc, NativeWindowHandle, &m_pSwapChain); - } - break; -#endif - - default: - LOG_ERROR_AND_THROW("Unknown device type"); - break; - } - - - std::stringstream ss; - ss << "Found " << Adapters.size() << " adapters:\n"; - for (Uint32 i = 0; i < Adapters.size(); ++i) - { - ss << Adapters[i].Description << " (" << (Adapters[i].DedicatedVideoMemory >> 20) << " MB). Num outputs: " << Adapters[i].NumOutputs << ". Display modes:\n"; - const auto &DisplayModes = AdapterDisplayModes[i]; - for(Uint32 m=0; m < DisplayModes.size(); ++m) - { - const auto &Mode = DisplayModes[m]; - float RefreshRate = (float)Mode.RefreshRateNumerator / (float)Mode.RefreshRateDenominator; - ss << " " << Mode.Width << 'x' << Mode.Height << " " << std::fixed << std::setprecision(2) << RefreshRate << " Hz\n"; - } - } - auto str = ss.str(); - LOG_INFO_MESSAGE(str); - - m_pImmediateContext.Attach(ppContexts[0]); - m_pDeferredContexts.resize(NumDeferredCtx); - for (Diligent::Uint32 ctx = 0; ctx < NumDeferredCtx; ++ctx) - m_pDeferredContexts[ctx].Attach(ppContexts[1 + ctx]); -} - -void TestApp::InitializeRenderers() -{ - m_TestGS.Init(m_pDevice, m_pImmediateContext, m_pSwapChain); - m_TestTessellation.Init(m_pDevice, m_pImmediateContext, m_pSwapChain); - - const auto* BackBufferFmt = m_pDevice->GetTextureFormatInfo(m_pSwapChain->GetDesc().ColorBufferFormat).Name; - const auto* DepthBufferFmt = m_pDevice->GetTextureFormatInfo(m_pSwapChain->GetDesc().DepthBufferFormat).Name; - - m_pTestDrawCommands.reset(new TestDrawCommands); - m_pTestDrawCommands->Init(m_pDevice, m_pImmediateContext, m_pSwapChain, 0, 0, 1, 1); - - m_pTestBufferAccess.reset(new TestBufferAccess); - m_pTestBufferAccess->Init(m_pDevice, m_pImmediateContext, m_pSwapChain, -1, 0, 0.5, 0.5); - - - TEXTURE_FORMAT TestFormats[16] = - { - TEX_FORMAT_RGBA8_UNORM, TEX_FORMAT_RGBA8_UNORM_SRGB, TEX_FORMAT_RGBA32_FLOAT, TEX_FORMAT_RGBA16_UINT, - TEX_FORMAT_RGBA8_SNORM, TEX_FORMAT_RGBA8_UINT, TEX_FORMAT_RG8_UNORM, TEX_FORMAT_RG8_UINT, - TEX_FORMAT_RG32_FLOAT, TEX_FORMAT_RG16_UINT, TEX_FORMAT_RG8_SNORM, TEX_FORMAT_R8_UNORM, - TEX_FORMAT_R32_FLOAT, TEX_FORMAT_R8_SNORM, TEX_FORMAT_R8_UINT, TEX_FORMAT_R16_UINT - }; - - for (int j = 0; j < 4; ++j) - for (int i = 0; i < 4; ++i) - { - auto Ind = i + j * 4; - m_pTestTexturing[Ind].reset(new TestTexturing); - m_pTestTexturing[Ind]->Init(m_pDevice, m_pImmediateContext, m_pSwapChain, TestFormats[Ind], -1 + (float)i*1.f / 4.f, -1 + (float)j*1.f / 4.f, 0.9f / 4.f, 0.9f / 4.f); - } - - TestCopyTexData TestCopyData(m_pDevice, m_pImmediateContext); - - TestVPAndSR TestVPAndSR(m_pDevice, m_pImmediateContext); - - m_pTestCS.reset(new TestComputeShaders); - m_pTestCS->Init(m_pDevice, m_pImmediateContext, m_pSwapChain); - - m_pTestRT.reset(new TestRenderTarget); - m_pTestRT->Init(m_pDevice, m_pImmediateContext, m_pSwapChain, -0.4f, 0.55f, 0.4f, 0.4f); - - float instance_offsets[] = { -0.3f, 0.0f, 0.0f, 0.0f, +0.3f, -0.3f }; - - { - Diligent::BufferDesc BuffDesc; - BuffDesc.Name = "cbTestBlock2"; - float UniformData[16] = { 1,1,1,1 }; - BuffDesc.uiSizeInBytes = sizeof(UniformData); - BuffDesc.BindFlags = BIND_UNIFORM_BUFFER; - BuffDesc.Usage = USAGE_DYNAMIC; - BuffDesc.CPUAccessFlags = CPU_ACCESS_WRITE; - m_pDevice->CreateBuffer(BuffDesc, nullptr, &m_pUniformBuff2); - } - - { - Diligent::BufferDesc BuffDesc; - BuffDesc.Name = "Test Constant Buffer 3"; - float UniformData[16] = { 1, 1, 1, 1 }; - BuffDesc.uiSizeInBytes = sizeof(UniformData); - BuffDesc.BindFlags = BIND_UNIFORM_BUFFER; - BuffDesc.Usage = USAGE_DEFAULT; - BuffDesc.CPUAccessFlags = CPU_ACCESS_NONE; - Diligent::BufferData BuffData; - BuffData.pData = UniformData; - BuffData.DataSize = sizeof(UniformData); - m_pDevice->CreateBuffer(BuffDesc, &BuffData, &m_pUniformBuff3); - } - - { - Diligent::BufferDesc BuffDesc; - BuffDesc.Name = "Test Constant Buffer 4"; - float UniformData[16] = { 1, 1, 1, 1 }; - BuffDesc.uiSizeInBytes = sizeof(UniformData); - BuffDesc.BindFlags = BIND_UNIFORM_BUFFER; - BuffDesc.Usage = USAGE_DEFAULT; - BuffDesc.CPUAccessFlags = CPU_ACCESS_NONE; - Diligent::BufferData BuffData; - BuffData.pData = UniformData; - BuffData.DataSize = sizeof(UniformData); - m_pDevice->CreateBuffer(BuffDesc, &BuffData, &m_pUniformBuff4); - } - - { - TextureDesc TexDesc; - TexDesc.Type = RESOURCE_DIM_TEX_2D; - TexDesc.Width = 1024; - TexDesc.Height = 1024; - TexDesc.Format = TEX_FORMAT_RGBA8_UNORM; - TexDesc.Usage = USAGE_DEFAULT; - TexDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET | BIND_UNORDERED_ACCESS; - TexDesc.Name = "UniqueTexture"; - - m_pDevice->CreateTexture(TexDesc, nullptr, &m_pTestTex); - - m_pTestTex.Release(); - m_pDevice->CreateTexture(TexDesc, nullptr, &m_pTestTex); - } - - { - m_pImmediateContext->Flush(); - // This is a test for possible bug in D3D12 - TextureDesc TexDesc; - TexDesc.Type = RESOURCE_DIM_TEX_2D; - TexDesc.Width = 512; - TexDesc.Height = 512; - TexDesc.Format = m_pSwapChain->GetDesc().ColorBufferFormat; - TexDesc.Usage = USAGE_DEFAULT; - TexDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET; - TexDesc.Name = "UniqueTexture"; - RefCntAutoPtr<ITexture> pTex; - m_pDevice->CreateTexture(TexDesc, nullptr, &pTex); - ITextureView *pRTVs[] = { pTex->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET) }; - - TexDesc.Format = m_pSwapChain->GetDesc().DepthBufferFormat; - RefCntAutoPtr<ITexture> pDepthTex; - TexDesc.BindFlags = BIND_DEPTH_STENCIL; - m_pDevice->CreateTexture(TexDesc, nullptr, &pDepthTex); - auto* pDSV = pDepthTex->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); - - { - MapHelper<float> UniformData(m_pImmediateContext, m_pUniformBuff2, MAP_WRITE, MAP_FLAG_DISCARD); - UniformData[0] = (float)sin(0)*0.1f; - UniformData[1] = (float)cos(0)*0.1f; - UniformData[2] = (float)sin(0)*0.1f; - UniformData[3] = 0; - } - - m_pImmediateContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - float ClearColor[] = {0.1f, 0.2f, 0.4f, 1.0f}; - m_pImmediateContext->ClearRenderTarget(nullptr, ClearColor, RESOURCE_STATE_TRANSITION_MODE_VERIFY); - - // This adds transition barrier for pTex1 - m_pImmediateContext->SetRenderTargets(1, pRTVs, pDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - m_pImmediateContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_VERIFY); - m_pImmediateContext->ClearDepthStencil(pDSV, CLEAR_DEPTH_FLAG, 1, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY); - // Generate draw command to the bound render target - m_pImmediateContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - // This will destroy texture and put D3D12 resource into release queue - pTex.Release(); - - - Diligent::BufferDesc BuffDesc; - BuffDesc.Name = "cbTestBlock2"; - float Data[16] = { 1,1,1,1 }; - BuffDesc.uiSizeInBytes = sizeof(Data); - BuffDesc.BindFlags = BIND_UNIFORM_BUFFER; - BuffDesc.Usage = USAGE_DEFAULT; - BuffDesc.CPUAccessFlags = CPU_ACCESS_NONE; - Diligent::BufferData BuffData; - BuffData.pData = Data; - BuffData.DataSize = sizeof(Data); - // This will result in creating and executing another command list - RefCntAutoPtr<IBuffer> pBuff; - m_pDevice->CreateBuffer(BuffDesc, &BuffData, &pBuff); - - // This may cause D3D12 error - m_pImmediateContext->Flush(); - } - - { - FenceDesc fenceDesc; - fenceDesc.Name = "Test fence"; - m_pDevice->CreateFence(fenceDesc, &m_pFence); - } -} - -void TestApp::ProcessCommandLine(const char *CmdLine) -{ - const auto* Key = "-mode "; - const auto *pos = strstr(CmdLine, Key); - if (pos != nullptr) - { - pos += strlen(Key); - if (_stricmp(pos, "D3D11") == 0) - { - m_DeviceType = DeviceType::D3D11; - } - else if (_stricmp(pos, "D3D12") == 0) - { - m_DeviceType = DeviceType::D3D12; - } - else if (_stricmp(pos, "GL") == 0) - { - m_DeviceType = DeviceType::OpenGL; - } - else if (_stricmp(pos, "VK") == 0) - { - m_DeviceType = DeviceType::Vulkan; - } - else - { - LOG_ERROR_AND_THROW("Unknown device type. Only the following types are supported: D3D11, D3D12, GL, VK"); - } - } - else - { -#if D3D12_SUPPORTED - m_DeviceType = DeviceType::D3D12; -#elif VULKAN_SUPPORTED - m_DeviceType = DeviceType::Vulkan; -#elif D3D11_SUPPORTED - m_DeviceType = DeviceType::D3D11; -#elif GL_SUPPORTED || GLES_SUPPORTED - m_DeviceType = DeviceType::OpenGL; -#endif - } - - switch (m_DeviceType) - { - case DeviceType::D3D11: m_AppTitle.append(" (D3D11)"); break; - case DeviceType::D3D12: m_AppTitle.append(" (D3D12)"); break; - case DeviceType::OpenGL: m_AppTitle.append(" (OpenGL)"); break; - case DeviceType::Vulkan: m_AppTitle.append(" (Vulkan)"); break; - default: UNEXPECTED("Unknown device type"); - } -} - -void TestApp::WindowResize(int width, int height) -{ - if (m_pSwapChain) - { - m_pSwapChain->Resize(width, height); - //auto SCWidth = m_pSwapChain->GetDesc().Width; - //auto SCHeight = m_pSwapChain->GetDesc().Height; - - - } -} - -void TestApp::Update(double CurrTime, double ElapsedTime) -{ - m_CurrTime = CurrTime; -} - -void TestApp::Render() -{ - m_pImmediateContext->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - float ClearColor[] = {0.1f, 0.2f, 0.4f, 1.0f}; - m_pImmediateContext->ClearRenderTarget(nullptr, ClearColor, RESOURCE_STATE_TRANSITION_MODE_VERIFY); - m_pImmediateContext->ClearDepthStencil(nullptr, CLEAR_DEPTH_FLAG, 1.f, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY); - - double dCurrTime = m_CurrTime; - - - m_pTestDrawCommands->Draw(); - m_pTestBufferAccess->Draw((float)dCurrTime); - - for (int i = 0; i<_countof(m_pTestTexturing); ++i) - { - m_pTestTexturing[i]->Draw(); - } - m_pTestCS->Draw(); - m_pTestRT->Draw(); - m_TestGS.Draw(); - - auto CompletedFenceValue = m_pFence->GetCompletedValue(); - VERIFY_EXPR(CompletedFenceValue < m_NextFenceValue); - m_pImmediateContext->SignalFence(m_pFence, m_NextFenceValue++); - - CompletedFenceValue = m_pFence->GetCompletedValue(); - VERIFY_EXPR(CompletedFenceValue < m_NextFenceValue); - - if (rand() % 10 == 0) - { - if (rand() % 2 == 0) - { - m_pImmediateContext->Flush(); - m_pImmediateContext->SignalFence(m_pFence, m_NextFenceValue++); - } - - m_pImmediateContext->WaitForFence(m_pFence, m_NextFenceValue-1, true); - CompletedFenceValue = m_pFence->GetCompletedValue(); - VERIFY_EXPR(CompletedFenceValue >= m_NextFenceValue-1); - } - - if (rand() % 30 == 0) - { - m_pImmediateContext->WaitForIdle(); - } - - if (rand() % 60 == 0) - { - m_pDevice->IdleGPU(); - } - - m_TestTessellation.Draw(); - - m_pImmediateContext->Flush(); - m_pImmediateContext->InvalidateState(); -} - -void TestApp::Present() -{ - m_pSwapChain->Present(0); -} - -} |
