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);
}
else
{
Core::UsedMem += bufferDesc.ByteWidth;
}
return hr;
}

View File

@ -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};
ID3D11UnorderedAccessView* Core::uavNULL[8] = {0};
int Core::UsedMem = 0;

View File

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

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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();
};
}
}

View File

@ -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 )
{

View File

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

View File

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

View File

@ -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

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