Preparing for Writeup

This commit is contained in:
2021-10-15 23:12:29 +02:00
parent 2cb70d7b16
commit b1d8ef4120
40 changed files with 284 additions and 192 deletions
+5
View File
@@ -124,6 +124,11 @@ void AssetRegistry::registerMesh(PMeshAsset mesh)
}
}
void AssetRegistry::registerTexture(PTextureAsset texture)
{
textures[texture->getFileName()] = texture;
}
void AssetRegistry::registerMaterial(PMaterialAsset material)
{
materials[material->getFileName()] = material;
+5 -3
View File
@@ -86,8 +86,8 @@ void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterialAsset>& glob
outMatFile << std::setw(4) << matCode;
outMatFile.flush();
outMatFile.close();
//TODO: let the material loader handle this instead
//std::cout << matCode << std::endl;
std::cout << "writing json to " << outMatFilename << std::endl;
PMaterial result = new Material(outMatFilename);
result->compile();
graphics->getShaderCompiler()->registerMaterial(result);
@@ -225,12 +225,13 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
stbi_write_png(texPngPath.string().c_str(), tex->mWidth, tex->mHeight, 4, tex->pcData, tex->mWidth * 32);
delete texData;
}
std::cout << "Loading model texture " << texPngPath.string() << std::endl;
AssetRegistry::importFile(texPngPath.string());
}
}
void MeshLoader::import(PMeshAsset meshAsset, const std::filesystem::path &path)
{
std::cout << "Starting to import "<<path << std::endl;
meshAsset->setStatus(Asset::Status::Loading);
Assimp::Importer importer;
importer.ReadFile(path.string().c_str(),
@@ -262,4 +263,5 @@ void MeshLoader::import(PMeshAsset meshAsset, const std::filesystem::path &path)
}
meshAsset->setStatus(Asset::Status::Ready);
meshAsset->save();
std::cout << "Finished loading " << path << std::endl;
}
+2 -1
View File
@@ -33,7 +33,8 @@ void TextureAsset::load()
{
setStatus(Status::Loading);
ktxTexture2* kTexture;
KTX_error_code result = ktxTexture2_CreateFromNamedFile(getFullPath().c_str(),
// TODO: consider return
ktxTexture2_CreateFromNamedFile(getFullPath().c_str(),
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT,
&kTexture);
TextureCreateInfo createInfo;
+5 -5
View File
@@ -28,7 +28,8 @@ void TextureLoader::importAsset(const std::filesystem::path& filePath)
PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string());
asset->setStatus(Asset::Status::Loading);
asset->setTexture(placeholderAsset->getTexture());
AssetRegistry::get().textures[asset->getFileName()] = asset;
std::cout << "Loading texture " << asset->getFileName() << std::endl;
AssetRegistry::get().registerTexture(asset);
futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
using namespace std::chrono_literals;
//std::this_thread::sleep_for(5s);
@@ -49,7 +50,6 @@ void TextureLoader::import(const std::filesystem::path& path, PTextureAsset text
unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4);
ktxTexture2* kTexture;
ktxTextureCreateInfo createInfo;
KTX_error_code result;
createInfo.vkFormat = VK_FORMAT_R8G8B8A8_SRGB;
createInfo.baseWidth = x;
@@ -62,15 +62,15 @@ void TextureLoader::import(const std::filesystem::path& path, PTextureAsset text
createInfo.isArray = false;
createInfo.generateMipmaps = true;
result = ktxTexture2_Create(&createInfo,
ktxTexture2_Create(&createInfo,
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
&kTexture);
result = ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
0, 0, 0, data, x * y * 4 * sizeof(unsigned char));
stbi_image_free(data);
result = ktxTexture_WriteToNamedFile(ktxTexture(kTexture), textureAsset->getFullPath().c_str());
ktxTexture_WriteToNamedFile(ktxTexture(kTexture), textureAsset->getFullPath().c_str());
ktxTexture_Destroy(ktxTexture(kTexture));
}
+2 -2
View File
@@ -32,9 +32,9 @@ namespace Seele
Array(Init_t)
: arraySize(0)
, allocated(0)
, _data(nullptr)
, beginIt(Iterator(nullptr))
, endIt(Iterator(nullptr))
, _data(nullptr)
{
}
Array(size_t size, T value = T())
@@ -420,7 +420,7 @@ namespace Seele
}
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
void serialize(Archive& ar, const unsigned int)
{
ar & arraySize;
resize(arraySize);
+2 -2
View File
@@ -111,10 +111,10 @@ private:
public:
Map()
: root(nullptr)
, _size(0)
, iteratorsDirty(false)
, beginIt(nullptr)
, endIt(nullptr)
, iteratorsDirty(false)
, _size(0)
{
}
Map(const Map& other)
+1 -1
View File
@@ -162,7 +162,7 @@ typedef uint32 KeyModifierFlags;
namespace Gfx
{
static constexpr bool useAsyncCompute = true;
static constexpr bool waitIdleOnSubmit = true;
static constexpr bool waitIdleOnSubmit = false;
static constexpr uint32 numFramesBuffered = 8;
extern uint32 currentFrameIndex;
extern double currentFrameDelta;
@@ -26,8 +26,10 @@ void modifyRenderPassMacros(Gfx::RenderPassType type, Map<const char*, const cha
{
case Gfx::RenderPassType::DepthPrepass:
DepthPrepass::modifyRenderPassMacros(defines);
break;
case Gfx::RenderPassType::BasePass:
BasePass::modifyRenderPassMacros(defines);
break;
}
}
@@ -138,10 +138,10 @@ void DepthPrepass::render()
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
graphics->beginRenderPass(renderPass);
/*for (auto &&meshBatch : scene->getStaticMeshes())
for (auto &&meshBatch : passData.staticDrawList)
{
processor->addMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
}*/
}
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
}
@@ -232,7 +232,7 @@ void LightCullingPass::createRenderPass()
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH")->getTexture();
}
void LightCullingPass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
void LightCullingPass::modifyRenderPassMacros(Map<const char*, const char*>&)
{
}
@@ -304,7 +304,7 @@ ComputeCommand::~ComputeCommand()
{
}
void ComputeCommand::begin(PCmdBuffer parent)
void ComputeCommand::begin(PCmdBuffer)
{
ready = false;
VkCommandBufferBeginInfo beginInfo =
@@ -117,7 +117,7 @@ DescriptorSet::~DescriptorSet()
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer)
{
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[binding]);
//UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[binding]);
/*if(vulkanBuffer->isDataEquals(cachedBuffer))
{
std::cout << "uniform data equal, skip" << std::endl;
@@ -63,8 +63,8 @@ public:
: setHandle(VK_NULL_HANDLE)
, graphics(graphics)
, owner(owner)
, currentlyInUse(false)
, currentlyBound(false)
, currentlyInUse(false)
{
}
virtual ~DescriptorSet();
@@ -432,16 +432,19 @@ void Graphics::pickPhysicalDevice()
vkGetPhysicalDeviceFeatures(dev, &features);
if (props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
{
std::cout << "found dedicated gpu " << props.deviceName << std::endl;
currentRating += 100;
}
else if (props.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
{
std::cout << "found integrated gpu " << props.deviceName << std::endl;
currentRating += 10;
}
if (currentRating > deviceRating)
{
deviceRating = currentRating;
bestDevice = dev;
std::cout << "bestDevice: " << props.deviceName << std::endl;
}
}
physicalDevice = bestDevice;
@@ -765,8 +765,7 @@ VkPipelineShaderStageCreateInfo init::PipelineShaderStageCreateInfo(VkShaderStag
return info;
}
#pragma warning(disable : 4100)
VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char *layerPrefix, const char *msg, void *userDataManager)
VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT, uint64_t, size_t, int32_t, const char *layerPrefix, const char *msg, void *)
{
if(flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
{
@@ -778,7 +777,6 @@ VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT flags, VkDebugReport
return VK_FALSE;
}
}
#pragma warning(default : 4100)
VkResult Seele::Vulkan::CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback)
{
+2 -2
View File
@@ -2,7 +2,7 @@
#include "VulkanGraphics.h"
#include "VulkanDescriptorSets.h"
#include "slang.h"
//#include "spirv_cross/spirv_reflect.hpp"
#include "stdlib.h"
using namespace slang;
using namespace Seele;
@@ -55,7 +55,7 @@ static SlangStage getStageFromShaderType(ShaderType type)
void Shader::create(const ShaderCreateInfo& createInfo)
{
entryPointName = createInfo.entryPoint;
static SlangSession* session = spCreateSession(NULL);
static SlangSession* session = spCreateSession(nullptr);
SlangCompileRequest* request = spCreateCompileRequest(session);
int targetIndex = spAddCodeGenTarget(request, SLANG_SPIRV);
@@ -162,9 +162,9 @@ void Window::advanceBackBuffer()
imageAcquiredSemaphore = imageAcquired[semaphoreIndex];
currentImageIndex = imageIndex;
PCmdBuffer cmdBuffer = graphics->getGraphicsCommands()->getCommands();
backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
VkClearColorValue clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
PCmdBuffer cmdBuffer = graphics->getGraphicsCommands()->getCommands();
VkImageSubresourceRange range = init::ImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT);
vkCmdClearColorImage(
cmdBuffer->getHandle(),
+3 -2
View File
@@ -54,7 +54,6 @@ void Material::compile()
std::string profile = j["profile"].get<std::string>();
codeStream << "import VERTEX_INPUT_IMPORT;" << std::endl;
codeStream << "import LightEnv;" << std::endl;
codeStream << "import Material;" << std::endl;
codeStream << "import BRDF;" << std::endl;
codeStream << "import MaterialParameter;" << std::endl;
@@ -105,7 +104,9 @@ void Material::compile()
layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
if(defaultValue != param.value().end())
{
p->data = AssetRegistry::findTexture(defaultValue.value().get<std::string>());
std::string defaultString = defaultValue.value().get<std::string>();
std::cout << "Texture parameter " << defaultString << std::endl;
p->data = AssetRegistry::findTexture(defaultString);
}
else
{
+1 -1
View File
@@ -82,7 +82,7 @@ CombinedTextureParameter::~CombinedTextureParameter()
}
void CombinedTextureParameter::updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8* dst)
void CombinedTextureParameter::updateDescriptorSet(Gfx::PDescriptorSet descriptorSet, uint8*)
{
descriptorSet->updateTexture(binding, data->getTexture(), sampler);
}
+2 -2
View File
@@ -53,9 +53,9 @@ public:
std::scoped_lock lock(registeredObjectsLock);
registeredObjects.erase(handle);
}
#pragma warning( disable: 4150)
// #pragma warning( disable: 4150)
delete handle;
#pragma warning( default: 4150)
// #pragma warning( default: 4150)
}
RefObject &operator=(const RefObject &rhs)
{
@@ -6,8 +6,8 @@
using namespace Seele;
CameraComponent::CameraComponent()
: bNeedsProjectionBuild(true)
, bNeedsViewBuild(true)
: bNeedsViewBuild(true)
, bNeedsProjectionBuild(true)
, originPoint(0, 0, 0)
, cameraPosition(0, 0, 0)
{
+1 -1
View File
@@ -13,7 +13,7 @@ Component::Component()
Component::~Component()
{
}
void Component::tick(float deltaTime)
void Component::tick(float)
{
}
PComponent Component::getParent()
+5
View File
@@ -11,6 +11,11 @@ Element::~Element()
{
}
PElement Element::getParent() const
{
return parent;
}
void Element::addChild(PElement element)
{
children.add(element);
+3 -3
View File
@@ -5,7 +5,7 @@ using namespace Seele;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
: View(graphics, window, createInfo)
, renderGraph(UIPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle())))
, uiPass(UIPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle())))
{
}
@@ -13,7 +13,7 @@ InspectorView::~InspectorView()
{
}
void InspectorView::beginFrame()
void InspectorView::beginUpdate()
{
}
@@ -22,7 +22,7 @@ void InspectorView::update()
}
void InspectorView::endFrame()
void InspectorView::commitUpdate()
{
}
+3 -3
View File
@@ -13,15 +13,15 @@ public:
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~InspectorView();
virtual void beginFrame() override;
virtual void beginUpdate() override;
virtual void update() override;
virtual void endFrame() override;
virtual void commitUpdate() override;
virtual void prepareRender() override;
virtual void render() override;
void selectActor();
protected:
UIPass renderGraph;
UIPass uiPass;
UIPassData uiPassData;
+36 -3
View File
@@ -1,6 +1,7 @@
#include "SceneView.h"
#include "Scene/Scene.h"
#include "Window.h"
#include "Asset/AssetRegistry.h"
#include "Scene/Actor/CameraActor.h"
#include "Scene/Components/CameraComponent.h"
@@ -15,15 +16,39 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
{
scene = new Scene(graphics);
scene->addActor(activeCamera);
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx");
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
ayaka->addWorldTranslation(Vector(0, 0, 100));
ayaka->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
scene->addPrimitiveComponent(ayaka);
PRenderGraphResources resources = new RenderGraphResources();
depthPrepass.setResources(resources);
lightCullingPass.setResources(resources);
basePass.setResources(resources);
depthPrepass.publishOutputs();
lightCullingPass.publishOutputs();
basePass.publishOutputs();
depthPrepass.createRenderPass();
lightCullingPass.createRenderPass();
basePass.createRenderPass();
}
Seele::SceneView::~SceneView()
{
}
void SceneView::beginFrame()
void SceneView::beginUpdate()
{
View::beginFrame();
View::beginUpdate();
scene->tick(Gfx::currentFrameDelta);
}
@@ -31,7 +56,7 @@ void SceneView::update()
{
}
void SceneView::endFrame()
void SceneView::commitUpdate()
{
depthPrepassData.staticDrawList = scene->getStaticMeshes();
lightCullingPassData.lightEnv = scene->getLightBuffer();
@@ -47,9 +72,17 @@ void SceneView::prepareRender()
void SceneView::render()
{
depthPrepass.beginFrame();
lightCullingPass.beginFrame();
basePass.beginFrame();
depthPrepass.render();
lightCullingPass.render();
basePass.render();
depthPrepass.endFrame();
lightCullingPass.endFrame();
basePass.endFrame();
}
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
+2 -2
View File
@@ -13,9 +13,9 @@ class SceneView : public View
public:
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
~SceneView();
virtual void beginFrame() override;
virtual void beginUpdate() override;
virtual void update() override;
virtual void endFrame() override;
virtual void commitUpdate() override;
virtual void prepareRender() override;
virtual void render() override;
+1 -1
View File
@@ -14,7 +14,7 @@ View::~View()
{
}
void View::applyArea(URect area)
void View::applyArea(URect)
{
}
+2 -2
View File
@@ -12,10 +12,10 @@ public:
virtual ~View();
// These are called from the view thread, and handle updating game data
virtual void beginFrame() {}
virtual void beginUpdate() {}
virtual void update() {}
// End frame is called with a lock, so it is safe to write to shared memory
virtual void endFrame() {}
virtual void commitUpdate() {}
// These are called from the render thread
// prepare render is also locked, so reading from shared memory is also safe
+2 -2
View File
@@ -58,9 +58,9 @@ void Window::viewWorker(WindowView* windowView)
{
while(true)
{
windowView->view->beginFrame();
windowView->view->beginUpdate();
windowView->view->update();
std::lock_guard lock(windowView->workerMutex);
windowView->view->endFrame();
windowView->view->commitUpdate();
}
}
+1 -9
View File
@@ -9,6 +9,7 @@ using namespace Seele;
int main()
{
PWindowManager windowManager = new WindowManager();
AssetRegistry::init("/home/dynamitos/TestSeeleProject");
WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280;
@@ -33,15 +34,6 @@ int main()
PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo);
window->addView(inspectorView);
sceneView->setFocused();
AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject\\");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
plane->setWorldScale(Vector(100, 100, 100));
PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Ely"));
arissa->addWorldTranslation(Vector(0, 0, 100));
arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
while (windowManager->isActive())
{
windowManager->render();