Forgetting to delete leads to memoryleaks
This commit is contained in:
+8
-4
@@ -130,16 +130,20 @@ endif()
|
|||||||
|
|
||||||
add_subdirectory(src/)
|
add_subdirectory(src/)
|
||||||
|
|
||||||
set(COPY_DLL_COMMAND "true")
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(COPY_DLL_COMMAND "copy $<TARGET_RUNTIME_DLLS:Editor> $<TARGET_FILE_DIR:Engine>")
|
add_custom_target(dll_copy ALL
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
|
||||||
|
COMMAND_EXPAND_LISTS
|
||||||
|
DEPENDS Editor slang-build)
|
||||||
|
else()
|
||||||
|
add_custom_target(dll_copy ALL
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E true)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_target(SeeleEngine ALL
|
add_custom_target(SeeleEngine ALL
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>
|
||||||
COMMAND ${CMAKE_COMMAND} -E ${COPY_DLL_COMMAND}
|
|
||||||
COMMAND_EXPAND_LISTS
|
COMMAND_EXPAND_LISTS
|
||||||
DEPENDS Editor slang-build)
|
DEPENDS Editor slang-build dll_copy)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
TARGETS
|
TARGETS
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "Asset/FontAsset.h"
|
#include "Asset/FontAsset.h"
|
||||||
#include "Asset/AssetRegistry.h"
|
#include "Asset/AssetRegistry.h"
|
||||||
#include "Graphics/Resources.h"
|
#include "Graphics/Resources.h"
|
||||||
|
#include "Graphics/Texture.h"
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset)
|
|||||||
error = FT_New_Face(ft, args.filePath.string().c_str(), 0, &face);
|
error = FT_New_Face(ft, args.filePath.string().c_str(), 0, &face);
|
||||||
assert(!error);
|
assert(!error);
|
||||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||||
|
Array<Gfx::OTexture2D> usedTextures;
|
||||||
for(uint32 c = 0; c < 256; ++c)
|
for(uint32 c = 0; c < 256; ++c)
|
||||||
{
|
{
|
||||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER))
|
if(FT_Load_Char(face, c, FT_LOAD_RENDER))
|
||||||
@@ -70,10 +72,12 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset)
|
|||||||
imageData.sourceData.size = sizeof(uint8);
|
imageData.sourceData.size = sizeof(uint8);
|
||||||
imageData.sourceData.data = &transparentPixel;
|
imageData.sourceData.data = &transparentPixel;
|
||||||
}
|
}
|
||||||
glyph.texture = graphics->createTexture2D(imageData);
|
glyph.textureIndex = usedTextures.size();
|
||||||
|
usedTextures.add(graphics->createTexture2D(imageData));
|
||||||
}
|
}
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
FT_Done_FreeType(ft);
|
FT_Done_FreeType(ft);
|
||||||
|
asset->setUsedTextures(std::move(usedTextures));
|
||||||
|
|
||||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->getFolderPath()) / asset->getName()).replace_extension("asset").string(), std::ios::binary);
|
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->getFolderPath()) / asset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->data = std::stof(defaultValue.value().get<std::string>());
|
p->data = std::stof(defaultValue.value().get<std::string>());
|
||||||
}
|
}
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[p->key] = std::move(p);
|
expressions[param.key()] = std::move(p);
|
||||||
}
|
}
|
||||||
// TODO: ALIGNMENT RULES
|
// TODO: ALIGNMENT RULES
|
||||||
else if(type.compare("float3") == 0)
|
else if(type.compare("float3") == 0)
|
||||||
@@ -92,7 +92,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->data = parseVector(defaultValue.value().get<std::string>().c_str());
|
p->data = parseVector(defaultValue.value().get<std::string>().c_str());
|
||||||
}
|
}
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[p->key] = std::move(p);
|
expressions[param.key()] = std::move(p);
|
||||||
}
|
}
|
||||||
else if(type.compare("Texture2D") == 0)
|
else if(type.compare("Texture2D") == 0)
|
||||||
{
|
{
|
||||||
@@ -108,7 +108,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
p->data = AssetRegistry::findTexture(""); // this will return placeholder texture
|
p->data = AssetRegistry::findTexture(""); // this will return placeholder texture
|
||||||
}
|
}
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[p->key] = std::move(p);
|
expressions[param.key()] = std::move(p);
|
||||||
}
|
}
|
||||||
else if(type.compare("SamplerState") == 0)
|
else if(type.compare("SamplerState") == 0)
|
||||||
{
|
{
|
||||||
@@ -116,7 +116,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
||||||
p->data = graphics->createSamplerState({});
|
p->data = graphics->createSamplerState({});
|
||||||
parameters.add(p->key);
|
parameters.add(p->key);
|
||||||
expressions[p->key] = std::move(p);
|
expressions[param.key()] = std::move(p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -136,7 +136,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
OConstantExpression c = new ConstantExpression(str, ExpressionType::UNKNOWN);
|
OConstantExpression c = new ConstantExpression(str, ExpressionType::UNKNOWN);
|
||||||
std::string name = std::format("Const{0}", auxKey++);
|
std::string name = std::format("Const{0}", auxKey++);
|
||||||
c->key = name;
|
c->key = name;
|
||||||
expressions[c->key] = std::move(c);
|
expressions[name] = std::move(c);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ void MeshLoader::importAsset(MeshImportArgs args)
|
|||||||
import(args, ref);
|
import(args, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialAsset>& globalMaterials)
|
void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials)
|
||||||
{
|
{
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
for(uint32 i = 0; i < scene->mNumMaterials; ++i)
|
for(uint32 i = 0; i < scene->mNumMaterials; ++i)
|
||||||
@@ -118,7 +118,11 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
|
|||||||
.filePath = meshDirectory / outMatFilename,
|
.filePath = meshDirectory / outMatFilename,
|
||||||
.importPath = importPath,
|
.importPath = importPath,
|
||||||
});
|
});
|
||||||
globalMaterials[i] = AssetRegistry::findMaterial(matCode["name"].get<std::string>());
|
PMaterialAsset baseMat = AssetRegistry::findMaterial(matCode["name"].get<std::string>());
|
||||||
|
globalMaterials[i] = baseMat->instantiate(InstantiationParameter{
|
||||||
|
.name = std::format("{0}_Inst_0", baseMat->getName()),
|
||||||
|
.folderPath = baseMat->getFolderPath(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,11 +139,11 @@ void findMeshRoots(aiNode *node, List<aiNode *> &meshNodes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider)
|
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider)
|
||||||
{
|
{
|
||||||
for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
|
for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
|
||||||
{
|
{
|
||||||
aiMesh *mesh = scene->mMeshes[meshIndex];
|
aiMesh* mesh = scene->mMeshes[meshIndex];
|
||||||
collider.boundingbox.adjust(Vector(mesh->mAABB.mMin.x, mesh->mAABB.mMin.y, mesh->mAABB.mMin.z));
|
collider.boundingbox.adjust(Vector(mesh->mAABB.mMin.x, mesh->mAABB.mMin.y, mesh->mAABB.mMin.z));
|
||||||
collider.boundingbox.adjust(Vector(mesh->mAABB.mMax.x, mesh->mAABB.mMax.y, mesh->mAABB.mMax.z));
|
collider.boundingbox.adjust(Vector(mesh->mAABB.mMax.x, mesh->mAABB.mMax.y, mesh->mAABB.mMax.z));
|
||||||
|
|
||||||
@@ -152,7 +156,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialAss
|
|||||||
|
|
||||||
StaticMeshVertexData* vertexData = StaticMeshVertexData::getInstance();
|
StaticMeshVertexData* vertexData = StaticMeshVertexData::getInstance();
|
||||||
|
|
||||||
for(uint32 i = 0; i < mesh->mNumVertices; ++i)
|
for (uint32 i = 0; i < mesh->mNumVertices; ++i)
|
||||||
{
|
{
|
||||||
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
||||||
texCoords[i] = Vector2(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].x);
|
texCoords[i] = Vector2(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].x);
|
||||||
@@ -240,7 +244,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialAss
|
|||||||
|
|
||||||
IndexBufferCreateInfo idxInfo;
|
IndexBufferCreateInfo idxInfo;
|
||||||
idxInfo.indexType = Gfx::SE_INDEX_TYPE_UINT32;
|
idxInfo.indexType = Gfx::SE_INDEX_TYPE_UINT32;
|
||||||
idxInfo.sourceData.data = (uint8 *)indices.data();
|
idxInfo.sourceData.data = (uint8*)indices.data();
|
||||||
idxInfo.sourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
|
idxInfo.sourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
|
||||||
idxInfo.sourceData.size = sizeof(uint32) * indices.size();
|
idxInfo.sourceData.size = sizeof(uint32) * indices.size();
|
||||||
Gfx::OIndexBuffer indexBuffer = graphics->createIndexBuffer(idxInfo);
|
Gfx::OIndexBuffer indexBuffer = graphics->createIndexBuffer(idxInfo);
|
||||||
@@ -249,10 +253,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialAss
|
|||||||
globalMeshes[meshIndex] = new Mesh();
|
globalMeshes[meshIndex] = new Mesh();
|
||||||
globalMeshes[meshIndex]->vertexData = vertexData;
|
globalMeshes[meshIndex]->vertexData = vertexData;
|
||||||
globalMeshes[meshIndex]->id = id;
|
globalMeshes[meshIndex]->id = id;
|
||||||
globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex]->instantiate(InstantiationParameter{
|
globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex];
|
||||||
.name = std::format("{0}_Inst_0", materials[mesh->mMaterialIndex]->getName()),
|
|
||||||
.folderPath = materials[mesh->mMaterialIndex]->getFolderPath(),
|
|
||||||
});
|
|
||||||
globalMeshes[meshIndex]->meshlets = std::move(meshlets);
|
globalMeshes[meshIndex]->meshlets = std::move(meshlets);
|
||||||
globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices;
|
globalMeshes[meshIndex]->vertexCount = mesh->mNumVertices;
|
||||||
globalMeshes[meshIndex]->indexBuffer = std::move(indexBuffer);
|
globalMeshes[meshIndex]->indexBuffer = std::move(indexBuffer);
|
||||||
@@ -314,7 +315,7 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
|||||||
aiProcess_FindDegenerates));
|
aiProcess_FindDegenerates));
|
||||||
const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
|
const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
|
||||||
|
|
||||||
Array<PMaterialAsset> globalMaterials(scene->mNumMaterials);
|
Array<PMaterialInstanceAsset> globalMaterials(scene->mNumMaterials);
|
||||||
loadTextures(scene, args.filePath.parent_path(), args.importPath);
|
loadTextures(scene, args.filePath.parent_path(), args.importPath);
|
||||||
loadMaterials(scene, args.filePath.stem().string(), args.filePath.parent_path(), args.importPath, globalMaterials);
|
loadMaterials(scene, args.filePath.stem().string(), args.filePath.parent_path(), args.importPath, globalMaterials);
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Seele
|
|||||||
{
|
{
|
||||||
DECLARE_REF(Mesh)
|
DECLARE_REF(Mesh)
|
||||||
DECLARE_REF(MeshAsset)
|
DECLARE_REF(MeshAsset)
|
||||||
DECLARE_REF(MaterialAsset)
|
DECLARE_REF(MaterialInstanceAsset)
|
||||||
DECLARE_NAME_REF(Gfx, Graphics)
|
DECLARE_NAME_REF(Gfx, Graphics)
|
||||||
struct MeshImportArgs
|
struct MeshImportArgs
|
||||||
{
|
{
|
||||||
@@ -24,9 +24,9 @@ public:
|
|||||||
~MeshLoader();
|
~MeshLoader();
|
||||||
void importAsset(MeshImportArgs args);
|
void importAsset(MeshImportArgs args);
|
||||||
private:
|
private:
|
||||||
void loadMaterials(const aiScene* scene, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialAsset>& globalMaterials);
|
void loadMaterials(const aiScene* scene, const std::string& baseName, const std::filesystem::path& meshDirectory, const std::string& importPath, Array<PMaterialInstanceAsset>& globalMaterials);
|
||||||
void loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath);
|
void loadTextures(const aiScene* scene, const std::filesystem::path& meshDirectory, const std::string& importPath);
|
||||||
void loadGlobalMeshes(const aiScene* scene, const Array<PMaterialAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider);
|
void loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes, Component::Collider& collider);
|
||||||
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
|
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
|
||||||
|
|
||||||
void import(MeshImportArgs args, PMeshAsset meshAsset);
|
void import(MeshImportArgs args, PMeshAsset meshAsset);
|
||||||
|
|||||||
+1
-1
@@ -227,7 +227,7 @@ int main()
|
|||||||
sceneViewInfo.dimensions.size.y = 720;
|
sceneViewInfo.dimensions.size.y = 720;
|
||||||
sceneViewInfo.dimensions.offset.x = 0;
|
sceneViewInfo.dimensions.offset.x = 0;
|
||||||
sceneViewInfo.dimensions.offset.y = 0;
|
sceneViewInfo.dimensions.offset.y = 0;
|
||||||
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath);
|
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
|
||||||
|
|
||||||
//ViewportCreateInfo inspectorViewInfo;
|
//ViewportCreateInfo inspectorViewInfo;
|
||||||
//inspectorViewInfo.dimensions.size.x = 640;
|
//inspectorViewInfo.dimensions.size.x = 640;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ AssetRegistry::~AssetRegistry()
|
|||||||
delete assetRoot;
|
delete assetRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetRegistry::init(const std::string& rootFolder, Gfx::PGraphics graphics)
|
void AssetRegistry::init(std::filesystem::path rootFolder, Gfx::PGraphics graphics)
|
||||||
{
|
{
|
||||||
get().initialize(rootFolder, graphics);
|
get().initialize(rootFolder, graphics);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class AssetRegistry
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~AssetRegistry();
|
~AssetRegistry();
|
||||||
static void init(const std::string& rootFolder, Gfx::PGraphics graphics);
|
static void init(std::filesystem::path path, Gfx::PGraphics graphics);
|
||||||
|
|
||||||
static std::filesystem::path getRootFolder();
|
static std::filesystem::path getRootFolder();
|
||||||
|
|
||||||
|
|||||||
@@ -22,36 +22,35 @@ FontAsset::~FontAsset()
|
|||||||
|
|
||||||
void FontAsset::save(ArchiveBuffer& buffer) const
|
void FontAsset::save(ArchiveBuffer& buffer) const
|
||||||
{
|
{
|
||||||
uint64 numGlyphs = glyphs.size();
|
Serialization::save(buffer, glyphs);
|
||||||
Serialization::save(buffer, numGlyphs);
|
Serialization::save(buffer, usedTextures.size());
|
||||||
for (auto& [index, glyph] : glyphs)
|
for (uint32 x = 0; x < usedTextures.size(); ++x)
|
||||||
{
|
{
|
||||||
|
|
||||||
Array<uint8> textureData;
|
Array<uint8> textureData;
|
||||||
ktxTexture2* kTexture;
|
ktxTexture2* kTexture;
|
||||||
ktxTextureCreateInfo createInfo = {
|
ktxTextureCreateInfo createInfo = {
|
||||||
.glInternalformat = 0,
|
.glInternalformat = 0,
|
||||||
.vkFormat = (uint32_t)glyph.texture->getFormat(),
|
.vkFormat = (uint32_t)usedTextures[x]->getFormat(),
|
||||||
.pDfd = nullptr,
|
.pDfd = nullptr,
|
||||||
.baseWidth = glyph.texture->getSizeX(),
|
.baseWidth = usedTextures[x]->getSizeX(),
|
||||||
.baseHeight = glyph.texture->getSizeY(),
|
.baseHeight = usedTextures[x]->getSizeY(),
|
||||||
.baseDepth = glyph.texture->getSizeZ(),
|
.baseDepth = usedTextures[x]->getSizeZ(),
|
||||||
.numDimensions = glyph.texture->getSizeZ() > 1 ? 3u : glyph.texture->getSizeY() > 1 ? 2u : 1u,
|
.numDimensions = usedTextures[x]->getSizeZ() > 1 ? 3u : usedTextures[x]->getSizeY() > 1 ? 2u : 1u,
|
||||||
.numLevels = glyph.texture->getMipLevels(),
|
.numLevels = usedTextures[x]->getMipLevels(),
|
||||||
.numLayers = glyph.texture->getSizeZ(),
|
.numLayers = usedTextures[x]->getSizeZ(),
|
||||||
.numFaces = glyph.texture->getNumFaces(),
|
.numFaces = usedTextures[x]->getNumFaces(),
|
||||||
.isArray = false,
|
.isArray = false,
|
||||||
.generateMipmaps = false,
|
.generateMipmaps = false,
|
||||||
};
|
};
|
||||||
ktxTexture2_Create(&createInfo, KTX_TEXTURE_CREATE_ALLOC_STORAGE, &kTexture);
|
ktxTexture2_Create(&createInfo, KTX_TEXTURE_CREATE_ALLOC_STORAGE, &kTexture);
|
||||||
|
|
||||||
for (uint32 depth = 0; depth < glyph.texture->getSizeZ(); ++depth)
|
for (uint32 depth = 0; depth < usedTextures[x]->getSizeZ(); ++depth)
|
||||||
{
|
{
|
||||||
for (uint32 face = 0; face < glyph.texture->getNumFaces(); ++face)
|
for (uint32 face = 0; face < usedTextures[x]->getNumFaces(); ++face)
|
||||||
{
|
{
|
||||||
// technically, downloading cant be const, because we have to allocate temporary buffers and change layouts
|
// technically, downloading cant be const, because we have to allocate temporary buffers and change layouts
|
||||||
// but practically the texture stays the same
|
// but practically the texture stays the same
|
||||||
glyph.texture->download(0, depth, face, textureData);
|
usedTextures[x]->download(0, depth, face, textureData);
|
||||||
ktxTexture_SetImageFromMemory(ktxTexture(kTexture), 0, depth, face, textureData.data(), textureData.size());
|
ktxTexture_SetImageFromMemory(ktxTexture(kTexture), 0, depth, face, textureData.data(), textureData.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,26 +71,18 @@ void FontAsset::save(ArchiveBuffer& buffer) const
|
|||||||
|
|
||||||
free(texData);
|
free(texData);
|
||||||
|
|
||||||
Serialization::save(buffer, index);
|
|
||||||
Serialization::save(buffer, rawData);
|
Serialization::save(buffer, rawData);
|
||||||
Serialization::save(buffer, glyph.size);
|
|
||||||
Serialization::save(buffer, glyph.bearing);
|
|
||||||
Serialization::save(buffer, glyph.advance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FontAsset::load(ArchiveBuffer& buffer)
|
void FontAsset::load(ArchiveBuffer& buffer)
|
||||||
{
|
{
|
||||||
uint64 numGlyphs = glyphs.size();
|
Serialization::load(buffer, glyphs);
|
||||||
Serialization::load(buffer, numGlyphs);
|
size_t numTextures;
|
||||||
for (uint64 x = 0; x < numGlyphs; ++x)
|
Serialization::load(buffer, numTextures);
|
||||||
|
for (uint64 x = 0; x < numTextures; ++x)
|
||||||
{
|
{
|
||||||
uint32 index;
|
|
||||||
Serialization::load(buffer, index);
|
|
||||||
|
|
||||||
Glyph& glyph = glyphs[index];
|
|
||||||
|
|
||||||
Array<uint8> rawTex;
|
Array<uint8> rawTex;
|
||||||
Serialization::load(buffer, rawTex);
|
Serialization::load(buffer, rawTex);
|
||||||
|
|
||||||
@@ -120,13 +111,29 @@ void FontAsset::load(ArchiveBuffer& buffer)
|
|||||||
};
|
};
|
||||||
|
|
||||||
Gfx::OTexture2D texture = buffer.getGraphics()->createTexture2D(createInfo);
|
Gfx::OTexture2D texture = buffer.getGraphics()->createTexture2D(createInfo);
|
||||||
glyph.texture = texture;
|
|
||||||
usedTextures.add(std::move(texture));
|
usedTextures.add(std::move(texture));
|
||||||
|
|
||||||
ktxTexture_Destroy(ktxTexture(kTexture));
|
ktxTexture_Destroy(ktxTexture(kTexture));
|
||||||
|
|
||||||
Serialization::load(buffer, glyph.size);
|
|
||||||
Serialization::load(buffer, glyph.bearing);
|
|
||||||
Serialization::load(buffer, glyph.advance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Seele::FontAsset::setUsedTextures(Array<Gfx::OTexture2D> _usedTextures)
|
||||||
|
{
|
||||||
|
usedTextures = std::move(_usedTextures);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontAsset::Glyph::save(ArchiveBuffer& buffer) const
|
||||||
|
{
|
||||||
|
Serialization::save(buffer, textureIndex);
|
||||||
|
Serialization::save(buffer, size);
|
||||||
|
Serialization::save(buffer, bearing);
|
||||||
|
Serialization::save(buffer, advance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontAsset::Glyph::load(ArchiveBuffer& buffer)
|
||||||
|
{
|
||||||
|
Serialization::load(buffer, textureIndex);
|
||||||
|
Serialization::load(buffer, size);
|
||||||
|
Serialization::load(buffer, bearing);
|
||||||
|
Serialization::load(buffer, advance);
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,12 +18,16 @@ public:
|
|||||||
|
|
||||||
struct Glyph
|
struct Glyph
|
||||||
{
|
{
|
||||||
Gfx::PTexture2D texture;
|
uint32 textureIndex;
|
||||||
IVector2 size;
|
IVector2 size;
|
||||||
IVector2 bearing;
|
IVector2 bearing;
|
||||||
uint32 advance;
|
uint32 advance;
|
||||||
|
void save(ArchiveBuffer& buffer) const;
|
||||||
|
void load(ArchiveBuffer& buffer);
|
||||||
};
|
};
|
||||||
const Map<uint32, Glyph> getGlyphData() const { return glyphs; }
|
const Map<uint32, Glyph> getGlyphData() const { return glyphs; }
|
||||||
|
Gfx::PTexture2D getTexture(uint32 index) { return usedTextures[index]; }
|
||||||
|
void setUsedTextures(Array<Gfx::OTexture2D> _usedTextures);
|
||||||
private:
|
private:
|
||||||
Array<Gfx::OTexture2D> usedTextures;
|
Array<Gfx::OTexture2D> usedTextures;
|
||||||
Map<uint32, Glyph> glyphs;
|
Map<uint32, Glyph> glyphs;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ void MaterialInstanceAsset::load(ArchiveBuffer& buffer)
|
|||||||
{
|
{
|
||||||
std::string id;
|
std::string id;
|
||||||
Serialization::load(buffer, id);
|
Serialization::load(buffer, id);
|
||||||
|
material = new MaterialInstance();
|
||||||
material->load(buffer);
|
material->load(buffer);
|
||||||
baseMaterial = AssetRegistry::findMaterial(id);
|
baseMaterial = AssetRegistry::findMaterial(id);
|
||||||
material->setBaseMaterial(baseMaterial);
|
material->setBaseMaterial(baseMaterial);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ protected:
|
|||||||
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DECLARE_REF(UniformBuffer)
|
||||||
class UniformBuffer : public Buffer
|
class UniformBuffer : public Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -30,7 +31,7 @@ public:
|
|||||||
virtual ~UniformBuffer();
|
virtual ~UniformBuffer();
|
||||||
// returns true if an update was performed, false if the old contents == new contents
|
// returns true if an update was performed, false if the old contents == new contents
|
||||||
virtual bool updateContents(const DataSource& sourceData);
|
virtual bool updateContents(const DataSource& sourceData);
|
||||||
bool isDataEquals(UniformBuffer* other)
|
bool isDataEquals(PUniformBuffer other)
|
||||||
{
|
{
|
||||||
if(other == nullptr)
|
if(other == nullptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ namespace Gfx
|
|||||||
{
|
{
|
||||||
static constexpr bool useAsyncCompute = true;
|
static constexpr bool useAsyncCompute = true;
|
||||||
static constexpr bool waitIdleOnSubmit = true;
|
static constexpr bool waitIdleOnSubmit = true;
|
||||||
extern bool useMeshShading = false; // enable if supported
|
static constexpr bool useMeshShading = true;
|
||||||
static constexpr uint32 numFramesBuffered = 3;
|
static constexpr uint32 numFramesBuffered = 3;
|
||||||
|
|
||||||
// meshlet dimensions curated by NVIDIA
|
// meshlet dimensions curated by NVIDIA
|
||||||
|
|||||||
@@ -80,10 +80,11 @@ public:
|
|||||||
virtual OPipelineLayout createPipelineLayout(PPipelineLayout baseLayout = nullptr) = 0;
|
virtual OPipelineLayout createPipelineLayout(PPipelineLayout baseLayout = nullptr) = 0;
|
||||||
|
|
||||||
virtual void copyTexture(Gfx::PTexture srcTexture, Gfx::PTexture dstTexture) = 0;
|
virtual void copyTexture(Gfx::PTexture srcTexture, Gfx::PTexture dstTexture) = 0;
|
||||||
|
bool supportMeshShading() const { return meshShadingEnabled; }
|
||||||
protected:
|
protected:
|
||||||
QueueFamilyMapping queueMapping;
|
QueueFamilyMapping queueMapping;
|
||||||
OShaderCompiler shaderCompiler;
|
OShaderCompiler shaderCompiler;
|
||||||
|
bool meshShadingEnabled = false;
|
||||||
friend class Window;
|
friend class Window;
|
||||||
};
|
};
|
||||||
DEFINE_REF(Graphics)
|
DEFINE_REF(Graphics)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void BasePass::render()
|
|||||||
graphics->beginRenderPass(renderPass);
|
graphics->beginRenderPass(renderPass);
|
||||||
Gfx::ShaderPermutation permutation;
|
Gfx::ShaderPermutation permutation;
|
||||||
permutation.hasFragment = true;
|
permutation.hasFragment = true;
|
||||||
if(Gfx::useMeshShading)
|
if(graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
permutation.useMeshShading = true;
|
permutation.useMeshShading = true;
|
||||||
permutation.hasTaskShader = true;
|
permutation.hasTaskShader = true;
|
||||||
@@ -115,7 +115,7 @@ void BasePass::render()
|
|||||||
|
|
||||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
||||||
assert(collection != nullptr);
|
assert(collection != nullptr);
|
||||||
if(Gfx::useMeshShading)
|
if(graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
Gfx::MeshPipelineCreateInfo pipelineInfo;
|
Gfx::MeshPipelineCreateInfo pipelineInfo;
|
||||||
pipelineInfo.taskShader = collection->taskShader;
|
pipelineInfo.taskShader = collection->taskShader;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public:
|
|||||||
virtual void createRenderPass() override;
|
virtual void createRenderPass() override;
|
||||||
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
||||||
private:
|
private:
|
||||||
Gfx::PRenderTargetAttachment colorAttachment;
|
Gfx::ORenderTargetAttachment colorAttachment;
|
||||||
Gfx::PTexture2D depthBuffer;
|
Gfx::PTexture2D depthBuffer;
|
||||||
Gfx::PShaderBuffer oLightIndexList;
|
Gfx::PShaderBuffer oLightIndexList;
|
||||||
Gfx::PShaderBuffer tLightIndexList;
|
Gfx::PShaderBuffer tLightIndexList;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void DepthPrepass::render()
|
|||||||
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
|
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||||
Gfx::ShaderPermutation permutation;
|
Gfx::ShaderPermutation permutation;
|
||||||
permutation.hasFragment = false;
|
permutation.hasFragment = false;
|
||||||
if(Gfx::useMeshShading)
|
if(graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
permutation.useMeshShading = true;
|
permutation.useMeshShading = true;
|
||||||
permutation.hasTaskShader = true;
|
permutation.hasTaskShader = true;
|
||||||
@@ -76,7 +76,7 @@ void DepthPrepass::render()
|
|||||||
|
|
||||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
||||||
assert(collection != nullptr);
|
assert(collection != nullptr);
|
||||||
if(Gfx::useMeshShading)
|
if(graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
Gfx::MeshPipelineCreateInfo pipelineInfo;
|
Gfx::MeshPipelineCreateInfo pipelineInfo;
|
||||||
pipelineInfo.taskShader = collection->taskShader;
|
pipelineInfo.taskShader = collection->taskShader;
|
||||||
@@ -107,7 +107,7 @@ void DepthPrepass::render()
|
|||||||
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
|
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
|
||||||
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
|
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
|
||||||
command->bindDescriptor(descriptorSets);
|
command->bindDescriptor(descriptorSets);
|
||||||
if(Gfx::useMeshShading)
|
if(graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
command->dispatch(instance.numMeshes, 1, 1);
|
command->dispatch(instance.numMeshes, 1, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ TextPass::FontData& TextPass::getFontData(PFontAsset font)
|
|||||||
gd.bearing = value.bearing;
|
gd.bearing = value.bearing;
|
||||||
gd.size = value.size;
|
gd.size = value.size;
|
||||||
gd.advance = value.advance;
|
gd.advance = value.advance;
|
||||||
textures.add(value.texture);
|
textures.add(font->getTexture(value.textureIndex));
|
||||||
}
|
}
|
||||||
fd.glyphDataSet = glyphData;
|
fd.glyphDataSet = glyphData;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public:
|
|||||||
void loadNormals(MeshId id, const Array<Vector>& data);
|
void loadNormals(MeshId id, const Array<Vector>& data);
|
||||||
void loadTangents(MeshId id, const Array<Vector>& data);
|
void loadTangents(MeshId id, const Array<Vector>& data);
|
||||||
void loadBiTangents(MeshId id, const Array<Vector>& data);
|
void loadBiTangents(MeshId id, const Array<Vector>& data);
|
||||||
virtual Gfx::PVertexDeclaration getDeclaration() override;
|
|
||||||
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override;
|
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override;
|
||||||
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
||||||
virtual void init(Gfx::PGraphics graphics) override;
|
virtual void init(Gfx::PGraphics graphics) override;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ void VertexData::createDescriptors()
|
|||||||
instanceDataLayout->reset();
|
instanceDataLayout->reset();
|
||||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
||||||
matInst.descriptorSet->updateBuffer(0, instanceBuffer);
|
matInst.descriptorSet->updateBuffer(0, instanceBuffer);
|
||||||
if (Gfx::useMeshShading)
|
if (graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
Gfx::PShaderBuffer meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
Gfx::PShaderBuffer meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData = {
|
.sourceData = {
|
||||||
@@ -181,7 +181,7 @@ void Seele::VertexData::init(Gfx::PGraphics graphics)
|
|||||||
verticesAllocated = NUM_DEFAULT_ELEMENTS;
|
verticesAllocated = NUM_DEFAULT_ELEMENTS;
|
||||||
instanceDataLayout = graphics->createDescriptorLayout("VertexDataInstanceLayout");
|
instanceDataLayout = graphics->createDescriptorLayout("VertexDataInstanceLayout");
|
||||||
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
if (Gfx::useMeshShading)
|
if (graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
// meshData
|
// meshData
|
||||||
instanceDataLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
instanceDataLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
|
|||||||
@@ -89,10 +89,8 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto& it : freeRanges)
|
for (auto& [allocatedOffset, freeAllocation] : freeRanges)
|
||||||
{
|
{
|
||||||
VkDeviceSize allocatedOffset = it.key;
|
|
||||||
OSubAllocation& freeAllocation = it.value;
|
|
||||||
assert(allocatedOffset == freeAllocation->allocatedOffset);
|
assert(allocatedOffset == freeAllocation->allocatedOffset);
|
||||||
VkDeviceSize alignedOffset = allocatedOffset + alignment - 1;
|
VkDeviceSize alignedOffset = allocatedOffset + alignment - 1;
|
||||||
alignedOffset /= alignment;
|
alignedOffset /= alignment;
|
||||||
@@ -284,18 +282,18 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
|
|||||||
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
|
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Allocator::free(Allocation *allocation)
|
void Allocator::free(PAllocation allocation)
|
||||||
{
|
{
|
||||||
std::scoped_lock lck(lock);
|
std::scoped_lock lck(lock);
|
||||||
for (auto& heap : heaps)
|
for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex)
|
||||||
{
|
{
|
||||||
for (uint32 heapIndex = 0; heapIndex < heap.allocations.size(); ++heapIndex)
|
for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc)
|
||||||
{
|
{
|
||||||
if (heap.allocations[heapIndex] == allocation)
|
if (heaps[heapIndex].allocations[alloc] == allocation)
|
||||||
{
|
{
|
||||||
heap.inUse -= allocation->bytesAllocated;
|
heaps[heapIndex].inUse -= allocation->bytesAllocated;
|
||||||
std::cout << "Heap " << heapIndex << " -" <<allocation->bytesAllocated << ":" << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
|
std::cout << "Heap " << heapIndex << " -" <<allocation->bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
|
||||||
heap.allocations.removeAt(heapIndex, false);
|
heaps[heapIndex].allocations.removeAt(heapIndex, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,11 +430,11 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
|
|||||||
|
|
||||||
void StagingManager::releaseStagingBuffer(OStagingBuffer buffer)
|
void StagingManager::releaseStagingBuffer(OStagingBuffer buffer)
|
||||||
{
|
{
|
||||||
std::scoped_lock l(lock);
|
if (buffer == nullptr)
|
||||||
if(activeBuffers.find(buffer) == activeBuffers.end())
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
std::scoped_lock l(lock);
|
||||||
activeBuffers.remove(buffer);
|
activeBuffers.remove(buffer);
|
||||||
std::cout << "Releasing stagingbuffer size " << buffer->getSize() << std::endl;
|
std::cout << "Releasing stagingbuffer size " << buffer->getSize() << std::endl;
|
||||||
freeBuffers.add(std::move(buffer));
|
freeBuffers.add(std::move(buffer));
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public:
|
|||||||
return allocate(requirements, props, &allocInfo);
|
return allocate(requirements, props, &allocInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(Allocation *allocation);
|
void free(PAllocation allocation);
|
||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,20 +61,6 @@ Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, Gfx::Q
|
|||||||
|
|
||||||
Buffer::~Buffer()
|
Buffer::~Buffer()
|
||||||
{
|
{
|
||||||
//PCmdBuffer cmdBuffer = graphics->getQueueCommands(owner)->getCommands();
|
|
||||||
//VkDevice device = graphics->getDevice();
|
|
||||||
//auto deletionLambda = [cmdBuffer, device](VkBuffer) -> void
|
|
||||||
//{
|
|
||||||
// //co_await cmdBuffer->asyncWait();
|
|
||||||
// //vkDestroyBuffer(device, buffer, nullptr);
|
|
||||||
// //co_return;
|
|
||||||
//};
|
|
||||||
//for (uint32 i = 0; i < numBuffers; ++i)
|
|
||||||
//{
|
|
||||||
// deletionLambda(buffers[i].buffer);
|
|
||||||
// buffers[i].allocation = nullptr;
|
|
||||||
//}
|
|
||||||
graphics = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkDeviceSize Buffer::getOffset() const
|
VkDeviceSize Buffer::getOffset() const
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ namespace Seele
|
|||||||
{
|
{
|
||||||
namespace Vulkan
|
namespace Vulkan
|
||||||
{
|
{
|
||||||
|
|
||||||
class Buffer
|
class Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -114,108 +114,95 @@ void Graphics::executeCommands(const Array<Gfx::PComputeCommand>& commands)
|
|||||||
|
|
||||||
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo)
|
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo)
|
||||||
{
|
{
|
||||||
OTexture2D result = new Texture2D(this, createInfo);
|
return new Texture2D(this, createInfo);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo)
|
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo)
|
||||||
{
|
{
|
||||||
OTexture3D result = new Texture3D(this, createInfo);
|
return new Texture3D(this, createInfo);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo &createInfo)
|
Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo &createInfo)
|
||||||
{
|
{
|
||||||
OTextureCube result = new TextureCube(this, createInfo);
|
return new TextureCube(this, createInfo);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData)
|
Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
OUniformBuffer uniformBuffer = new UniformBuffer(this, bulkData);
|
return new UniformBuffer(this, bulkData);
|
||||||
return uniformBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData)
|
Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
OShaderBuffer shaderBuffer = new ShaderBuffer(this, bulkData);
|
return new ShaderBuffer(this, bulkData);
|
||||||
return shaderBuffer;
|
|
||||||
}
|
}
|
||||||
Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData)
|
Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
OVertexBuffer vertexBuffer = new VertexBuffer(this, bulkData);
|
return new VertexBuffer(this, bulkData);
|
||||||
return vertexBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData)
|
Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
OIndexBuffer indexBuffer = new IndexBuffer(this, bulkData);
|
return new IndexBuffer(this, bulkData);
|
||||||
return indexBuffer;
|
|
||||||
}
|
}
|
||||||
Gfx::PRenderCommand Graphics::createRenderCommand(const std::string& name)
|
Gfx::PRenderCommand Graphics::createRenderCommand(const std::string& name)
|
||||||
{
|
{
|
||||||
PRenderCommand cmdBuffer = getGraphicsCommands()->createRenderCommand(activeRenderPass, activeFramebuffer, name);
|
return getGraphicsCommands()->createRenderCommand(activeRenderPass, activeFramebuffer, name);
|
||||||
return cmdBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name)
|
Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name)
|
||||||
{
|
{
|
||||||
PComputeCommand cmdBuffer = getComputeCommands()->createComputeCommand(name);
|
return getComputeCommands()->createComputeCommand(name);
|
||||||
return cmdBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OVertexDeclaration Graphics::createVertexDeclaration(const Array<Gfx::VertexElement>& element)
|
Gfx::OVertexDeclaration Graphics::createVertexDeclaration(const Array<Gfx::VertexElement>& element)
|
||||||
{
|
{
|
||||||
OVertexDeclaration declaration = new VertexDeclaration(element);
|
return new VertexDeclaration(element);
|
||||||
return declaration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo)
|
Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OVertexShader shader = new VertexShader(this);
|
OVertexShader shader = new VertexShader(this);
|
||||||
shader->create(createInfo);
|
shader->create(createInfo);
|
||||||
return shader;
|
return std::move(shader);
|
||||||
}
|
}
|
||||||
Gfx::OFragmentShader Graphics::createFragmentShader(const ShaderCreateInfo& createInfo)
|
Gfx::OFragmentShader Graphics::createFragmentShader(const ShaderCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OFragmentShader shader = new FragmentShader(this);
|
OFragmentShader shader = new FragmentShader(this);
|
||||||
shader->create(createInfo);
|
shader->create(createInfo);
|
||||||
return shader;
|
return std::move(shader);
|
||||||
}
|
}
|
||||||
Gfx::OComputeShader Graphics::createComputeShader(const ShaderCreateInfo& createInfo)
|
Gfx::OComputeShader Graphics::createComputeShader(const ShaderCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OComputeShader shader = new ComputeShader(this);
|
OComputeShader shader = new ComputeShader(this);
|
||||||
shader->create(createInfo);
|
shader->create(createInfo);
|
||||||
return shader;
|
return std::move(shader);
|
||||||
}
|
}
|
||||||
Gfx::OTaskShader Graphics::createTaskShader(const ShaderCreateInfo& createInfo)
|
Gfx::OTaskShader Graphics::createTaskShader(const ShaderCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OTaskShader shader = new TaskShader(this);
|
OTaskShader shader = new TaskShader(this);
|
||||||
shader->create(createInfo);
|
shader->create(createInfo);
|
||||||
return shader;
|
return std::move(shader);
|
||||||
}
|
}
|
||||||
Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo)
|
Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OMeshShader shader = new MeshShader(this);
|
OMeshShader shader = new MeshShader(this);
|
||||||
shader->create(createInfo);
|
shader->create(createInfo);
|
||||||
return shader;
|
return std::move(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OGraphicsPipeline Graphics::createGraphicsPipeline(const Gfx::LegacyPipelineCreateInfo& createInfo)
|
Gfx::OGraphicsPipeline Graphics::createGraphicsPipeline(const Gfx::LegacyPipelineCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OGraphicsPipeline pipeline = pipelineCache->createPipeline(createInfo);
|
return pipelineCache->createPipeline(createInfo);
|
||||||
return pipeline;
|
|
||||||
}
|
}
|
||||||
Gfx::OGraphicsPipeline Graphics::createGraphicsPipeline(const Gfx::MeshPipelineCreateInfo& createInfo)
|
Gfx::OGraphicsPipeline Graphics::createGraphicsPipeline(const Gfx::MeshPipelineCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OGraphicsPipeline pipeline = pipelineCache->createPipeline(createInfo);
|
return pipelineCache->createPipeline(createInfo);
|
||||||
return pipeline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OComputePipeline Graphics::createComputePipeline(const Gfx::ComputePipelineCreateInfo& createInfo)
|
Gfx::OComputePipeline Graphics::createComputePipeline(const Gfx::ComputePipelineCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
OComputePipeline pipeline = pipelineCache->createPipeline(createInfo);
|
return pipelineCache->createPipeline(createInfo);
|
||||||
return pipeline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OSamplerState Graphics::createSamplerState(const SamplerCreateInfo& createInfo)
|
Gfx::OSamplerState Graphics::createSamplerState(const SamplerCreateInfo& createInfo)
|
||||||
@@ -240,17 +227,15 @@ Gfx::OSamplerState Graphics::createSamplerState(const SamplerCreateInfo& createI
|
|||||||
vkInfo.mipmapMode = cast(createInfo.mipmapMode);
|
vkInfo.mipmapMode = cast(createInfo.mipmapMode);
|
||||||
vkInfo.unnormalizedCoordinates = createInfo.unnormalizedCoordinates;
|
vkInfo.unnormalizedCoordinates = createInfo.unnormalizedCoordinates;
|
||||||
VK_CHECK(vkCreateSampler(handle, &vkInfo, nullptr, &sampler->sampler));
|
VK_CHECK(vkCreateSampler(handle, &vkInfo, nullptr, &sampler->sampler));
|
||||||
return sampler;
|
return std::move(sampler);
|
||||||
}
|
}
|
||||||
Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name)
|
Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name)
|
||||||
{
|
{
|
||||||
ODescriptorLayout layout = new DescriptorLayout(this, name);
|
return new DescriptorLayout(this, name);
|
||||||
return layout;
|
|
||||||
}
|
}
|
||||||
Gfx::OPipelineLayout Graphics::createPipelineLayout(Gfx::PPipelineLayout baseLayout)
|
Gfx::OPipelineLayout Graphics::createPipelineLayout(Gfx::PPipelineLayout baseLayout)
|
||||||
{
|
{
|
||||||
OPipelineLayout layout = new PipelineLayout(this, baseLayout);
|
return new PipelineLayout(this, baseLayout);
|
||||||
return layout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::copyTexture(Gfx::PTexture srcTexture, Gfx::PTexture dstTexture)
|
void Graphics::copyTexture(Gfx::PTexture srcTexture, Gfx::PTexture dstTexture)
|
||||||
@@ -469,18 +454,21 @@ void Graphics::pickPhysicalDevice()
|
|||||||
physicalDevice = bestDevice;
|
physicalDevice = bestDevice;
|
||||||
vkGetPhysicalDeviceProperties(physicalDevice, &props);
|
vkGetPhysicalDeviceProperties(physicalDevice, &props);
|
||||||
vkGetPhysicalDeviceFeatures(physicalDevice, &features);
|
vkGetPhysicalDeviceFeatures(physicalDevice, &features);
|
||||||
|
if (Gfx::useMeshShading)
|
||||||
|
{
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
vkEnumerateDeviceExtensionProperties(physicalDevice, "VK_EXT_mesh_shader", &count, nullptr);
|
vkEnumerateDeviceExtensionProperties(physicalDevice, VK_EXT_MESH_SHADER_EXTENSION_NAME, &count, nullptr);
|
||||||
Array<VkExtensionProperties> extensionProps(count);
|
Array<VkExtensionProperties> extensionProps(count);
|
||||||
vkEnumerateDeviceExtensionProperties(physicalDevice, "VK_EXT_mesh_shader", &count, extensionProps.data());
|
vkEnumerateDeviceExtensionProperties(physicalDevice, VK_EXT_MESH_SHADER_EXTENSION_NAME, &count, extensionProps.data());
|
||||||
for(size_t i = 0; i < count; ++i)
|
for (size_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
if(std::strcmp("VK_EXT_mesh_shader", extensionProps[i].extensionName) == 0)
|
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
||||||
{
|
{
|
||||||
Gfx::useMeshShading = true;
|
meshShadingEnabled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::createDevice(GraphicsInitializer initializer)
|
void Graphics::createDevice(GraphicsInitializer initializer)
|
||||||
@@ -605,7 +593,7 @@ void Graphics::createDevice(GraphicsInitializer initializer)
|
|||||||
.taskShader = VK_TRUE,
|
.taskShader = VK_TRUE,
|
||||||
.meshShader = VK_TRUE,
|
.meshShader = VK_TRUE,
|
||||||
};
|
};
|
||||||
if (Gfx::useMeshShading)
|
if (supportMeshShading())
|
||||||
{
|
{
|
||||||
descriptorIndexing.pNext = &enabledMeshShaderFeatures;
|
descriptorIndexing.pNext = &enabledMeshShaderFeatures;
|
||||||
initializer.deviceExtensions.add("VK_EXT_mesh_shader");
|
initializer.deviceExtensions.add("VK_EXT_mesh_shader");
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ PipelineCache::~PipelineCache()
|
|||||||
{
|
{
|
||||||
VkDeviceSize cacheSize;
|
VkDeviceSize cacheSize;
|
||||||
vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, nullptr);
|
vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, nullptr);
|
||||||
Array<uint8> cacheData;
|
Array<uint8> cacheData(cacheSize);
|
||||||
vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, cacheData.data());
|
vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, cacheData.data());
|
||||||
std::ofstream stream(cacheFile, std::ios::binary);
|
std::ofstream stream(cacheFile, std::ios::binary);
|
||||||
stream.write((char*)cacheData.data(), cacheSize);
|
stream.write((char*)cacheData.data(), cacheSize);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Vulkan;
|
using namespace Seele::Vulkan;
|
||||||
|
|
||||||
double useMeshShading = false;
|
|
||||||
double currentFrameDelta = 0;
|
double currentFrameDelta = 0;
|
||||||
double Gfx::getCurrentFrameDelta()
|
double Gfx::getCurrentFrameDelta()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
|
|||||||
if(sourceData.size > 0)
|
if(sourceData.size > 0)
|
||||||
{
|
{
|
||||||
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||||
PStagingBuffer staging = graphics->getStagingManager()->allocateStagingBuffer(sourceData.size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
OStagingBuffer staging = graphics->getStagingManager()->allocateStagingBuffer(sourceData.size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||||
void* data = staging->getMappedPointer();
|
void* data = staging->getMappedPointer();
|
||||||
std::memcpy(data, sourceData.data, sourceData.size);
|
std::memcpy(data, sourceData.data, sourceData.size);
|
||||||
staging->flushMappedMemory();
|
staging->flushMappedMemory();
|
||||||
@@ -134,6 +134,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
|
|||||||
|
|
||||||
// When loading a texture from a file, we will almost always use it as a texture map for fragment shaders
|
// When loading a texture from a file, we will almost always use it as a texture map for fragment shaders
|
||||||
changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||||
|
graphics->getStagingManager()->releaseStagingBuffer(std::move(staging));
|
||||||
}
|
}
|
||||||
else if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
else if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||||
{
|
{
|
||||||
@@ -213,7 +214,7 @@ void TextureHandle::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Ar
|
|||||||
{
|
{
|
||||||
uint64 imageSize = sizeX * sizeY * sizeZ * Gfx::getFormatInfo(format).blockSize;
|
uint64 imageSize = sizeX * sizeY * sizeZ * Gfx::getFormatInfo(format).blockSize;
|
||||||
|
|
||||||
PStagingBuffer stagingbuffer = graphics->getStagingManager()->allocateStagingBuffer(imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true);
|
OStagingBuffer stagingbuffer = graphics->getStagingManager()->allocateStagingBuffer(imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true);
|
||||||
auto prevlayout = layout;
|
auto prevlayout = layout;
|
||||||
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||||
PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
|
PCmdBuffer cmdBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
|
||||||
@@ -236,6 +237,7 @@ void TextureHandle::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Ar
|
|||||||
buffer.resize(stagingbuffer->getSize());
|
buffer.resize(stagingbuffer->getSize());
|
||||||
void* data = stagingbuffer->getMappedPointer();
|
void* data = stagingbuffer->getMappedPointer();
|
||||||
std::memcpy(buffer.data(), data, buffer.size());
|
std::memcpy(buffer.data(), data, buffer.size());
|
||||||
|
graphics->getStagingManager()->releaseStagingBuffer(std::move(stagingbuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureHandle::executeOwnershipBarrier(Gfx::QueueType newOwner)
|
void TextureHandle::executeOwnershipBarrier(Gfx::QueueType newOwner)
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ public:
|
|||||||
OwningPtr(OwningPtr<F>&& other)
|
OwningPtr(OwningPtr<F>&& other)
|
||||||
{
|
{
|
||||||
pointer = dynamic_cast<T*>(*other);
|
pointer = dynamic_cast<T*>(*other);
|
||||||
|
other.clear();
|
||||||
}
|
}
|
||||||
OwningPtr(const OwningPtr& other) = delete;
|
OwningPtr(const OwningPtr& other) = delete;
|
||||||
OwningPtr(OwningPtr&& other) noexcept
|
OwningPtr(OwningPtr&& other) noexcept
|
||||||
@@ -162,9 +163,14 @@ public:
|
|||||||
Deleter()(pointer);
|
Deleter()(pointer);
|
||||||
}
|
}
|
||||||
pointer = other.pointer;
|
pointer = other.pointer;
|
||||||
|
other.pointer = nullptr;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
~OwningPtr()
|
||||||
|
{
|
||||||
|
Deleter()(pointer);
|
||||||
|
}
|
||||||
operator RefPtr<T>()
|
operator RefPtr<T>()
|
||||||
{
|
{
|
||||||
return RefPtr<T>(pointer);
|
return RefPtr<T>(pointer);
|
||||||
@@ -189,14 +195,19 @@ public:
|
|||||||
{
|
{
|
||||||
return pointer;
|
return pointer;
|
||||||
}
|
}
|
||||||
constexpr bool operator==(const OwningPtr& rhs) const noexcept
|
constexpr bool operator==(std::nullptr_t) const noexcept
|
||||||
{
|
{
|
||||||
return pointer == rhs.pointer;
|
return pointer == nullptr;
|
||||||
}
|
}
|
||||||
constexpr auto operator<=>(const OwningPtr& rhs) const noexcept
|
constexpr auto operator<=>(const OwningPtr& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return pointer <=> rhs.pointer;
|
return pointer <=> rhs.pointer;
|
||||||
}
|
}
|
||||||
|
// INTERNAL USE
|
||||||
|
constexpr void clear()
|
||||||
|
{
|
||||||
|
pointer = nullptr;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
friend class RefPtr<T>;
|
friend class RefPtr<T>;
|
||||||
T* pointer;
|
T* pointer;
|
||||||
|
|||||||
Reference in New Issue
Block a user