From 55028f171a9092bb820aa2fa09f505bb3a828e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Fri, 7 Sep 2018 10:29:36 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 075a1e97e..b674f3e24 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Python script which will generate the SPIR-V shader building program "build_SPIR is automatic if you start the application with Vulkan support. This feature is experimental, not tested thoroughly yet. -* **To load HLSL 6 shaders, replicate the exact steps as with SPIR-V, but the pyhton script you should run is called "generate_shader_buildtask_spirv.py" which will generate "build_HLSL6.bat". +* **To load HLSL 6 shaders, replicate the exact steps as with SPIR-V, but the pyhton script you should run is called "generate_shader_buildtask_hlsl6.py" which will generate "build_HLSL6.bat". This feature is experimental, not tested thoroughly yet. ### Platforms: From f471f78934f513ff129875b36d52465d3d11d302 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Fri, 14 Sep 2018 12:48:31 +0100 Subject: [PATCH 2/2] fix: change resolution, resize window, gui scaling --- Editor/main.cpp | 12 ++++++ Template_Windows/main.cpp | 11 +++++ Tests/main.cpp | 11 +++++ WickedEngine/Renderable2DComponent.cpp | 2 + WickedEngine/Renderable3DComponent.cpp | 2 + WickedEngine/wiGUI.cpp | 12 ++++++ WickedEngine/wiGUI.h | 3 +- WickedEngine/wiGraphicsDevice_DX11.cpp | 59 ++++++++++++++++---------- WickedEngine/wiGraphicsDevice_DX11.h | 17 ++++---- WickedEngine/wiGraphicsDevice_DX12.cpp | 21 +++++++-- WickedEngine/wiVersion.cpp | 2 +- WickedEngine/wiWidget.cpp | 6 +-- 12 files changed, 120 insertions(+), 38 deletions(-) diff --git a/Editor/main.cpp b/Editor/main.cpp index 3b406a22b..cfcdee36e 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -206,6 +206,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } break; + case WM_SIZE: + { + if (wiRenderer::graphicsDevice) + { + int width = LOWORD(lParam); + int height = HIWORD(lParam); + + wiRenderer::GetDevice()->SetResolution(width, height); + wiRenderer::getCamera()->SetUp((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800); + } + } + break; case WM_MBUTTONDOWN: ShowCursor(false); break; diff --git a/Template_Windows/main.cpp b/Template_Windows/main.cpp index faad022a5..d5f00b861 100644 --- a/Template_Windows/main.cpp +++ b/Template_Windows/main.cpp @@ -157,6 +157,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } break; + case WM_SIZE: + { + if (wiRenderer::graphicsDevice) + { + int width = LOWORD(lParam); + int height = HIWORD(lParam); + + wiRenderer::GetDevice()->SetResolution(width, height); + wiRenderer::getCamera()->SetUp((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800); + } + } case WM_KEYDOWN: switch (wParam) { diff --git a/Tests/main.cpp b/Tests/main.cpp index 3fb4468a3..8c8465201 100644 --- a/Tests/main.cpp +++ b/Tests/main.cpp @@ -159,6 +159,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } break; + case WM_SIZE: + { + if (wiRenderer::graphicsDevice) + { + int width = LOWORD(lParam); + int height = HIWORD(lParam); + + wiRenderer::GetDevice()->SetResolution(width, height); + wiRenderer::getCamera()->SetUp((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800); + } + } case WM_KEYDOWN: switch (wParam) { diff --git a/WickedEngine/Renderable2DComponent.cpp b/WickedEngine/Renderable2DComponent.cpp index 3f7ec5794..374cdbb04 100644 --- a/WickedEngine/Renderable2DComponent.cpp +++ b/WickedEngine/Renderable2DComponent.cpp @@ -22,6 +22,8 @@ Renderable2DComponent::~Renderable2DComponent() wiRenderTarget Renderable2DComponent::rtFinal; void Renderable2DComponent::ResizeBuffers() { + wiRenderer::GetDevice()->WaitForGPU(); + FORMAT defaultTextureFormat = wiRenderer::GetDevice()->GetBackBufferFormat(); // Protect against multiple buffer resizes when there is no change! diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index 3db4d4595..28d9c840f 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -37,6 +37,8 @@ void Renderable3DComponent::ResizeBuffers() { Renderable2DComponent::ResizeBuffers(); + wiRenderer::GetDevice()->WaitForGPU(); + FORMAT defaultTextureFormat = wiRenderer::GetDevice()->GetBackBufferFormat(); // Protect against multiple buffer resizes when there is no change! diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index 3a0196485..2587ff96b 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -8,6 +8,9 @@ using namespace std; wiGUI::wiGUI(GRAPHICSTHREAD threadID) :threadID(threadID), activeWidget(nullptr), focus(false), visible(true), pointerpos(XMFLOAT2(0,0)) { + Transform::scale_rest.x = (float)wiRenderer::GetDevice()->GetScreenWidth(); + Transform::scale_rest.y = (float)wiRenderer::GetDevice()->GetScreenHeight(); + Transform::UpdateTransform(); } @@ -23,6 +26,13 @@ void wiGUI::Update(float dt) return; } + if (wiRenderer::GetDevice()->ResolutionChanged()) + { + Transform::scale_rest.x = (float)wiRenderer::GetDevice()->GetScreenWidth(); + Transform::scale_rest.y = (float)wiRenderer::GetDevice()->GetScreenHeight(); + Transform::UpdateTransform(); + } + XMFLOAT4 _p = wiInputManager::GetInstance()->getpointer(); pointerpos.x = _p.x; pointerpos.y = _p.y; @@ -95,11 +105,13 @@ void wiGUI::ResetScissor() void wiGUI::AddWidget(wiWidget* widget) { + widget->attachTo(this); widgets.push_back(widget); } void wiGUI::RemoveWidget(wiWidget* widget) { + this->detachChild(widget); widgets.remove(widget); } diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index 546f9deb2..7b8b27eab 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -1,6 +1,7 @@ #pragma once #include "CommonInclude.h" #include "wiEnums.h" +#include "wiSceneComponents.h" #include @@ -8,7 +9,7 @@ class wiHashString; class wiWidget; -class wiGUI +class wiGUI : public wiSceneComponents::Transform { friend class wiWidget; private: diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index a31829180..965d010e4 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -1535,27 +1535,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo //D3D11_FEATURE_DATA_D3D11_OPTIONS3 features_3; //hr = device->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS3, &features_3, sizeof(features_3)); - // Create a render target view - backBuffer = NULL; - hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer); - if (FAILED(hr)) { - wiHelper::messageBox("BackBuffer creation Failed!", "Error!"); - exit(1); - } - - hr = device->CreateRenderTargetView(backBuffer, NULL, &renderTargetView); - if (FAILED(hr)) { - wiHelper::messageBox("Main Rendertarget creation Failed!", "Error!"); - exit(1); - } - - // Setup the main viewport - viewPort.Width = (FLOAT)SCREENWIDTH; - viewPort.Height = (FLOAT)SCREENHEIGHT; - viewPort.MinDepth = 0.0f; - viewPort.MaxDepth = 1.0f; - viewPort.TopLeftX = 0; - viewPort.TopLeftY = 0; + CreateBackBufferResources(); } GraphicsDevice_DX11::~GraphicsDevice_DX11() @@ -1571,13 +1551,40 @@ GraphicsDevice_DX11::~GraphicsDevice_DX11() SAFE_RELEASE(device); } +void GraphicsDevice_DX11::CreateBackBufferResources() +{ + SAFE_RELEASE(backBuffer); + SAFE_RELEASE(renderTargetView); + + HRESULT hr; + + hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer); + if (FAILED(hr)) { + wiHelper::messageBox("BackBuffer creation Failed!", "Error!"); + exit(1); + } + + hr = device->CreateRenderTargetView(backBuffer, nullptr, &renderTargetView); + if (FAILED(hr)) { + wiHelper::messageBox("Main Rendertarget creation Failed!", "Error!"); + exit(1); + } +} + void GraphicsDevice_DX11::SetResolution(int width, int height) { if (width != SCREENWIDTH || height != SCREENHEIGHT) { SCREENWIDTH = width; SCREENHEIGHT = height; - swapChain->ResizeBuffers(2, width, height, _ConvertFormat(GetBackBufferFormat()), 0); + + SAFE_RELEASE(backBuffer); + SAFE_RELEASE(renderTargetView); + HRESULT hr = swapChain->ResizeBuffers(GetBackBufferCount(), width, height, _ConvertFormat(GetBackBufferFormat()), 0); + assert(SUCCEEDED(hr)); + + CreateBackBufferResources(); + RESOLUTIONCHANGED = true; } } @@ -2964,7 +2971,15 @@ void GraphicsDevice_DX11::SetName(GPUResource* pResource, const std::string& nam void GraphicsDevice_DX11::PresentBegin() { + ViewPort viewPort; + viewPort.Width = (FLOAT)SCREENWIDTH; + viewPort.Height = (FLOAT)SCREENHEIGHT; + viewPort.MinDepth = 0.0f; + viewPort.MaxDepth = 1.0f; + viewPort.TopLeftX = 0; + viewPort.TopLeftY = 0; BindViewports(1, &viewPort, GRAPHICSTHREAD_IMMEDIATE); + deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->OMSetRenderTargets(1, &renderTargetView, 0); float ClearColor[4] = { 0, 0, 0, 1.0f }; // red,green,blue,alpha deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->ClearRenderTargetView(renderTargetView, ClearColor); diff --git a/WickedEngine/wiGraphicsDevice_DX11.h b/WickedEngine/wiGraphicsDevice_DX11.h index 529928434..762a66012 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.h +++ b/WickedEngine/wiGraphicsDevice_DX11.h @@ -21,16 +21,15 @@ namespace wiGraphicsTypes class GraphicsDevice_DX11 : public GraphicsDevice { private: - ID3D11Device* device; + ID3D11Device* device = nullptr; D3D_DRIVER_TYPE driverType; D3D_FEATURE_LEVEL featureLevel; - IDXGISwapChain1* swapChain; - ID3D11RenderTargetView* renderTargetView; - ID3D11Texture2D* backBuffer; - ViewPort viewPort; - ID3D11DeviceContext* deviceContexts[GRAPHICSTHREAD_COUNT]; - ID3D11CommandList* commandLists[GRAPHICSTHREAD_COUNT]; - ID3DUserDefinedAnnotation* userDefinedAnnotations[GRAPHICSTHREAD_COUNT]; + IDXGISwapChain1* swapChain = nullptr; + ID3D11RenderTargetView* renderTargetView = nullptr; + ID3D11Texture2D* backBuffer = nullptr; + ID3D11DeviceContext* deviceContexts[GRAPHICSTHREAD_COUNT] = {}; + ID3D11CommandList* commandLists[GRAPHICSTHREAD_COUNT] = {}; + ID3DUserDefinedAnnotation* userDefinedAnnotations[GRAPHICSTHREAD_COUNT] = {}; UINT stencilRef[GRAPHICSTHREAD_COUNT]; XMFLOAT4 blendFactor[GRAPHICSTHREAD_COUNT]; @@ -54,6 +53,8 @@ namespace wiGraphicsTypes uint8_t raster_uavs_count[GRAPHICSTHREAD_COUNT] = {}; void validate_raster_uavs(GRAPHICSTHREAD threadID); + void CreateBackBufferResources(); + public: GraphicsDevice_DX11(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false); diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 7f488fcf3..8d26a127d 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -2038,7 +2038,24 @@ namespace wiGraphicsTypes { SCREENWIDTH = width; SCREENHEIGHT = height; - swapChain->ResizeBuffers(2, width, height, _ConvertFormat(GetBackBufferFormat()), 0); + + WaitForGPU(); + + for (UINT fr = 0; fr < BACKBUFFER_COUNT; ++fr) + { + SAFE_RELEASE(frames[fr].backBuffer); + } + + HRESULT hr = swapChain->ResizeBuffers(GetBackBufferCount(), width, height, _ConvertFormat(GetBackBufferFormat()), 0); + assert(SUCCEEDED(hr)); + + for (UINT fr = 0; fr < BACKBUFFER_COUNT; ++fr) + { + hr = swapChain->GetBuffer(fr, __uuidof(ID3D12Resource), (void**)&frames[fr].backBuffer); + assert(SUCCEEDED(hr)); + device->CreateRenderTargetView(frames[fr].backBuffer, nullptr, *frames[fr].backBufferRTV); + } + RESOLUTIONCHANGED = true; } } @@ -3349,7 +3366,6 @@ namespace wiGraphicsTypes { HRESULT result; - // Indicate that the back buffer will now be used to present. D3D12_RESOURCE_BARRIER barrier = {}; barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; @@ -3416,7 +3432,6 @@ namespace wiGraphicsTypes GetFrameResources().SamplerDescriptorsGPU[threadID]->reset(device, nullDescriptors); GetFrameResources().resourceBuffer[threadID]->clear(); - D3D12_RECT pRects[8]; for (UINT i = 0; i < 8; ++i) { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 2c19f1011..4640be8bc 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 20; // minor bug fixes, alterations, refactors, updates - const int revision = 3; + const int revision = 4; long GetVersion() diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 3a26916fb..18a41c87c 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -771,7 +771,7 @@ void wiSlider::Render(wiGUI* gui) wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) , wiImageEffects(headPosX - headWidth * 0.5f, translation.y, headWidth, scale.y), gui->GetGraphicsThread()); - if (parent != nullptr) + if (parent != gui) { wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); } @@ -908,7 +908,7 @@ void wiCheckBox::Render(wiGUI* gui) , gui->GetGraphicsThread()); } - if (parent != nullptr) + if (parent != gui) { wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); } @@ -1096,7 +1096,7 @@ void wiComboBox::Render(wiGUI* gui) textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); - if (parent != nullptr) + if (parent != gui) { wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); }