Calculate Graphics Memory Usage

This commit is contained in:
lanariel 2014-02-05 16:54:57 +01:00
parent 51711b86e3
commit aafbfa01f3
11 changed files with 39 additions and 3 deletions

View File

@ -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); //MessageBox(NULL, L"Unable to create buffer.", L"Slenda Error", MB_ICONERROR | MB_OK);
} }
else
{
Core::UsedMem += bufferDesc.ByteWidth;
}
return hr; return hr;
} }

View File

@ -33,4 +33,6 @@ Oyster::Math::Float2 Core::resolution = Oyster::Math::Float2::null;
ID3D11ShaderResourceView* Core::srvNULL[16] = {0}; ID3D11ShaderResourceView* Core::srvNULL[16] = {0};
ID3D11RenderTargetView* Core::rtvNULL[8] = {0}; ID3D11RenderTargetView* Core::rtvNULL[8] = {0};
ID3D11UnorderedAccessView* Core::uavNULL[8] = {0}; ID3D11UnorderedAccessView* Core::uavNULL[8] = {0};
int Core::UsedMem = 0;

View File

@ -46,6 +46,8 @@ namespace Oyster
static ID3D11RenderTargetView* rtvNULL[8]; static ID3D11RenderTargetView* rtvNULL[8];
static ID3D11UnorderedAccessView* uavNULL[8]; static ID3D11UnorderedAccessView* uavNULL[8];
static int UsedMem;
class Buffer class Buffer
{ {
public: public:

View File

@ -110,6 +110,7 @@ namespace Oyster
if(Core::swapChain) if(Core::swapChain)
{ {
Core::swapChain->Release(); Core::swapChain->Release();
Core::UsedMem -= desc.BufferDesc.Height * desc.BufferDesc.Width * 16;
delete Core::swapChain; delete Core::swapChain;
} }
@ -167,7 +168,7 @@ namespace Oyster
} }
dxgiFactory->Release(); dxgiFactory->Release();
Core::UsedMem += desc.BufferDesc.Height * desc.BufferDesc.Width * 16;
return Init::Success; return Init::Success;
} }
@ -187,6 +188,7 @@ namespace Oyster
if(Core::depthStencil) if(Core::depthStencil)
{ {
Core::depthStencil->Release(); Core::depthStencil->Release();
Core::UsedMem -= desc.Height * desc.Width * 4;
delete Core::depthStencil; delete Core::depthStencil;
} }
@ -214,6 +216,7 @@ namespace Oyster
{ {
return Init::Fail; return Init::Fail;
} }
Core::UsedMem += desc.Height * desc.Width * 4;
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = DXGI_FORMAT_D32_FLOAT; dsvDesc.Format = DXGI_FORMAT_D32_FLOAT;
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
@ -382,6 +385,9 @@ namespace Oyster
if(FAILED(Core::device->CreateTexture2D(&texDesc,NULL,&tex))) if(FAILED(Core::device->CreateTexture2D(&texDesc,NULL,&tex)))
return State::Fail; return State::Fail;
Core::UsedMem += texDesc.Height*texDesc.Width*16;
if(rtv) if(rtv)
{ {
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;

View File

@ -143,5 +143,14 @@ namespace Oyster
return State::Sucsess; return State::Sucsess;
} }
#endif #endif
API::Option API::GetOption()
{
Option o;
o.BytesUsed = Core::UsedMem;
o.modelPath = Core::modelPath;
o.texturePath = Core::texturePath;
return o;
}
} }
} }

View File

@ -27,6 +27,7 @@ namespace Oyster
struct Option struct Option
{ {
std::wstring modelPath, texturePath; std::wstring modelPath, texturePath;
int BytesUsed;
}; };
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); 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 //! @brief removes all lights from the scene
static void ClearLights(); static void ClearLights();
//! @brief Sets Options to the graphics, note: currently unused //! @brief Sets Options to the graphics
static State SetOptions(Option); static State SetOptions(Option);
//! @brief Gets Options to the graphics
static Option GetOption();
}; };
} }
} }

View File

@ -690,6 +690,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1; SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1;
//TODO calc mipmap data
hr = d3dDevice->CreateShaderResourceView( tex, &SRVDesc, textureView ); hr = d3dDevice->CreateShaderResourceView( tex, &SRVDesc, textureView );
if ( FAILED(hr) ) if ( FAILED(hr) )
@ -697,6 +698,9 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
tex->Release(); tex->Release();
return hr; return hr;
} }
//todo check calc
int TexSize = twidth * theight * bpp;
Oyster::Graphics::Core::UsedMem += TexSize;
if ( autogen ) if ( autogen )
{ {

View File

@ -146,6 +146,7 @@ namespace Oyster
return NULL; return NULL;
} }
#endif #endif
Core::UsedMem += data.size;
return Core::PipelineManager::CreateShader(data, Core::PipelineManager::ShaderType(type)); return Core::PipelineManager::CreateShader(data, Core::PipelineManager::ShaderType(type));
} }
} }

View File

@ -43,6 +43,7 @@ namespace Oyster
ID3D11ShaderResourceView* Deffered::SSAOKernel = NULL; ID3D11ShaderResourceView* Deffered::SSAOKernel = NULL;
ID3D11ShaderResourceView* Deffered::SSAORandom = NULL; ID3D11ShaderResourceView* Deffered::SSAORandom = NULL;
Core::Init::State Deffered::InitShaders() Core::Init::State Deffered::InitShaders()
{ {
#ifdef _DEBUG #ifdef _DEBUG

View File

@ -17,6 +17,7 @@ namespace Oyster
static const int GBufferSize = 2; static const int GBufferSize = 2;
static const int LBufferSize = 3; static const int LBufferSize = 3;
static const int MaxLightSize = 100; static const int MaxLightSize = 100;
//! GBuffers //! GBuffers
//! 0 = Diffuse + Glow //! 0 = Diffuse + Glow
//! 1 = Normal + Spec //! 1 = Normal + Spec

View File

@ -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(m);
Oyster::Graphics::API::DeleteModel(m2); Oyster::Graphics::API::DeleteModel(m2);
Oyster::Graphics::API::DeleteModel(m3); Oyster::Graphics::API::DeleteModel(m3);