Fixed Mem leaks on gpu and start on deffered pipeline

This commit is contained in:
lanariel 2013-12-05 14:56:34 +01:00
parent 47aa2c89a2
commit fb51881fab
16 changed files with 171 additions and 34 deletions

View File

@ -120,11 +120,12 @@ void OysterResource::Clean()
//Remove all the references
while (!OResource::Release(i->second));
const wchar_t* temp = i->second->GetResourceFilename();
std::wstring temp = i->second->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}
resourcePrivate.resources.clear();
}
void OysterResource::ReleaseResource(const OHRESOURCE& resourceData)
{
@ -133,7 +134,7 @@ void OysterResource::ReleaseResource(const OHRESOURCE& resourceData)
{
if(OResource::Release(t))
{
const wchar_t* temp = t->GetResourceFilename();
std::wstring temp = t->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}
@ -146,7 +147,7 @@ void OysterResource::ReleaseResource(const wchar_t filename[])
{
if(OResource::Release(t))
{
const wchar_t* temp = t->GetResourceFilename();
std::wstring temp = t->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}

View File

@ -279,7 +279,7 @@ namespace Oyster
void Core::ShaderManager::Clean()
{
for(int i = 0; i < VData.size(); ++i)
for(int i = 0; i < (int)VData.size(); ++i)
{
delete[] VData[i].data;
}

View File

@ -4,11 +4,18 @@
#include "../Render/Rendering/Render.h"
#include "../FileLoader/ObjReader.h"
#include "../../Misc/Resource/OysterResource.h"
#include "../FileLoader/GeneralLoader.h"
namespace Oyster
{
namespace Graphics
{
namespace
{
Math::Float4x4 View;
Math::Float4x4 Projection;
}
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion)
{
Core::resolution = resulotion;
@ -26,16 +33,31 @@ namespace Oyster
return API::Sucsess;
}
void API::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection)
void API::SetProjection(Math::Float4x4& projection)
{
Projection = projection;
}
void API::SetView(Math::Float4x4& view)
{
View = view;
}
void API::NewFrame()
{
Render::Rendering::Basic::NewFrame(View, Projection);
}
void API::RenderScene(Model::Model* models, int count)
void API::RenderScene(Model::Model models[], int count)
{
Render::Rendering::Basic::RenderScene(models,count);
}
void API::RenderModel(Model::Model& m)
{
Render::Rendering::Basic::RenderScene(&m,1);
}
void API::EndFrame()
{
Render::Rendering::Basic::EndFrame();
@ -52,9 +74,7 @@ namespace Oyster
m->WorldMatrix = Oyster::Math::Float4x4::identity;
m->Visible = true;
OBJReader or;
or.readOBJFile(filename);
m->info = or.toModel();
m->info = Oyster::Resource::OysterResource::LoadResource(filename.c_str(),Oyster::Graphics::Loading::LoadOBJ);
return m;
}
@ -63,12 +83,7 @@ namespace Oyster
{
Model::ModelInfo* info = (Model::ModelInfo*)model->info;
delete model;
SAFE_DELETE(info->Vertices);
if(info->Indexed)
{
SAFE_DELETE(info->Indecies);
}
delete info;
Oyster::Resource::OysterResource::ReleaseResource((Oyster::Resource::OHRESOURCE)info);
}
void API::Clean()
@ -77,6 +92,14 @@ namespace Oyster
Oyster::Resource::OysterResource::Clean();
Oyster::Graphics::Core::ShaderManager::Clean();
Oyster::Graphics::Render::Resources::Clean();
SAFE_RELEASE(Core::depthStencil);
SAFE_RELEASE(Core::backBufferRTV);
SAFE_RELEASE(Core::backBufferUAV);
SAFE_RELEASE(Core::swapChain);
SAFE_RELEASE(Core::deviceContext);
SAFE_RELEASE(Core::device);
}
}
}

View File

@ -28,9 +28,14 @@ namespace Oyster
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion);
static void Clean();
//! @brief from Oyster::Math Float4x4, expects corect methods
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection);
static void RenderScene(Oyster::Graphics::Model::Model* models, int count);
static void SetView(Oyster::Math::Float4x4& View);
static void SetProjection(Oyster::Math::Float4x4& Projection);
//! @brief will internally use last values from SetView and SetProjection
static void NewFrame();
static void RenderScene(Oyster::Graphics::Model::Model models[], int count);
static void RenderModel(Oyster::Graphics::Model::Model& model);
static void EndFrame();
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);

View File

@ -27,7 +27,8 @@ namespace Oyster
void UnloadShaderD(void* loadedData);
void LoadShaderD(const wchar_t filename[], Oyster::Resource::CustomData& out);
void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type);
void UnloadOBJ(void* loadedData);
void LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out);
}
}
}

View File

@ -1,6 +1,7 @@
#include "GeneralLoader.h"
#include "..\Core\Dx11Includes.h"
#include "..\Core\Core.h"
#include "ObjReader.h"
HRESULT CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
ID3D11DeviceContext* d3dContext,
@ -35,6 +36,30 @@ void Oyster::Graphics::Loading::UnloadTexture(void* data)
SAFE_RELEASE(srv);
}
void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out)
{
OBJReader obj;
obj.readOBJFile(filename);
Model::ModelInfo* info;
info = obj.toModel();
out.loadedData = info;
out.resourceUnloadFnc = Oyster::Graphics::Loading::UnloadOBJ;
}
void Oyster::Graphics::Loading::UnloadOBJ(void* data)
{
Model::ModelInfo* info = (Model::ModelInfo*) data;
SAFE_DELETE(info->Vertices);
if(info->Indexed)
{
SAFE_DELETE(info->Indecies);
}
for(int i =0;i<info->Material.size();++i)
{
Oyster::Resource::OysterResource::ReleaseResource(info->Material[i]);
}
delete info;
}
#include <wrl.h>
#include <memory>

