3700 FPS here we go
This commit is contained in:
Vendored
+2
-1
@@ -107,7 +107,8 @@
|
|||||||
"stack": "cpp",
|
"stack": "cpp",
|
||||||
"coroutine": "cpp",
|
"coroutine": "cpp",
|
||||||
"*.tcc": "cpp",
|
"*.tcc": "cpp",
|
||||||
"stop_token": "cpp"
|
"stop_token": "cpp",
|
||||||
|
"span": "cpp"
|
||||||
},
|
},
|
||||||
"cmake.skipConfigureIfCachePresent": false,
|
"cmake.skipConfigureIfCachePresent": false,
|
||||||
"cmake.configureArgs": [
|
"cmake.configureArgs": [
|
||||||
|
|||||||
@@ -45,17 +45,12 @@ PMeshAsset AssetRegistry::findMesh(const std::string &filePath)
|
|||||||
{
|
{
|
||||||
auto it = get().meshes.find(filePath);
|
auto it = get().meshes.find(filePath);
|
||||||
assert(it != get().meshes.end());
|
assert(it != get().meshes.end());
|
||||||
return it->value;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
PTextureAsset AssetRegistry::findTexture(const std::string &filePath)
|
PTextureAsset AssetRegistry::findTexture(const std::string &filePath)
|
||||||
{
|
{
|
||||||
PTextureAsset result = get().textures[filePath];
|
return get().textures[filePath];
|
||||||
if(result == nullptr)
|
|
||||||
{
|
|
||||||
return get().textureLoader->getPlaceholderTexture();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath)
|
PMaterialAsset AssetRegistry::findMaterial(const std::string &filePath)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "MinimalEngine.h"
|
#include "MinimalEngine.h"
|
||||||
#include "Asset.h"
|
#include "Asset.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
@@ -46,9 +47,10 @@ private:
|
|||||||
std::ifstream internalCreateReadStream(const std::string& relaitvePath, std::ios_base::openmode openmode = std::ios::in);
|
std::ifstream internalCreateReadStream(const std::string& relaitvePath, std::ios_base::openmode openmode = std::ios::in);
|
||||||
|
|
||||||
std::filesystem::path rootFolder;
|
std::filesystem::path rootFolder;
|
||||||
Map<std::string, PTextureAsset> textures;
|
//Todo: Seele::Map doesn't really work with strings for some reason, so just use std::map for now
|
||||||
Map<std::string, PMeshAsset> meshes;
|
std::map<std::string, PTextureAsset> textures;
|
||||||
Map<std::string, PMaterialAsset> materials;
|
std::map<std::string, PMeshAsset> meshes;
|
||||||
|
std::map<std::string, PMaterialAsset> materials;
|
||||||
UPTextureLoader textureLoader;
|
UPTextureLoader textureLoader;
|
||||||
UPMeshLoader meshLoader;
|
UPMeshLoader meshLoader;
|
||||||
UPMaterialLoader materialLoader;
|
UPMaterialLoader materialLoader;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
}
|
}
|
||||||
Gfx::PTexture getTexture()
|
Gfx::PTexture getTexture()
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lck(lock);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ TextureLoader::TextureLoader(Gfx::PGraphics graphics)
|
|||||||
placeholderTexture = import("./textures/placeholder.png");
|
placeholderTexture = import("./textures/placeholder.png");
|
||||||
placeholderAsset->setTexture(placeholderTexture);
|
placeholderAsset->setTexture(placeholderTexture);
|
||||||
placeholderAsset->setStatus(Asset::Status::Ready);
|
placeholderAsset->setStatus(Asset::Status::Ready);
|
||||||
|
AssetRegistry::get().textures[""] = placeholderAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureLoader::~TextureLoader()
|
TextureLoader::~TextureLoader()
|
||||||
@@ -28,13 +29,13 @@ void TextureLoader::importAsset(const std::filesystem::path& filePath)
|
|||||||
PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string());
|
PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string());
|
||||||
asset->setStatus(Asset::Status::Loading);
|
asset->setStatus(Asset::Status::Loading);
|
||||||
asset->setTexture(placeholderTexture);
|
asset->setTexture(placeholderTexture);
|
||||||
std::cout << "Loading texture, placeholder" << std::endl;
|
|
||||||
AssetRegistry::get().textures[asset->getFileName()] = asset;
|
AssetRegistry::get().textures[asset->getFileName()] = asset;
|
||||||
futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
|
futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(5s);
|
||||||
Gfx::PTexture2D texture = import(filePath);
|
Gfx::PTexture2D texture = import(filePath);
|
||||||
asset->setTexture(texture);
|
asset->setTexture(texture);
|
||||||
asset->setStatus(Asset::Status::Ready);
|
asset->setStatus(Asset::Status::Ready);
|
||||||
std::cout << "Finished loading texture" << std::endl;
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -280,11 +280,11 @@ public:
|
|||||||
}
|
}
|
||||||
inline V &operator[](K&& key)
|
inline V &operator[](K&& key)
|
||||||
{
|
{
|
||||||
root = splay(root, std::forward<K>(key));
|
root = splay(root, std::move(key));
|
||||||
markIteratorDirty();
|
markIteratorDirty();
|
||||||
if (root == nullptr || root->pair.key < key || key < root->pair.key)
|
if (root == nullptr || root->pair.key < key || key < root->pair.key)
|
||||||
{
|
{
|
||||||
root = insert(root, std::forward<K>(key));
|
root = insert(root, std::move(key));
|
||||||
_size++;
|
_size++;
|
||||||
}
|
}
|
||||||
return root->pair.value;
|
return root->pair.value;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ target_sources(SeeleEngine
|
|||||||
GraphicsResources.cpp
|
GraphicsResources.cpp
|
||||||
GraphicsInitializer.h
|
GraphicsInitializer.h
|
||||||
GraphicsEnums.h
|
GraphicsEnums.h
|
||||||
|
GraphicsEnums.cpp
|
||||||
Graphics.h
|
Graphics.h
|
||||||
Graphics.cpp
|
Graphics.cpp
|
||||||
Mesh.h
|
Mesh.h
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#include "GraphicsEnums.h"
|
||||||
|
|
||||||
|
using namespace Gfx;
|
||||||
|
|
||||||
|
uint32 Gfx::currentFrameIndex = 0;
|
||||||
|
double Gfx::currentFrameDelta = 0;
|
||||||
@@ -164,7 +164,8 @@ namespace Gfx
|
|||||||
static constexpr bool useAsyncCompute = true;
|
static constexpr bool useAsyncCompute = true;
|
||||||
static constexpr bool waitIdleOnSubmit = false;
|
static constexpr bool waitIdleOnSubmit = false;
|
||||||
static constexpr uint32 numFramesBuffered = 8;
|
static constexpr uint32 numFramesBuffered = 8;
|
||||||
static uint32 currentFrameIndex = 0;
|
extern uint32 currentFrameIndex;
|
||||||
|
extern double currentFrameDelta;
|
||||||
|
|
||||||
enum class MaterialShadingModel
|
enum class MaterialShadingModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -168,12 +168,11 @@ Buffer::~Buffer()
|
|||||||
|
|
||||||
UniformBuffer::UniformBuffer(QueueFamilyMapping mapping, const BulkResourceData& resourceData)
|
UniformBuffer::UniformBuffer(QueueFamilyMapping mapping, const BulkResourceData& resourceData)
|
||||||
: Buffer(mapping, resourceData.owner)
|
: Buffer(mapping, resourceData.owner)
|
||||||
, size(resourceData.size)
|
, contents(resourceData.size)
|
||||||
{
|
{
|
||||||
if(resourceData.data != nullptr)
|
if(resourceData.data != nullptr)
|
||||||
{
|
{
|
||||||
contents = new uint8[size];
|
std::memcpy(contents.data(), resourceData.data, contents.size());
|
||||||
std::memcpy(contents, resourceData.data, size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,10 +180,15 @@ UniformBuffer::~UniformBuffer()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void UniformBuffer::updateContents(const BulkResourceData& resourceData)
|
bool UniformBuffer::updateContents(const BulkResourceData& resourceData)
|
||||||
{
|
{
|
||||||
assert(size == resourceData.size);
|
assert(contents.size() == resourceData.size);
|
||||||
std::memcpy(contents, resourceData.data, size);
|
if(std::memcmp(contents.data(), resourceData.data, contents.size()) == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::memcpy(contents.data(), resourceData.data, contents.size());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, QueueType startQueueType)
|
StructuredBuffer::StructuredBuffer(QueueFamilyMapping mapping, QueueType startQueueType)
|
||||||
|
|||||||
@@ -321,26 +321,26 @@ class UniformBuffer : public Buffer
|
|||||||
public:
|
public:
|
||||||
UniformBuffer(QueueFamilyMapping mapping, const BulkResourceData& resourceData);
|
UniformBuffer(QueueFamilyMapping mapping, const BulkResourceData& resourceData);
|
||||||
virtual ~UniformBuffer();
|
virtual ~UniformBuffer();
|
||||||
virtual void updateContents(const BulkResourceData& resourceData);
|
// returns true if an update was performed, false if the old contents == new contents
|
||||||
|
virtual bool updateContents(const BulkResourceData& resourceData);
|
||||||
bool isDataEquals(UniformBuffer* other)
|
bool isDataEquals(UniformBuffer* other)
|
||||||
{
|
{
|
||||||
if(other == nullptr)
|
if(other == nullptr)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(size != other->size)
|
if(contents.size() != other->contents.size())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(std::memcmp(contents, other->contents, size) != 0)
|
if(std::memcmp(contents.data(), other->contents.data(), contents.size()) != 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
void* contents;
|
Array<uint8> contents;
|
||||||
uint32 size;
|
|
||||||
// Inherited via QueueOwnedResource
|
// Inherited via QueueOwnedResource
|
||||||
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport v
|
|||||||
lightLayout = graphics->createDescriptorLayout();
|
lightLayout = graphics->createDescriptorLayout();
|
||||||
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
uniformInitializer.resourceData.size = sizeof(LightEnv);
|
uniformInitializer.resourceData.size = sizeof(LightEnv);
|
||||||
uniformInitializer.resourceData.data = (uint8*)&scene->getLightEnvironment();
|
uniformInitializer.resourceData.data = nullptr;
|
||||||
uniformInitializer.bDynamic = true;
|
uniformInitializer.bDynamic = true;
|
||||||
lightUniform = graphics->createUniformBuffer(uniformInitializer);
|
lightUniform = graphics->createUniformBuffer(uniformInitializer);
|
||||||
lightLayout->create();
|
lightLayout->create();
|
||||||
@@ -163,14 +163,18 @@ void BasePass::beginFrame()
|
|||||||
descriptorSets[1]->updateBuffer(0, viewParamBuffer);
|
descriptorSets[1]->updateBuffer(0, viewParamBuffer);
|
||||||
descriptorSets[1]->updateBuffer(1, screenToViewParamBuffer);
|
descriptorSets[1]->updateBuffer(1, screenToViewParamBuffer);
|
||||||
descriptorSets[1]->writeChanges();
|
descriptorSets[1]->writeChanges();
|
||||||
|
for(auto &&meshBatch : scene->getStaticMeshes())
|
||||||
|
{
|
||||||
|
meshBatch.material->updateDescriptorData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasePass::render()
|
void BasePass::render()
|
||||||
{
|
{
|
||||||
graphics->beginRenderPass(renderPass);
|
graphics->beginRenderPass(renderPass);
|
||||||
for (auto &&primitive : scene->getStaticMeshes())
|
for (auto &&meshBatch : scene->getStaticMeshes())
|
||||||
{
|
{
|
||||||
processor->addMeshBatch(primitive, renderPass, basePassLayout, primitiveLayout, descriptorSets);
|
processor->addMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets);
|
||||||
}
|
}
|
||||||
graphics->executeCommands(processor->getRenderCommands());
|
graphics->executeCommands(processor->getRenderCommands());
|
||||||
graphics->endRenderPass();
|
graphics->endRenderPass();
|
||||||
|
|||||||
@@ -265,6 +265,18 @@ UniformBuffer::~UniformBuffer()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UniformBuffer::updateContents(const BulkResourceData &resourceData)
|
||||||
|
{
|
||||||
|
if(!Gfx::UniformBuffer::updateContents(resourceData))
|
||||||
|
{
|
||||||
|
// no update was performed, skip
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
void* data = lock();
|
||||||
|
std::memcpy(data, resourceData.data, resourceData.size);
|
||||||
|
unlock();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
void* UniformBuffer::lock(bool bWriteOnly)
|
void* UniformBuffer::lock(bool bWriteOnly)
|
||||||
{
|
{
|
||||||
if(dedicatedStagingBuffer != nullptr)
|
if(dedicatedStagingBuffer != nullptr)
|
||||||
|
|||||||
@@ -92,11 +92,9 @@ void CmdBuffer::executeCommands(Array<Gfx::PRenderCommand> commands)
|
|||||||
{
|
{
|
||||||
auto command = commands[i].cast<SecondaryCmdBuffer>();
|
auto command = commands[i].cast<SecondaryCmdBuffer>();
|
||||||
// Cache array and size to save on pointer access
|
// Cache array and size to save on pointer access
|
||||||
DescriptorSet** boundDescriptors = command->boundDescriptors.data();
|
for(auto boundDescriptor : command->boundDescriptors)
|
||||||
size_t numDescriptors = command->boundDescriptors.size();
|
|
||||||
for(size_t i = 0; i < numDescriptors; ++i)
|
|
||||||
{
|
{
|
||||||
boundDescriptors[i]->currentlyBound = true;
|
boundDescriptor->currentlyBound = this;
|
||||||
}
|
}
|
||||||
command->end();
|
command->end();
|
||||||
executingCommands.add(command);
|
executingCommands.add(command);
|
||||||
@@ -182,11 +180,9 @@ void SecondaryCmdBuffer::end()
|
|||||||
void SecondaryCmdBuffer::reset()
|
void SecondaryCmdBuffer::reset()
|
||||||
{
|
{
|
||||||
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
||||||
size_t numBoundDescriptors = boundDescriptors.size();
|
for(auto boundDescriptor : boundDescriptors)
|
||||||
DescriptorSet** boundDescriptorSets = boundDescriptors.data();
|
|
||||||
for(size_t i = 0; i < numBoundDescriptors; ++i)
|
|
||||||
{
|
{
|
||||||
boundDescriptorSets[i]->currentlyBound = false;
|
boundDescriptor->currentlyBound = nullptr;
|
||||||
}
|
}
|
||||||
boundDescriptors.clear();
|
boundDescriptors.clear();
|
||||||
ready = true;
|
ready = true;
|
||||||
|
|||||||
@@ -116,16 +116,17 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
|
|||||||
{
|
{
|
||||||
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
|
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
|
||||||
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[Gfx::currentFrameIndex][binding]);
|
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||||
if(vulkanBuffer->isDataEquals(cachedBuffer))
|
/*if(vulkanBuffer->isDataEquals(cachedBuffer))
|
||||||
{
|
{
|
||||||
|
std::cout << "uniform data equal, skip" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
|
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
|
||||||
|
|
||||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding, &bufferInfos.back());
|
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding, &bufferInfos.back());
|
||||||
writeDescriptors.add(writeDescriptor);
|
writeDescriptors.add(writeDescriptor);
|
||||||
|
|
||||||
cachedData[Gfx::currentFrameIndex][binding] = vulkanBuffer.getHandle();
|
cachedData[Gfx::currentFrameIndex][binding] = new UniformBuffer(*vulkanBuffer.getHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer)
|
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer)
|
||||||
@@ -171,10 +172,8 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
|||||||
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[Gfx::currentFrameIndex][binding]);
|
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[Gfx::currentFrameIndex][binding]);
|
||||||
if(vulkanTexture == cachedTexture)
|
if(vulkanTexture == cachedTexture)
|
||||||
{
|
{
|
||||||
std::cout << "Cached texture is same as new one, skipping update" << std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout << "Texture changed, updating" << std::endl;
|
|
||||||
//It is assumed that the image is in the correct layout
|
//It is assumed that the image is in the correct layout
|
||||||
VkDescriptorImageInfo imageInfo =
|
VkDescriptorImageInfo imageInfo =
|
||||||
init::DescriptorImageInfo(
|
init::DescriptorImageInfo(
|
||||||
@@ -187,7 +186,12 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
|||||||
imageInfo.sampler = vulkanSampler->sampler;
|
imageInfo.sampler = vulkanSampler->sampler;
|
||||||
}
|
}
|
||||||
imageInfos.add(imageInfo);
|
imageInfos.add(imageInfo);
|
||||||
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], samplerState != nullptr ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, binding, &imageInfos.back());
|
VkWriteDescriptorSet writeDescriptor =
|
||||||
|
init::WriteDescriptorSet(
|
||||||
|
setHandle[Gfx::currentFrameIndex],
|
||||||
|
samplerState != nullptr ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||||
|
binding,
|
||||||
|
&imageInfos.back());
|
||||||
if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT)
|
if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT)
|
||||||
{
|
{
|
||||||
writeDescriptor.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
writeDescriptor.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
|
||||||
@@ -212,7 +216,11 @@ void DescriptorSet::writeChanges()
|
|||||||
{
|
{
|
||||||
if (writeDescriptors.size() > 0)
|
if (writeDescriptors.size() > 0)
|
||||||
{
|
{
|
||||||
assert(!isCurrentlyBound());
|
if(isCurrentlyBound())
|
||||||
|
{
|
||||||
|
graphics->getGraphicsCommands()->waitForCommands(currentlyBound);
|
||||||
|
currentlyBound = nullptr;
|
||||||
|
}
|
||||||
vkUpdateDescriptorSets(graphics->getDevice(), (uint32)writeDescriptors.size(), writeDescriptors.data(), 0, nullptr);
|
vkUpdateDescriptorSets(graphics->getDevice(), (uint32)writeDescriptors.size(), writeDescriptors.data(), 0, nullptr);
|
||||||
writeDescriptors.clear();
|
writeDescriptors.clear();
|
||||||
imageInfos.clear();
|
imageInfos.clear();
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
|
|
||||||
inline bool isCurrentlyBound() const
|
inline bool isCurrentlyBound() const
|
||||||
{
|
{
|
||||||
return currentlyBound;
|
return currentlyBound != nullptr;
|
||||||
}
|
}
|
||||||
inline bool isCurrentlyInUse() const
|
inline bool isCurrentlyInUse() const
|
||||||
{
|
{
|
||||||
@@ -90,8 +90,8 @@ public:
|
|||||||
virtual uint32 getSetIndex() const;
|
virtual uint32 getSetIndex() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Array<VkDescriptorImageInfo> imageInfos;
|
List<VkDescriptorImageInfo> imageInfos;
|
||||||
Array<VkDescriptorBufferInfo> bufferInfos;
|
List<VkDescriptorBufferInfo> bufferInfos;
|
||||||
Array<VkWriteDescriptorSet> writeDescriptors;
|
Array<VkWriteDescriptorSet> writeDescriptors;
|
||||||
// contains the previously bound resources at every binding
|
// contains the previously bound resources at every binding
|
||||||
// since the layout is fixed, trying to bind a texture to a buffer
|
// since the layout is fixed, trying to bind a texture to a buffer
|
||||||
@@ -100,7 +100,7 @@ private:
|
|||||||
VkDescriptorSet setHandle[Gfx::numFramesBuffered];
|
VkDescriptorSet setHandle[Gfx::numFramesBuffered];
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
PDescriptorAllocator owner;
|
PDescriptorAllocator owner;
|
||||||
bool currentlyBound;
|
PCmdBuffer currentlyBound;
|
||||||
bool currentlyInUse;
|
bool currentlyInUse;
|
||||||
friend class DescriptorAllocator;
|
friend class DescriptorAllocator;
|
||||||
friend class CmdBuffer;
|
friend class CmdBuffer;
|
||||||
|
|||||||
@@ -49,13 +49,6 @@ void QueueOwnedResourceDeletion::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UniformBuffer::updateContents(const BulkResourceData &resourceData)
|
|
||||||
{
|
|
||||||
Gfx::UniformBuffer::updateContents(resourceData);
|
|
||||||
void* data = lock();
|
|
||||||
std::memcpy(data, resourceData.data, resourceData.size);
|
|
||||||
unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
Semaphore::Semaphore(PGraphics graphics)
|
Semaphore::Semaphore(PGraphics graphics)
|
||||||
: graphics(graphics)
|
: graphics(graphics)
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class UniformBuffer : public Gfx::UniformBuffer, public ShaderBuffer
|
|||||||
public:
|
public:
|
||||||
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &resourceData);
|
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &resourceData);
|
||||||
virtual ~UniformBuffer();
|
virtual ~UniformBuffer();
|
||||||
virtual void updateContents(const BulkResourceData &resourceData);
|
virtual bool updateContents(const BulkResourceData &resourceData);
|
||||||
|
|
||||||
virtual void* lock(bool bWriteOnly = true) override;
|
virtual void* lock(bool bWriteOnly = true) override;
|
||||||
virtual void unlock() override;
|
virtual void unlock() override;
|
||||||
|
|||||||
@@ -213,6 +213,11 @@ void Window::present()
|
|||||||
presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info);
|
presentResult = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &info);
|
||||||
}
|
}
|
||||||
Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered;
|
Gfx::currentFrameIndex = (Gfx::currentFrameIndex + 1)%Gfx::numFramesBuffered;
|
||||||
|
static double lastFrameTime = 0.f;
|
||||||
|
double currentTime = glfwGetTime();
|
||||||
|
double currentDelta = currentTime - lastFrameTime;
|
||||||
|
Gfx::currentFrameDelta = currentDelta;
|
||||||
|
lastFrameTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::createSwapchain()
|
void Window::createSwapchain()
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ void Material::compile()
|
|||||||
{
|
{
|
||||||
p->data = AssetRegistry::findTexture(""); // this will return placeholder texture
|
p->data = AssetRegistry::findTexture(""); // this will return placeholder texture
|
||||||
}
|
}
|
||||||
|
assert(p->data != nullptr);
|
||||||
parameters.add(p);
|
parameters.add(p);
|
||||||
}
|
}
|
||||||
else if(type.compare("SamplerState") == 0)
|
else if(type.compare("SamplerState") == 0)
|
||||||
@@ -137,8 +138,6 @@ void Material::compile()
|
|||||||
uniformBuffer = WindowManager::getGraphics()->createUniformBuffer(uniformInitializer);
|
uniformBuffer = WindowManager::getGraphics()->createUniformBuffer(uniformInitializer);
|
||||||
}
|
}
|
||||||
layout->create();
|
layout->create();
|
||||||
descriptorSet = layout->allocatedDescriptorSet();
|
|
||||||
updateDescriptorData();
|
|
||||||
BRDF* brdf = BRDF::getBRDFByName(profile);
|
BRDF* brdf = BRDF::getBRDFByName(profile);
|
||||||
brdf->generateMaterialCode(codeStream, j["code"]);
|
brdf->generateMaterialCode(codeStream, j["code"]);
|
||||||
codeStream << "};";
|
codeStream << "};";
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ private:
|
|||||||
static std::mutex shaderMapLock;
|
static std::mutex shaderMapLock;
|
||||||
|
|
||||||
std::string materialName;
|
std::string materialName;
|
||||||
Gfx::PDescriptorLayout layout;
|
|
||||||
friend class MaterialLoader;
|
friend class MaterialLoader;
|
||||||
friend class MaterialInstance;
|
friend class MaterialInstance;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ void MaterialAsset::endFrame()
|
|||||||
|
|
||||||
void MaterialAsset::updateDescriptorData()
|
void MaterialAsset::updateDescriptorData()
|
||||||
{
|
{
|
||||||
|
layout->reset();
|
||||||
|
descriptorSet = layout->allocatedDescriptorSet();
|
||||||
BulkResourceData uniformUpdate;
|
BulkResourceData uniformUpdate;
|
||||||
uniformUpdate.size = uniformDataSize;
|
uniformUpdate.size = uniformDataSize;
|
||||||
uniformUpdate.data = uniformData;
|
uniformUpdate.data = uniformData;
|
||||||
|
|||||||
@@ -24,11 +24,14 @@ public:
|
|||||||
|
|
||||||
// This needs to be called while the descriptorset is unused
|
// This needs to be called while the descriptorset is unused
|
||||||
void updateDescriptorData();
|
void updateDescriptorData();
|
||||||
|
void resetDescriptorSet();
|
||||||
const Gfx::PDescriptorSet getDescriptor() const;
|
const Gfx::PDescriptorSet getDescriptor() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//For now its simply the collection of parameters, since there is no point for expressions
|
//For now its simply the collection of parameters, since there is no point for expressions
|
||||||
Array<PShaderParameter> parameters;
|
Array<PShaderParameter> parameters;
|
||||||
Gfx::PDescriptorSet descriptorSet;
|
Gfx::PDescriptorSet descriptorSet;
|
||||||
|
Gfx::PDescriptorLayout layout;
|
||||||
Gfx::PUniformBuffer uniformBuffer;
|
Gfx::PUniformBuffer uniformBuffer;
|
||||||
uint32 uniformDataSize;
|
uint32 uniformDataSize;
|
||||||
uint8* uniformData;
|
uint8* uniformData;
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ void MaterialInstance::load()
|
|||||||
uniformInitializer.resourceData.size = baseMaterial->uniformDataSize;
|
uniformInitializer.resourceData.size = baseMaterial->uniformDataSize;
|
||||||
uniformInitializer.resourceData.data = nullptr;
|
uniformInitializer.resourceData.data = nullptr;
|
||||||
uniformBuffer = WindowManager::getGraphics()->createUniformBuffer(uniformInitializer);
|
uniformBuffer = WindowManager::getGraphics()->createUniformBuffer(uniformInitializer);
|
||||||
descriptorSet = baseMaterial->layout->allocatedDescriptorSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Material* MaterialInstance::getRenderMaterial() const
|
const Material* MaterialInstance::getRenderMaterial() const
|
||||||
|
|||||||
@@ -3,6 +3,22 @@
|
|||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
|
std::ostream& Seele::operator<<(std::ostream& stream, const Vector2& vector)
|
||||||
|
{
|
||||||
|
stream << "(" << vector.x << ", " << vector.y << ")";
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
std::ostream& Seele::operator<<(std::ostream& stream, const Vector& vector)
|
||||||
|
{
|
||||||
|
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
std::ostream& Seele::operator<<(std::ostream& stream, const Vector4& vector)
|
||||||
|
{
|
||||||
|
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ", " << vector.w << ")";
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
Vector Seele::parseVector(const char* str)
|
Vector Seele::parseVector(const char* str)
|
||||||
{
|
{
|
||||||
//regex pattern consisting of 'float3(xComp, yComp, zComp)', more also matches for invalid floats, but that will throw later
|
//regex pattern consisting of 'float3(xComp, yComp, zComp)', more also matches for invalid floats, but that will throw later
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ typedef glm::quat Quaternion;
|
|||||||
|
|
||||||
Vector parseVector(const char*);
|
Vector parseVector(const char*);
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const Vector2& vector);
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const Vector& vector);
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const Vector4& vector);
|
||||||
|
|
||||||
static inline float square(float x)
|
static inline float square(float x)
|
||||||
{
|
{
|
||||||
return x * x;
|
return x * x;
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ public:
|
|||||||
RefObject(T *ptr)
|
RefObject(T *ptr)
|
||||||
: handle(ptr), refCount(1)
|
: handle(ptr), refCount(1)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(registeredObjectsLock);
|
|
||||||
registeredObjects[ptr] = this;
|
registeredObjects[ptr] = this;
|
||||||
}
|
}
|
||||||
inline RefObject(const RefObject &rhs)
|
inline RefObject(const RefObject &rhs)
|
||||||
@@ -54,7 +53,9 @@ public:
|
|||||||
std::scoped_lock lock(registeredObjectsLock);
|
std::scoped_lock lock(registeredObjectsLock);
|
||||||
registeredObjects.erase(handle);
|
registeredObjects.erase(handle);
|
||||||
}
|
}
|
||||||
|
#pragma warning( disable: 4150)
|
||||||
delete handle;
|
delete handle;
|
||||||
|
#pragma warning( default: 4150)
|
||||||
}
|
}
|
||||||
RefObject &operator=(const RefObject &rhs)
|
RefObject &operator=(const RefObject &rhs)
|
||||||
{
|
{
|
||||||
@@ -126,13 +127,16 @@ public:
|
|||||||
{
|
{
|
||||||
std::unique_lock l(registeredObjectsLock);
|
std::unique_lock l(registeredObjectsLock);
|
||||||
auto registeredObj = registeredObjects.find(ptr);
|
auto registeredObj = registeredObjects.find(ptr);
|
||||||
l.unlock();
|
// get here for thread safetly
|
||||||
if (registeredObj == registeredObjects.end())
|
auto registeredEnd = registeredObjects.end();
|
||||||
|
if (registeredObj == registeredEnd)
|
||||||
{
|
{
|
||||||
object = new RefObject<T>(ptr);
|
object = new RefObject<T>(ptr);
|
||||||
|
l.unlock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
l.unlock();
|
||||||
object = (RefObject<T> *)registeredObj->value;
|
object = (RefObject<T> *)registeredObj->value;
|
||||||
object->addRef();
|
object->addRef();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
target_sources(SeeleEngine
|
target_sources(SeeleEngine
|
||||||
PRIVATE
|
PRIVATE
|
||||||
Scene.cpp
|
Scene.cpp
|
||||||
Scene.h)
|
Scene.h
|
||||||
|
SceneUpdater.h
|
||||||
|
SceneUpdater.cpp)
|
||||||
|
|
||||||
add_subdirectory(Actor/)
|
add_subdirectory(Actor/)
|
||||||
add_subdirectory(Components/)
|
add_subdirectory(Components/)
|
||||||
@@ -11,7 +11,7 @@ Scene::Scene(Gfx::PGraphics graphics)
|
|||||||
: graphics(graphics)
|
: graphics(graphics)
|
||||||
{
|
{
|
||||||
lightEnv.directionalLights[0].color = Vector4(1, 0, 0, 1);
|
lightEnv.directionalLights[0].color = Vector4(1, 0, 0, 1);
|
||||||
lightEnv.directionalLights[0].direction = Vector4(1, 1, 0, 1);
|
lightEnv.directionalLights[0].direction = Vector4(0, 0, 0, 1);
|
||||||
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
|
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
|
||||||
lightEnv.numDirectionalLights = 1;
|
lightEnv.numDirectionalLights = 1;
|
||||||
lightEnv.numPointLights = 0;
|
lightEnv.numPointLights = 0;
|
||||||
@@ -22,11 +22,15 @@ Scene::~Scene()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::tick(float deltaTime)
|
void Scene::tick(double deltaTime)
|
||||||
{
|
{
|
||||||
|
lightEnv.directionalLights[0].direction.x += ((rand() / (double)RAND_MAX) - 0.5f) * 100.f * deltaTime;
|
||||||
|
lightEnv.directionalLights[0].direction.y += ((rand() / (double)RAND_MAX) - 0.5f) * 100.f * deltaTime;
|
||||||
|
lightEnv.directionalLights[0].direction.z += ((rand() / (double)RAND_MAX) - 0.5f) * 100.f * deltaTime;
|
||||||
|
std::cout << lightEnv.directionalLights[0].direction << std::endl;
|
||||||
for (auto actor : rootActors)
|
for (auto actor : rootActors)
|
||||||
{
|
{
|
||||||
actor->tick(deltaTime);
|
actor->tick(static_cast<float>(deltaTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +43,7 @@ void Scene::addActor(PActor actor)
|
|||||||
void Scene::addPrimitiveComponent(PPrimitiveComponent comp)
|
void Scene::addPrimitiveComponent(PPrimitiveComponent comp)
|
||||||
{
|
{
|
||||||
primitives.add(comp);
|
primitives.add(comp);
|
||||||
for(auto& batch : comp->staticMeshes)
|
for(auto& batch : comp->getStaticMeshes())
|
||||||
{
|
{
|
||||||
PrimitiveUniformBuffer data;
|
PrimitiveUniformBuffer data;
|
||||||
data.actorWorldPosition = Vector4(comp->getTransform().getPosition(), 1);
|
data.actorWorldPosition = Vector4(comp->getTransform().getPosition(), 1);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class Scene
|
|||||||
public:
|
public:
|
||||||
Scene(Gfx::PGraphics graphics);
|
Scene(Gfx::PGraphics graphics);
|
||||||
~Scene();
|
~Scene();
|
||||||
void tick(float deltaTime);
|
void tick(double deltaTime);
|
||||||
void addActor(PActor actor);
|
void addActor(PActor actor);
|
||||||
void addPrimitiveComponent(PPrimitiveComponent comp);
|
void addPrimitiveComponent(PPrimitiveComponent comp);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Containers/Array.h"
|
||||||
|
|
||||||
|
namespace Seele
|
||||||
|
{
|
||||||
|
class SceneUpdater
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SceneUpdater();
|
||||||
|
~SceneUpdater();
|
||||||
|
private:
|
||||||
|
Array<std::thread> workers;
|
||||||
|
List<std::function<void(float)> pendingUpdates;
|
||||||
|
void work();
|
||||||
|
};
|
||||||
|
} // namespace Seele
|
||||||
@@ -23,7 +23,7 @@ Seele::SceneView::~SceneView()
|
|||||||
void SceneView::beginFrame()
|
void SceneView::beginFrame()
|
||||||
{
|
{
|
||||||
View::beginFrame();
|
View::beginFrame();
|
||||||
scene->tick(0);//TODO: update in separate thread
|
scene->tick(Gfx::currentFrameDelta);//TODO: update in separate thread
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
|
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class SceneView : public View
|
|||||||
public:
|
public:
|
||||||
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
|
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
|
||||||
~SceneView();
|
~SceneView();
|
||||||
virtual void beginFrame();
|
virtual void beginFrame() override;
|
||||||
PScene getScene() const { return scene; }
|
PScene getScene() const { return scene; }
|
||||||
private:
|
private:
|
||||||
PScene scene;
|
PScene scene;
|
||||||
|
|||||||
@@ -66,4 +66,13 @@ BOOST_AUTO_TEST_CASE(custom_key)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(string_key)
|
||||||
|
{
|
||||||
|
std::map<std::string, int> map;
|
||||||
|
map["Test"] = 2;
|
||||||
|
map["Test2"] = 3;
|
||||||
|
BOOST_REQUIRE_EQUAL(map["Test"], 2);
|
||||||
|
BOOST_REQUIRE_EQUAL(map["Test2"], 3);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
Reference in New Issue
Block a user