mirror of
https://github.com/antopilo/Nuake.git
synced 2025-12-30 21:49:06 +03:00
Compare commits
2 Commits
2a9b4de5eb
...
f88c76445f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f88c76445f | ||
|
|
fe89b84222 |
@@ -7,6 +7,7 @@
|
||||
#include "VulkanInit.h"
|
||||
#include "DescriptorLayoutBuilder.h"
|
||||
|
||||
#include "GPUData/GPUData.h"
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -150,11 +151,11 @@ void BindlessDescriptor::Swap(int32_t frameIndex)
|
||||
|
||||
ResourceDescriptors::ResourceDescriptors(const ResourceDescriptorsLimits& limits)
|
||||
{
|
||||
AddResourceDescriptors<ResourceType::View, View>(limits.MaxView);
|
||||
//AddResourceDescriptors<ResourceType::Material>(limits.MaxMaterial);
|
||||
//AddResourceDescriptors<ResourceType::Texture>(limits.MaxTexture);
|
||||
//AddResourceDescriptors<ResourceType::Light>(limits.MaxLight);
|
||||
//AddResourceDescriptors<ResourceType::Sampler>(limits.MaxSampler);
|
||||
AddResourceDescriptors<ResourceType::View, CameraView>(limits.MaxView);
|
||||
AddResourceDescriptors<ResourceType::Material, MaterialBufferStruct>(limits.MaxMaterial);
|
||||
AddResourceDescriptors<ResourceType::Texture, VkDescriptorImageInfo>(limits.MaxTexture);
|
||||
AddResourceDescriptors<ResourceType::Light, LightData>(limits.MaxLight);
|
||||
AddResourceDescriptors<ResourceType::Sampler, VkDescriptorImageInfo>(limits.MaxSampler);
|
||||
}
|
||||
|
||||
void ResourceDescriptors::Swap(int32_t frameIndex)
|
||||
@@ -162,6 +163,5 @@ void ResourceDescriptors::Swap(int32_t frameIndex)
|
||||
for (auto& [type, desc] : Descriptors)
|
||||
{
|
||||
desc.Swap(frameIndex);
|
||||
Logger::Log("Swapped: " + GetResourceTypeName(type));
|
||||
}
|
||||
}
|
||||
66
Nuake/Source/Nuake/Rendering/Vulkan/GPUData/GPUData.h
Normal file
66
Nuake/Source/Nuake/Rendering/Vulkan/GPUData/GPUData.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
#include "Nuake/Core/Maths.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
struct TransformData
|
||||
{
|
||||
std::array<Matrix4, 3000> Data;
|
||||
};
|
||||
|
||||
struct MaterialBufferStruct
|
||||
{
|
||||
int HasAlbedo;
|
||||
Vector3 AlbedoColor;
|
||||
int HasNormal;
|
||||
int HasMetalness;
|
||||
int HasRoughness;
|
||||
int HasAO;
|
||||
float MetalnessValue;
|
||||
float RoughnessValue;
|
||||
float AoValue;
|
||||
uint32_t AlbedoTextureId;
|
||||
uint32_t NormalTextureId;
|
||||
uint32_t MetalnessTextureId;
|
||||
uint32_t RoughnessTextureId;
|
||||
uint32_t AoTextureId;
|
||||
int SamplerType;
|
||||
int ReceiveShadow;
|
||||
int CastShadow;
|
||||
int Unlit;
|
||||
int AlphaScissor;
|
||||
int pad[3];
|
||||
};
|
||||
|
||||
struct LightData
|
||||
{
|
||||
Vector3 Position;
|
||||
int Type;
|
||||
Vector4 Color;
|
||||
Vector3 Direction;
|
||||
float OuterConeAngle;
|
||||
float InnerConeAngle;
|
||||
int CastShadow;
|
||||
int ShadowMapTextureId[4];
|
||||
int TransformId[4];
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
struct CameraView
|
||||
{
|
||||
Matrix4 View;
|
||||
Matrix4 Projection;
|
||||
Matrix4 ViewProjection;
|
||||
Matrix4 InverseView;
|
||||
Matrix4 InverseProjection;
|
||||
Vector3 Position;
|
||||
float Near;
|
||||
float Far;
|
||||
float pad;
|
||||
float pad2;
|
||||
float pad3;
|
||||
//char padding[64]; // 124 bytes to reach 128 bytes
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "Nuake/Rendering/Vulkan/VulkanRenderer.h"
|
||||
|
||||
#include "Nuake/Rendering/Vulkan/BindlessDescriptor.h"
|
||||
#include "Nuake/Rendering/Vulkan/GPUData/GPUData.h"
|
||||
|
||||
#include <volk/volk.h>
|
||||
|
||||
@@ -22,77 +23,17 @@
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
struct ModelData
|
||||
{
|
||||
std::array<Matrix4, 3000> Data;
|
||||
};
|
||||
|
||||
// This is what is present on the shader as a structured buffer
|
||||
struct MaterialBufferStruct
|
||||
{
|
||||
int HasAlbedo;
|
||||
Vector3 AlbedoColor;
|
||||
int HasNormal;
|
||||
int HasMetalness;
|
||||
int HasRoughness;
|
||||
int HasAO;
|
||||
float MetalnessValue;
|
||||
float RoughnessValue;
|
||||
float AoValue;
|
||||
uint32_t AlbedoTextureId;
|
||||
uint32_t NormalTextureId;
|
||||
uint32_t MetalnessTextureId;
|
||||
uint32_t RoughnessTextureId;
|
||||
uint32_t AoTextureId;
|
||||
int SamplerType;
|
||||
int ReceiveShadow;
|
||||
int CastShadow;
|
||||
int Unlit;
|
||||
int AlphaScissor;
|
||||
int pad[3];
|
||||
};
|
||||
|
||||
// This is the *whole* buffer
|
||||
struct MaterialData
|
||||
{
|
||||
std::array<MaterialBufferStruct, 2000> Data;
|
||||
};
|
||||
|
||||
struct LightData
|
||||
{
|
||||
Vector3 Position;
|
||||
int Type;
|
||||
Vector4 Color;
|
||||
Vector3 Direction;
|
||||
float OuterConeAngle;
|
||||
float InnerConeAngle;
|
||||
int CastShadow;
|
||||
int ShadowMapTextureId[4];
|
||||
int TransformId[4];
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
struct LightDataContainer
|
||||
{
|
||||
std::array<LightData, 100> Data;
|
||||
};
|
||||
|
||||
struct CameraView
|
||||
{
|
||||
Matrix4 View;
|
||||
Matrix4 Projection;
|
||||
Matrix4 ViewProjection;
|
||||
Matrix4 InverseView;
|
||||
Matrix4 InverseProjection;
|
||||
Vector3 Position;
|
||||
float Near;
|
||||
float Far;
|
||||
float pad;
|
||||
float pad2;
|
||||
float pad3;
|
||||
//char padding[64]; // 124 bytes to reach 128 bytes
|
||||
};
|
||||
|
||||
constexpr uint32_t MAX_MODEL_MATRIX = 3000;
|
||||
constexpr uint32_t MAX_MATERIAL = 2000;
|
||||
constexpr uint32_t MAX_TEXTURES = 3000;
|
||||
@@ -147,7 +88,7 @@ namespace Nuake
|
||||
std::vector<CleanUpStack> DeletionQueue;
|
||||
|
||||
public:
|
||||
ModelData ModelTransforms;
|
||||
TransformData ModelTransforms;
|
||||
MaterialData MaterialDataContainer;
|
||||
|
||||
LightDataContainer LightDataContainerArray;
|
||||
|
||||
@@ -54,28 +54,17 @@ void GPUResources::Init()
|
||||
};
|
||||
resourceDescriptors = CreateScope<ResourceDescriptors>(limits);
|
||||
|
||||
View testData
|
||||
{
|
||||
.myView = 1,
|
||||
.dat2 = 2
|
||||
};
|
||||
|
||||
|
||||
std::vector<View> testDataVector;
|
||||
testDataVector.reserve(limits.MaxView);
|
||||
for (int i = 0; i < limits.MaxView; i++)
|
||||
{
|
||||
testDataVector.push_back(testData);
|
||||
}
|
||||
|
||||
resourceDescriptors->UpdateBuffer<ResourceType::View>(0, testDataVector.data(), testDataVector.size());
|
||||
|
||||
testDataVector[0].myView = 1337;
|
||||
resourceDescriptors->UpdateBuffer<ResourceType::View>(1, testDataVector.data(), testDataVector.size());
|
||||
|
||||
resourceDescriptors->Swap(1);
|
||||
resourceDescriptors->Swap(0);
|
||||
resourceDescriptors->UpdateBuffer<ResourceType::View>(1, testDataVector.data(), testDataVector.size());
|
||||
resourceDescriptors->Swap(0);
|
||||
//resourceDescriptors->UpdateBuffer<ResourceType::View>(0, testDataVector.data(), testDataVector.size());
|
||||
//
|
||||
//testDataVector[0].myView = 1337;
|
||||
//resourceDescriptors->UpdateBuffer<ResourceType::View>(1, testDataVector.data(), testDataVector.size());
|
||||
//
|
||||
//resourceDescriptors->Swap(1);
|
||||
//resourceDescriptors->Swap(0);
|
||||
//resourceDescriptors->UpdateBuffer<ResourceType::View>(1, testDataVector.data(), testDataVector.size());
|
||||
//resourceDescriptors->Swap(0);
|
||||
}
|
||||
|
||||
Ref<AllocatedBuffer> GPUResources::CreateBuffer(size_t size, BufferUsage flags, MemoryUsage usage, const std::string& name)
|
||||
|
||||
@@ -90,9 +90,95 @@ namespace Nuake
|
||||
std::string value = fieldVal.cast<std::string>();
|
||||
cursor[displayName] = value;
|
||||
}
|
||||
else if (auto prop = dataType.prop(HashedFieldPropName::IsEnum); prop)
|
||||
{
|
||||
auto enumMeta = dataType.type();
|
||||
// Fallback to integer value if name not available
|
||||
cursor[displayName] = static_cast<int>(fieldVal.cast<int>());
|
||||
}
|
||||
}
|
||||
|
||||
return jsonSnippet;
|
||||
}
|
||||
|
||||
template<IsComponentT T>
|
||||
void Deserialize(const json& jsonSnippet, T& component)
|
||||
{
|
||||
const entt::meta_type meta = entt::resolve<T>();
|
||||
if (!meta) return;
|
||||
|
||||
entt::meta_any metaAny = meta.from_void(static_cast<void*>(&component));
|
||||
if (!metaAny) return;
|
||||
|
||||
const std::string componentName = Component::GetName(meta);
|
||||
if (!jsonSnippet.contains(componentName)) return;
|
||||
|
||||
const json& cursor = jsonSnippet.at(componentName);
|
||||
|
||||
for (auto [fst, dataMember] : meta.data())
|
||||
{
|
||||
auto propName = dataMember.prop(HashedName::DisplayName);
|
||||
if (!propName) continue;
|
||||
|
||||
const char* displayNameC = *propName.value().try_cast<const char*>();
|
||||
std::string displayName = displayNameC;
|
||||
|
||||
if (!cursor.contains(displayName)) continue;
|
||||
|
||||
const entt::meta_type fieldType = dataMember.type();
|
||||
|
||||
if (fieldType == entt::resolve<float>())
|
||||
{
|
||||
dataMember.set(metaAny, cursor.at(displayName).get<float>());
|
||||
}
|
||||
else if (fieldType == entt::resolve<int32_t>())
|
||||
{
|
||||
dataMember.set(metaAny, cursor.at(displayName).get<int32_t>());
|
||||
}
|
||||
else if (fieldType == entt::resolve<bool>())
|
||||
{
|
||||
dataMember.set(metaAny, cursor.at(displayName).get<bool>());
|
||||
}
|
||||
else if (fieldType == entt::resolve<Vector2>())
|
||||
{
|
||||
Vector2 vec;
|
||||
vec.x = cursor.at(displayName).at("x").get<float>();
|
||||
vec.y = cursor.at(displayName).at("y").get<float>();
|
||||
dataMember.set(metaAny, vec);
|
||||
}
|
||||
else if (fieldType == entt::resolve<Vector3>())
|
||||
{
|
||||
Vector3 vec;
|
||||
vec.x = cursor.at(displayName).at("x").get<float>();
|
||||
vec.y = cursor.at(displayName).at("y").get<float>();
|
||||
vec.z = cursor.at(displayName).at("z").get<float>();
|
||||
dataMember.set(metaAny, vec);
|
||||
}
|
||||
else if (fieldType == entt::resolve<Vector4>())
|
||||
{
|
||||
Vector4 vec;
|
||||
vec.x = cursor.at(displayName).at("x").get<float>();
|
||||
vec.y = cursor.at(displayName).at("y").get<float>();
|
||||
vec.z = cursor.at(displayName).at("z").get<float>();
|
||||
vec.w = cursor.at(displayName).at("w").get<float>();
|
||||
dataMember.set(metaAny, vec);
|
||||
}
|
||||
else if (fieldType == entt::resolve<ResourceFile>())
|
||||
{
|
||||
std::string fileKey = "file" + displayName;
|
||||
if (cursor.contains(fileKey))
|
||||
{
|
||||
//std::string relativePath = cursor.at(fileKey).get<std::string>();
|
||||
//ResourceFile resource;
|
||||
//resource.file = std::make_shared<File>(relativePath);
|
||||
//dataMember.set(metaAny, resource);
|
||||
}
|
||||
}
|
||||
else if (fieldType == entt::resolve<std::string>())
|
||||
{
|
||||
dataMember.set(metaAny, cursor.at(displayName).get<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,14 @@ namespace Serialization
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
enum class TestEnum : int32_t
|
||||
{
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
Four
|
||||
};
|
||||
|
||||
class TestData : public Component
|
||||
{
|
||||
NUAKECOMPONENT(TestData, "TestData");
|
||||
@@ -19,6 +27,7 @@ namespace Serialization
|
||||
Vector2 myVec2;
|
||||
Vector3 myVec3;
|
||||
Vector4 myVec4;
|
||||
TestEnum myEnum;
|
||||
|
||||
static void InitializeComponentClass()
|
||||
{
|
||||
@@ -28,6 +37,7 @@ namespace Serialization
|
||||
BindComponentField<&TestData::myVec2>("myVec2", "myVec2");
|
||||
BindComponentField<&TestData::myVec3>("myVec3", "myVec3");
|
||||
BindComponentField<&TestData::myVec4>("myVec4", "myVec4");
|
||||
BindComponentField<&TestData::myEnum>("myEnum", "myEnum");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,7 +52,8 @@ namespace Serialization
|
||||
.myString = "Hello World",
|
||||
.myVec2 = Vector2(1, 2),
|
||||
.myVec3 = Vector3(3, 4, 5),
|
||||
.myVec4 = Vector4(6, 7, 8, 9)
|
||||
.myVec4 = Vector4(6, 7, 8, 9),
|
||||
.myEnum = TestEnum::Two
|
||||
};
|
||||
|
||||
// Serialize into json
|
||||
@@ -76,4 +87,35 @@ namespace Serialization
|
||||
REQUIRE(result["TestData"]["myVec4"]["z"] == testData.myVec4.z);
|
||||
REQUIRE(result["TestData"]["myVec4"]["w"] == testData.myVec4.w);
|
||||
}
|
||||
|
||||
TEST_CASE("Deserialize Struct", "[Serialization]")
|
||||
{
|
||||
// Initialize component
|
||||
TestData::InternalInitializeClass();
|
||||
TestData testData =
|
||||
{
|
||||
.myInt = 1337,
|
||||
.myBool = true,
|
||||
.myString = "Hello World",
|
||||
.myVec2 = Vector2(1, 2),
|
||||
.myVec3 = Vector3(3, 4, 5),
|
||||
.myVec4 = Vector4(6, 7, 8, 9)
|
||||
};
|
||||
|
||||
// Serialize into json
|
||||
ComponentSerializer serializer;
|
||||
json result = serializer.Serialize(testData);
|
||||
|
||||
// Deserialize
|
||||
TestData inTestData = TestData{ };
|
||||
serializer.Deserialize(result, inTestData);
|
||||
|
||||
// Test JSON result
|
||||
REQUIRE(inTestData.myInt == testData.myInt);
|
||||
REQUIRE(inTestData.myBool == testData.myBool);
|
||||
REQUIRE(inTestData.myString == testData.myString);
|
||||
REQUIRE(inTestData.myVec2 == testData.myVec2);
|
||||
REQUIRE(inTestData.myVec3 == testData.myVec3);
|
||||
REQUIRE(inTestData.myVec4 == testData.myVec4);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user