View File

@ -10,6 +10,8 @@ namespace Oyster
{
namespace Loading
{
void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type);
void UnloadShaderP(void* loadedData)
{
ID3D11PixelShader* ps = ((ID3D11PixelShader*)loadedData);

View File

@ -178,7 +178,7 @@
<ClCompile Include="DllInterfaces\GFXAPI.cpp" />
<ClCompile Include="FileLoader\ObjReader.cpp" />
<ClCompile Include="FileLoader\ShaderLoader.cpp" />
<ClCompile Include="FileLoader\TextureLoader.cpp" />
<ClCompile Include="FileLoader\ModelLoader.cpp" />
<ClCompile Include="Render\Preparations\BasicPreparations.cpp" />
<ClCompile Include="Render\Rendering\BasicRender.cpp" />
<ClCompile Include="Render\Resources\Resources.cpp" />
@ -270,6 +270,8 @@
<ItemGroup>
<None Include="Shader\HLSL\Deffered Shaders\GatherGBuffer\GBufferHeader.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\Defines.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\LightCalc.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\PosManipulation.hlsli" />
<None Include="Shader\HLSL\SimpleDebug\Debug.hlsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -2,6 +2,8 @@
#include "../Resources/Resources.h"
#include "../../Definitions/GraphicalDefinition.h"
#include "../../Model/ModelInfo.h"
#include <map>
#include <vector>
namespace Oyster
{

View File

@ -159,10 +159,9 @@ namespace Oyster
void Resources::Clean()
{
Resources::ModelData.~Buffer();
Resources::VPData.~Buffer();
for(int i = 0; i < obj.CBuffers.Vertex.size(); ++i)
{
//SAFE_RELEASE(obj.CBuffers.Vertex[i]);
obj.CBuffers.Vertex[i]->~Buffer();
}
for(int i = 0; i < obj.CBuffers.Pixel.size(); ++i)
{

View File

@ -1,7 +1,31 @@
#ifndef DEFINES
#define DEFINES
struct PointLight
{
float3 Pos;
float Radius;
float4 PosRadius;
float4 ColorBright;
};
float3 Color;
struct DiffSpec
{
float3 Diffuse;
float3 Specular;
};
cbuffer PointLights : register(b0)
{
PointLight pl;
}
cbuffer LightConstants : register(b1)
{
float4x4 InvProj;
int2 Pixels;
}
Texture2D DiffuseGlow : register(t0);
Texture2D NormalSpec : register(t1);
Texture2D DepthTexture : register(t2);
#endif

View File

@ -0,0 +1,23 @@
#include "Defines.hlsli"
DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
{
DiffSpec output;
float4 normalSpec = NormalSpec[texCoord];
float3 lightVec = pl.PosRadius.xyz - pos.xyz;
float d = length(lightVec);
lightVec = lightVec/d;
float diffFactor = max(dot(lightVec, normalSpec.xyz), 0.0f);
float3 v = reflect(-lightVec, normalSpec.xyz);
float specFactor = pow(max(dot(v,normalize(-pos)), 0.0f),normalSpec.w);
//Check att later
float att = (max(d-pl.PosRadius.w,0)/pow(pl.PosRadius.w,2));
//fix Ilum calcs instead of PhongBlinn
output.Diffuse = pl.ColorBright.w * att * diffFactor * pl.ColorBright.xyz;
output.Specular = pl.ColorBright.w * att * specFactor * pl.ColorBright.xyz;
if(diffFactor == 0)
output.Specular * 0;
return output;
}

View File

@ -1,11 +1,16 @@
#include "Defines.hlsli"
#include "LightCalc.hlsli"
#include "PosManipulation.hlsli"
//todo
//LightCulling
//Calc Diff + Spec
//Calc Ambience
//Write Glow
[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
float3 ViewPos = ToVpos(DTid.xy);
//DiffSpec LightCalc(pl, float3 pos)
}

View File

@ -0,0 +1,21 @@
#include "Defines.hlsli"
//assumes ProperfloatTexCoords
float3 ToVpos(float2 texCoord)
{
//Get proper UV
float2 UV = float2(texCoord) / float2(Pixels);
float4 ViewPos;
// Get the depth value for this pixel
ViewPos.z= DepthTexture[texCoord].x;
//Get X/w
ViewPos.x = UV.x * 2 - 1;
//Get Y/w
ViewPos.y = 1 - 2 * UV.y;
ViewPos.w = 1;
//Un project
ViewPos = mul(ViewPos, InvProj);
return ViewPos.xyz / ViewPos.w;
}

View File

@ -93,6 +93,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
}
Oyster::Graphics::API::DeleteModel(m);
Oyster::Graphics::API::DeleteModel(m2);
Oyster::Graphics::API::Clean();
return (int) msg.wParam;
}
@ -194,6 +195,8 @@ HRESULT InitDirect3D()
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
Oyster::Graphics::API::SetProjection(P);
P.Invert();
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
V = Oyster::Math3D::InverseOrientationMatrix(V);
@ -212,10 +215,11 @@ HRESULT Update(float deltaTime)
HRESULT Render(float deltaTime)
{
Oyster::Graphics::API::NewFrame(V,P);
Oyster::Graphics::API::SetView(V);
Oyster::Graphics::API::NewFrame();
Oyster::Graphics::API::RenderScene(m,1);
Oyster::Graphics::API::RenderScene(m2,1);
Oyster::Graphics::API::RenderModel(*m);
Oyster::Graphics::API::RenderModel(*m2);
Oyster::Graphics::API::EndFrame();

View File

@ -69,7 +69,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
@ -77,7 +77,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
@ -93,7 +93,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>