There is a memory leak

This commit is contained in:
Dynamitos
2023-11-30 11:51:53 +01:00
parent d1475d506e
commit 1493627ceb
20 changed files with 91 additions and 102 deletions
+14 -1
View File
@@ -15,7 +15,7 @@
{
"name": "Release",
"generator": "Visual Studio 17 2022 Win64",
"configurationType": "RelWithDebInfo",
"configurationType": "Release",
"buildRoot": "C:/Users/Dynamitos/Seele/bin/",
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildCommandArgs": "",
@@ -23,6 +23,19 @@
"inheritEnvironments": [ "msvc_x64" ],
"intelliSenseMode": "windows-msvc-x64",
"installRoot": "C:/Program Files/Seele"
},
{
"name": "RelWithDebInfo",
"generator": "Visual Studio 17 2022 Win64",
"configurationType": "RelWithDebInfo",
"buildRoot": "C:/Users/Dynamitos/Seele/bin/",
"installRoot": "C:/Program Files/Seele",
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64" ],
"intelliSenseMode": "windows-msvc-x64",
"variables": []
}
]
}
+1
View File
@@ -19,6 +19,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
{
MaterialParameter materialParams = params.getMaterialParameter();
LightingParameter lightingParams = params.getLightingParameter();
let brdf = pMaterial.prepare(materialParams);
float3 result = float3(0, 0, 0);
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
+8 -7
View File
@@ -2,7 +2,7 @@ import Common;
interface IBRDF
{
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor);
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor);
};
struct BlinnPhong : IBRDF
@@ -23,13 +23,14 @@ struct BlinnPhong : IBRDF
sheen = 1;
}
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
{
float nDotL = saturate(dot(normal, lightDir_TS));
float3 h = normalize(lightDir_TS + viewDir_TS);
float nDotH = saturate(dot(normal, h));
float3 normal_WS = mul(tbn, normal);
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
float3 h = lightDir_WS + viewDir_WS;
float specular = dot(normal_WS, h);
return baseColor;
return lightDir_WS * 2 + float3(1, 1, 1);//baseColor * (diffuse + specular) * lightColor;
}
};
@@ -48,7 +49,7 @@ struct DisneyBRDF : IBRDF
float clearCoat = 0;
float clearCoatGloss = 1;
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
{
return baseColor;
}
+4 -6
View File
@@ -14,8 +14,7 @@ struct DirectionalLight : ILightEnv
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
{
float3 lightDir_TS = mul(params.tbn, normalize(direction.xyz));
return brdf.evaluate(params.viewDir_TS, -lightDir_TS, color.xyz);
return brdf.evaluate(params.tbn, params.viewDir_WS, -normalize(direction.xyz), color.xyz);
}
};
@@ -26,11 +25,10 @@ struct PointLight : ILightEnv
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
{
float3 position_TS = mul(params.tbn, position_WS.xyz);
float3 lightDir_TS = position_TS - params.position_TS;
float d = length(lightDir_TS);
float3 lightDir_WS = position_WS.xyz - params.position_WS;
float d = length(lightDir_WS);
float illuminance = max(1 - d / colorRange.w, 0);
return illuminance * brdf.evaluate(params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
return brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
}
bool insidePlane(Plane plane)
+10 -17
View File
@@ -2,7 +2,6 @@ import Common;
struct MaterialParameter
{
float3 position_TS;
float3 position_WS;
float2 texCoords;
float3 vertexColor;
@@ -11,18 +10,16 @@ struct MaterialParameter
// data used by light environment
struct LightingParameter
{
// world to tangent space
float3x3 tbn;
float3 position_TS;
float3 viewDir_TS;
float3 position_WS;
float3 viewDir_WS;
};
// data passed to fragment shader
struct FragmentParameter
{
float4 position_CS : SV_Position;
float3 position_TS : POSITION0;
float3 viewDir_TS : POSITION1;
float3 viewDir_WS : POSITION1;
float3 normal_WS : NORMAL0;
float3 tangent_WS : TANGENT0;
float3 biTangent_WS : TANGENT1;
@@ -32,7 +29,6 @@ struct FragmentParameter
MaterialParameter getMaterialParameter()
{
MaterialParameter result;
result.position_TS = position_TS;
result.position_WS = position_WS;
result.texCoords = texCoords;
result.vertexColor = vertexColor;
@@ -41,9 +37,9 @@ struct FragmentParameter
LightingParameter getLightingParameter()
{
LightingParameter result;
result.tbn = transpose(float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS)));
result.position_TS = position_TS;
result.viewDir_TS = viewDir_TS;
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
result.position_WS = position_WS;
result.viewDir_WS = viewDir_WS;
return result;
}
};
@@ -63,14 +59,11 @@ struct VertexAttributes
float4 worldPos = mul(transformMatrix, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
float3 tangent_WS = mul(transformMatrix, float4(normalize(tangent_MS), 0)).xyz;
float3 biTangent_WS = mul(transformMatrix, float4(normalize(biTangent_MS), 0)).xyz;
float3 normal_WS = mul(transformMatrix, float4(normalize(normal_MS), 0)).xyz;
// Transforms from world space into tangent space
float3x3 tbn = transpose(float3x3(tangent_WS, biTangent_WS, normal_WS));
float3 tangent_WS = mul(float3x3(transformMatrix), normalize(tangent_MS));
float3 biTangent_WS = mul(float3x3(transformMatrix), normalize(biTangent_MS));
float3 normal_WS = mul(float3x3(transformMatrix), normalize(normal_MS));
FragmentParameter result;
result.position_TS = mul(tbn, worldPos.xyz);
result.viewDir_TS = mul(tbn, pViewParams.cameraPos_WS.xyz - worldPos.xyz);
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
result.normal_WS = normal_WS;
result.tangent_WS = tangent_WS;
result.biTangent_WS = biTangent_WS;
+1 -1
View File
@@ -109,7 +109,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
{
}
std::string outMatFilename = matCode["name"].get<std::string>().append(".asset");
std::string outMatFilename = matCode["name"].get<std::string>().append(".json");
std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename);
outMatFile << std::setw(4) << matCode;
outMatFile.flush();
+4 -4
View File
@@ -217,14 +217,14 @@ int main()
WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280;
mainWindowInfo.height = 720;
mainWindowInfo.width = 1920;
mainWindowInfo.height = 1080;
mainWindowInfo.numSamples = 1;
mainWindowInfo.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB;
auto window = windowManager->addWindow(graphics, mainWindowInfo);
ViewportCreateInfo sceneViewInfo;
sceneViewInfo.dimensions.size.x = 1280;
sceneViewInfo.dimensions.size.y = 720;
sceneViewInfo.dimensions.size.x = 1920;
sceneViewInfo.dimensions.size.y = 1080;
sceneViewInfo.dimensions.offset.x = 0;
sceneViewInfo.dimensions.offset.y = 0;
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
+1 -1
View File
@@ -7,7 +7,7 @@ CameraActor::CameraActor(PScene scene)
: Actor(scene)
{
attachComponent<Component::Camera>();
accessComponent<Component::Transform>().setRelativeLocation(Vector(10, 5, 14));
accessComponent<Component::Transform>().setPosition(Vector(10, 5, 14));
}
CameraActor::~CameraActor()
+11 -14
View File
@@ -11,8 +11,8 @@ Camera::Camera()
: viewMatrix(Matrix4())
, bNeedsViewBuild(false)
{
yaw = 0;
pitch = 0.2;
yaw = 3.1415f/2;
pitch = 0;
}
Camera::~Camera()
@@ -21,40 +21,37 @@ Camera::~Camera()
void Camera::mouseMove(float deltaYaw, float deltaPitch)
{
yaw -= deltaYaw / 500.f;
yaw += deltaYaw / 500.f;
pitch += deltaPitch / 500.f;
//std::cout << "Yaw: " << yaw << " Pitch: " << pitch << std::endl;
Vector cameraDirection = glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
Vector xyz = glm::cross(cameraDirection, Vector(0, 0, 1));
Quaternion result = Quaternion(glm::dot(cameraDirection, Vector(0, 0, 1)) + 1, xyz.x, xyz.y, xyz.z);
//std::cout << "Result " << Vector(0, 0, 1) * glm::normalize(result) << " cameraDirection: " << cameraDirection << std::endl;
getTransform().setRelativeRotation(result);
Matrix4 viewMat = glm::lookAt(getTransform().getPosition(), getTransform().getPosition() + cameraDirection, Vector(0, 1, 0));
getTransform().setRotation(viewMat); // quaternion from matrix, janky but im bad at math
bNeedsViewBuild = true;
}
void Camera::mouseScroll(float x)
{
getTransform().addRelativeLocation(getTransform().getForward()*x);
getTransform().translate(getTransform().getForward()*x);
bNeedsViewBuild = true;
}
void Camera::moveX(float amount)
{
getTransform().addRelativeLocation(getTransform().getForward()*amount);
getTransform().translate(getTransform().getForward()*amount);
bNeedsViewBuild = true;
}
void Camera::moveY(float amount)
{
getTransform().addRelativeLocation(getTransform().getRight()*amount);
getTransform().translate(getTransform().getRight()*amount);
bNeedsViewBuild = true;
}
void Camera::buildViewMatrix()
{
Vector eyePos = getTransform().getPosition();//getAbsoluteTransform().getPosition();
Vector lookAt = eyePos + glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
Vector eyePos = getTransform().getPosition();
Vector lookAt = eyePos + getTransform().getForward();
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
cameraPos = eyePos;
bNeedsViewBuild = false;
}
+3 -1
View File
@@ -21,7 +21,7 @@ struct Camera
}
Vector getCameraPosition() const
{
return Vector(viewMatrix[3]);
return cameraPos;
}
void mouseMove(float deltaX, float deltaY);
void mouseScroll(float x);
@@ -29,6 +29,8 @@ struct Camera
void moveY(float amount);
void buildViewMatrix();
Matrix4 viewMatrix;
Vector cameraPos;
Vector cameraDirection;
//Transforms relative to actor
float yaw;
float pitch;
+6 -24
View File
@@ -4,7 +4,6 @@ using namespace Seele::Component;
DEFINE_COMPONENT(Transform)
void Transform::setPosition(Vector pos)
{
transform.setPosition(pos);
@@ -19,32 +18,15 @@ void Transform::setScale(Vector scale)
{
transform.setScale(scale);
}
void Transform::setRelativeLocation(Vector location)
void Transform::translate(Vector direction)
{
transform = Math::Transform(location, transform.getRotation(), transform.getScale());
transform.setPosition(transform.getPosition() + direction);
}
void Transform::setRelativeRotation(Vector rotation)
void Transform::rotate(Quaternion quat)
{
transform = Math::Transform(transform.getPosition(), Quaternion(rotation), transform.getScale());
transform.setRotation(transform.getRotation() * quat);
}
void Transform::setRelativeRotation(Quaternion rotation)
void Transform::scale(Vector scale)
{
transform = Math::Transform(transform.getPosition(), rotation, transform.getScale());
}
void Transform::setRelativeScale(Vector scale)
{
transform = Math::Transform(transform.getPosition(), transform.getRotation(), scale);
}
void Transform::addRelativeLocation(Vector translation)
{
transform = Math::Transform(transform.getPosition() + translation, transform.getRotation(), transform.getScale());
}
void Transform::addRelativeRotation(Vector rotation)
{
transform = Math::Transform(transform.getPosition(), transform.getRotation() * Quaternion(rotation), transform.getScale());
}
void Transform::addRelativeRotation(Quaternion rotation)
{
transform = Math::Transform(transform.getPosition(), transform.getRotation() * rotation, transform.getScale());
transform.setScale(transform.getScale() + scale);
}
+3 -9
View File
@@ -21,15 +21,9 @@ struct Transform
void setPosition(Vector pos);
void setRotation(Quaternion quat);
void setScale(Vector scale);
void setRelativeLocation(Vector location);
void setRelativeRotation(Quaternion rotation);
void setRelativeRotation(Vector rotation);
void setRelativeScale(Vector scale);
void addRelativeLocation(Vector translation);
void addRelativeRotation(Quaternion rotation);
void addRelativeRotation(Vector rotation);
void translate(Vector direction);
void rotate(Quaternion quat);
void scale(Vector scale);
private:
Math::Transform transform;
};
+2 -1
View File
@@ -165,8 +165,9 @@ void BasePass::render()
{
if (meshData.numIndices > 0)
{
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset++);
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset);
}
instanceOffset++;
}
}
}
+2 -2
View File
@@ -10,7 +10,7 @@
using namespace Seele;
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 16 * 1024;
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024;
void VertexData::resetMeshData()
{
@@ -166,7 +166,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices)
head += numVertices;
if (head > verticesAllocated)
{
verticesAllocated = head;
verticesAllocated = std::max(head, verticesAllocated + NUM_DEFAULT_ELEMENTS);
resizeBuffers();
}
return res;
+9 -5
View File
@@ -62,12 +62,10 @@ void DescriptorLayout::create()
PipelineLayout::~PipelineLayout()
{
if (layoutHandle != VK_NULL_HANDLE)
{
vkDestroyPipelineLayout(graphics->getDevice(), layoutHandle, nullptr);
}
}
Map<uint32, VkPipelineLayout> cachedLayouts;
void PipelineLayout::create()
{
vulkanDescriptorLayouts.resize(descriptorSetLayouts.size());
@@ -105,7 +103,14 @@ void PipelineLayout::create()
layoutHash = CRC::Calculate(createInfo.pPushConstantRanges, sizeof(VkPushConstantRange) * createInfo.pushConstantRangeCount, CRC::CRC_32());
layoutHash = CRC::Calculate(createInfo.pSetLayouts, sizeof(VkDescriptorSetLayout) * createInfo.setLayoutCount, CRC::CRC_32(), layoutHash);
if (cachedLayouts.contains(layoutHash))
{
layoutHandle = cachedLayouts[layoutHash];
return;
}
VK_CHECK(vkCreatePipelineLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
cachedLayouts[layoutHash] = layoutHandle;
}
void PipelineLayout::reset()
@@ -391,7 +396,6 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet()
{
//If it hasnt been initialized, allocate it
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
std::cout << "New descriptor " << cachedHandles[setIndex]->setHandle << std::endl;
}
cachedHandles[setIndex]->allocate();
+1
View File
@@ -1,5 +1,6 @@
#include "Transform.h"
#include <glm/gtx/quaternion.hpp>
#include "Transform.h"
using namespace Seele;
using namespace Seele::Math;
-4
View File
@@ -60,10 +60,6 @@ void LightEnvironment::addPointLight(Component::PointLight pointLight)
void LightEnvironment::commit()
{
dirs.add(Component::DirectionalLight{
.color = Vector4(1, 1, 1, 1),
.direction = Vector4(1, 0, 1, 0),
});
lightEnv.numDirectionalLights = dirs.size();
lightEnv.numPointLights = points.size();
lightEnvBuffer->updateContents(DataSource{
-1
View File
@@ -25,7 +25,6 @@ Scene::~Scene()
void Scene::update(float deltaTime)
{
lightEnv->reset();
physics.update(deltaTime);
}
+4 -4
View File
@@ -22,6 +22,10 @@ void KeyboardInput::update(Component::KeyboardInput& input)
input.mouseY = mouseY;
input.mouse1 = mouse1;
input.mouse2 = mouse2;
deltaX = mouseX - lastMouseX;
deltaY = mouseY - lastMouseY;
lastMouseX = mouseX;
lastMouseY = mouseY;
}
void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
@@ -33,10 +37,6 @@ void KeyboardInput::mouseCallback(double x, double y)
{
mouseX = x;
mouseY = y;
deltaX = x - lastMouseX;
deltaY = y - lastMouseY;
lastMouseX = x;
lastMouseY = y;
}
void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
+7
View File
@@ -15,4 +15,11 @@ LightGather::~LightGather()
void LightGather::update()
{
lightEnv->reset();
scene->view<Component::PointLight>([this](Component::PointLight& pointLight) {
lightEnv->addPointLight(pointLight);
});
scene->view<Component::DirectionalLight>([this](Component::DirectionalLight& dirLight) {
lightEnv->addDirectionalLight(dirLight);
});
}