From aafbfa01f3995f321ed82cdb3b6ae46d6758682d Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 5 Feb 2014 16:54:57 +0100 Subject: [PATCH] Calculate Graphics Memory Usage --- Code/OysterGraphics/Core/Buffer.cpp | 4 ++++ Code/OysterGraphics/Core/Core.cpp | 4 +++- Code/OysterGraphics/Core/Core.h | 2 ++ Code/OysterGraphics/Core/Init.cpp | 8 +++++++- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 9 +++++++++ Code/OysterGraphics/DllInterfaces/GFXAPI.h | 6 +++++- Code/OysterGraphics/FileLoader/ModelLoader.cpp | 4 ++++ Code/OysterGraphics/FileLoader/ShaderLoader.cpp | 1 + Code/OysterGraphics/Render/Resources/Deffered.cpp | 1 + Code/OysterGraphics/Render/Resources/Deffered.h | 1 + Code/Tester/MainTest.cpp | 2 ++ 11 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Code/OysterGraphics/Core/Buffer.cpp b/Code/OysterGraphics/Core/Buffer.cpp index d6994554..6cef2b17 100644 --- a/Code/OysterGraphics/Core/Buffer.cpp +++ b/Code/OysterGraphics/Core/Buffer.cpp @@ -155,6 +155,10 @@ HRESULT Core::Buffer::Init(const BUFFER_INIT_DESC& initDesc) { //MessageBox(NULL, L"Unable to create buffer.", L"Slenda Error", MB_ICONERROR | MB_OK); } + else + { + Core::UsedMem += bufferDesc.ByteWidth; + } return hr; } diff --git a/Code/OysterGraphics/Core/Core.cpp b/Code/OysterGraphics/Core/Core.cpp index f2392f4c..d03a64ef 100644 --- a/Code/OysterGraphics/Core/Core.cpp +++ b/Code/OysterGraphics/Core/Core.cpp @@ -33,4 +33,6 @@ Oyster::Math::Float2 Core::resolution = Oyster::Math::Float2::null; ID3D11ShaderResourceView* Core::srvNULL[16] = {0}; ID3D11RenderTargetView* Core::rtvNULL[8] = {0}; -ID3D11UnorderedAccessView* Core::uavNULL[8] = {0}; \ No newline at end of file +ID3D11UnorderedAccessView* Core::uavNULL[8] = {0}; + +int Core::UsedMem = 0; \ No newline at end of file diff --git a/Code/OysterGraphics/Core/Core.h b/Code/OysterGraphics/Core/Core.h index 050d54c5..eb420c04 100644 --- a/Code/OysterGraphics/Core/Core.h +++ b/Code/OysterGraphics/Core/Core.h @@ -46,6 +46,8 @@ namespace Oyster static ID3D11RenderTargetView* rtvNULL[8]; static ID3D11UnorderedAccessView* uavNULL[8]; + static int UsedMem; + class Buffer { public: diff --git a/Code/OysterGraphics/Core/Init.cpp b/Code/OysterGraphics/Core/Init.cpp index 05a91a59..f0b4907f 100644 --- a/Code/OysterGraphics/Core/Init.cpp +++ b/Code/OysterGraphics/Core/Init.cpp @@ -110,6 +110,7 @@ namespace Oyster if(Core::swapChain) { Core::swapChain->Release(); + Core::UsedMem -= desc.BufferDesc.Height * desc.BufferDesc.Width * 16; delete Core::swapChain; } @@ -167,7 +168,7 @@ namespace Oyster } dxgiFactory->Release(); - + Core::UsedMem += desc.BufferDesc.Height * desc.BufferDesc.Width * 16; return Init::Success; } @@ -187,6 +188,7 @@ namespace Oyster if(Core::depthStencil) { Core::depthStencil->Release(); + Core::UsedMem -= desc.Height * desc.Width * 4; delete Core::depthStencil; } @@ -214,6 +216,7 @@ namespace Oyster { return Init::Fail; } + Core::UsedMem += desc.Height * desc.Width * 4; D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; dsvDesc.Format = DXGI_FORMAT_D32_FLOAT; dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; @@ -382,6 +385,9 @@ namespace Oyster if(FAILED(Core::device->CreateTexture2D(&texDesc,NULL,&tex))) return State::Fail; + + Core::UsedMem += texDesc.Height*texDesc.Width*16; + if(rtv) { D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index ad010c8b..66476a89 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -143,5 +143,14 @@ namespace Oyster return State::Sucsess; } #endif + + API::Option API::GetOption() + { + Option o; + o.BytesUsed = Core::UsedMem; + o.modelPath = Core::modelPath; + o.texturePath = Core::texturePath; + return o; + } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index 81a3bedc..555e8a0c 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -27,6 +27,7 @@ namespace Oyster struct Option { std::wstring modelPath, texturePath; + int BytesUsed; }; static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); @@ -63,8 +64,11 @@ namespace Oyster //! @brief removes all lights from the scene static void ClearLights(); - //! @brief Sets Options to the graphics, note: currently unused + //! @brief Sets Options to the graphics static State SetOptions(Option); + + //! @brief Gets Options to the graphics + static Option GetOption(); }; } } diff --git a/Code/OysterGraphics/FileLoader/ModelLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp index b7b8b09a..fba207d1 100644 --- a/Code/OysterGraphics/FileLoader/ModelLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -690,6 +690,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1; + //TODO calc mipmap data hr = d3dDevice->CreateShaderResourceView( tex, &SRVDesc, textureView ); if ( FAILED(hr) ) @@ -697,6 +698,9 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, tex->Release(); return hr; } + //todo check calc + int TexSize = twidth * theight * bpp; + Oyster::Graphics::Core::UsedMem += TexSize; if ( autogen ) { diff --git a/Code/OysterGraphics/FileLoader/ShaderLoader.cpp b/Code/OysterGraphics/FileLoader/ShaderLoader.cpp index 5edc86dd..033be403 100644 --- a/Code/OysterGraphics/FileLoader/ShaderLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ShaderLoader.cpp @@ -146,6 +146,7 @@ namespace Oyster return NULL; } #endif + Core::UsedMem += data.size; return Core::PipelineManager::CreateShader(data, Core::PipelineManager::ShaderType(type)); } } diff --git a/Code/OysterGraphics/Render/Resources/Deffered.cpp b/Code/OysterGraphics/Render/Resources/Deffered.cpp index 361a94dd..c767da77 100644 --- a/Code/OysterGraphics/Render/Resources/Deffered.cpp +++ b/Code/OysterGraphics/Render/Resources/Deffered.cpp @@ -43,6 +43,7 @@ namespace Oyster ID3D11ShaderResourceView* Deffered::SSAOKernel = NULL; ID3D11ShaderResourceView* Deffered::SSAORandom = NULL; + Core::Init::State Deffered::InitShaders() { #ifdef _DEBUG diff --git a/Code/OysterGraphics/Render/Resources/Deffered.h b/Code/OysterGraphics/Render/Resources/Deffered.h index 025da28b..d422f722 100644 --- a/Code/OysterGraphics/Render/Resources/Deffered.h +++ b/Code/OysterGraphics/Render/Resources/Deffered.h @@ -17,6 +17,7 @@ namespace Oyster static const int GBufferSize = 2; static const int LBufferSize = 3; static const int MaxLightSize = 100; + //! GBuffers //! 0 = Diffuse + Glow //! 1 = Normal + Spec diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 279f89f2..31a2c8fc 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -90,6 +90,8 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL } } + Oyster::Graphics::API::Option o = Oyster::Graphics::API::GetOption(); + Oyster::Graphics::API::DeleteModel(m); Oyster::Graphics::API::DeleteModel(m2); Oyster::Graphics::API::DeleteModel(m3);