First runnable render loop

This commit is contained in:
Dynamitos
2020-10-14 01:49:43 +02:00
parent ceee96b462
commit 8d4c43361b
35 changed files with 519 additions and 134 deletions
+9 -5
View File
@@ -45,6 +45,9 @@ find_package(assimp REQUIRED)
find_package(JSON REQUIRED)
find_package(GLFW REQUIRED)
find_package(SPIRV REQUIRED)
find_package(GLM REQUIRED)
find_package(STB REQUIRED)
find_package(SLang REQUIRED)
include_directories(${GLM_INCLUDE_DIRS})
include_directories(${STB_INCLUDE_DIRS})
@@ -58,18 +61,20 @@ include_directories(${JSON_INCLUDE_DIRS})
include_directories(${SPIRV_INCLUDE_DIRS})
include_directories(${ENGINE_ROOT})
include_directories(src/Engine)
add_definitions(${GLM_DEFINITIONS})
add_definitions(${Vulkan_DEFINITIONS})
add_definitions(${Boost_DEFINITIONS})
add_compile_definitions(GLFW_WINDOWS)
if(WIN32)
add_compile_definitions(USE_EXTENSIONS)
endif()
if(CMAKE_DEBUG_POSTFIX)
add_compile_definitions(ENABLE_VALIDATION)
endif()
add_executable(SeeleEngine "")
target_link_libraries(SeeleEngine ${Vulkan_LIBRARY})
target_link_libraries(SeeleEngine ${Boost_LIBRARIES})
target_link_libraries(SeeleEngine ${GLFW_LIBRARIES})
target_link_libraries(SeeleEngine ${SLANG_LIBRARY})
target_link_libraries(SeeleEngine ${SLANG_LIBRARIES})
target_link_libraries(SeeleEngine ${ASSIMP_LIBRARIES})
target_link_libraries(SeeleEngine ${JSON_LIBRARY})
target_link_libraries(SeeleEngine ${SPIRV_LIBRARIES})
@@ -105,8 +110,7 @@ add_subdirectory(test/)
add_custom_target(copy-runtime-files ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:SeeleEngine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_ROOT}/${SLANG_BINARY} $<TARGET_FILE_DIR:SeeleEngine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_ROOT}/${SLANG_GLSLANG} $<TARGET_FILE_DIR:SeeleEngine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_BINARY} $<TARGET_FILE_DIR:SeeleEngine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_GLSLANG} $<TARGET_FILE_DIR:SeeleEngine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GLFW_BINARY} $<TARGET_FILE_DIR:SeeleEngine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ASSIMP_BINARY} $<TARGET_FILE_DIR:SeeleEngine>
DEPENDS SeeleEngine)
+4 -1
View File
@@ -14,7 +14,10 @@
"release": {
"short": "Release",
"long": "Optimize binary for speed",
"buildType": "Release"
"buildType": "Release",
"settings": {
"CMAKE_DEBUG_POSTFIX": ""
}
}
}
},
+2 -22
View File
@@ -26,17 +26,10 @@ if (WIN32)
# Find library files
find_library(
ASSIMP_LIBRARY
NAMES assimp-vc${MSVC_TOOLSET_VERSION}-mt${CMAKE_DEBUG_POSTFIX}
NAMES assimp-vc${MSVC_TOOLSET_VERSION}-mt${CMAKE_DEBUG_POSTFIX}.lib
PATHS
$ENV{PROGRAMFILES}/lib
${ASSIMP_ROOT}/lib/)
find_file(
ASSIMP_BINARY
NAMES assimp-vc${MSVC_TOOLSET_VERSION}-mt${CMAKE_DEBUG_POSTFIX}.dll
PATHS
$ENV{PROGRAMFILES}/bin
${ASSIMP_ROOT}/bin/)
else()
# Find include files
find_path(
@@ -62,23 +55,10 @@ else()
/opt/local/lib
${ASSIMP_ROOT}/lib
DOC "The Assimp library")
find_file(
ASSIMP_BINARY
NAMES assimp.so
PATHS
/usr/bin64
/usr/bin
/usr/local/bin64
/usr/local/bin
/sw/bin
/opt/local/bin
${ASSIMP_ROOT}/lib
DOC "The Assimp binary")
endif()
# Handle REQUIRD argument, define *_FOUND variable
find_package_handle_standard_args(assimp DEFAULT_MSG ASSIMP_INCLUDE_DIR ASSIMP_LIBRARY ASSIMP_BINARY)
find_package_handle_standard_args(assimp DEFAULT_MSG ASSIMP_INCLUDE_DIR ASSIMP_LIBRARY)
# Define GLFW_LIBRARIES and GLFW_INCLUDE_DIRS
if (ASSIMP_FOUND)
+53
View File
@@ -0,0 +1,53 @@
#
# Find GLM
#
# Try to find GLM library.
# This module defines the following variables:
# - GLM_INCLUDE_DIRS
# - GLM_LIBRARIES
# - GLM_FOUND
#
# The following variables can be set as arguments for the module.
# - GLM_ROOT : Root library directory of GLM
# - GLM_USE_STATIC_LIBS : Specifies to use static version of GLM library (Windows only)
#
# References:
# - https://github.com/progschj/OpenGL-Examples/blob/master/cmake_modules/FindGLM.cmake
# - https://bitbucket.org/Ident8/cegui-mk2-opengl3-renderer/src/befd47200265/cmake/FindGLM.cmake
#
# Additional modules
include(FindPackageHandleStandardArgs)
if (WIN32)
# Find include files
find_path(
GLM_INCLUDE_DIR
NAMES GLM/glm.hpp
PATHS
$ENV{PROGRAMFILES}/include
${GLM_ROOT}
DOC "The directory where GLM/glm.h resides")
else()
# Find include files
find_path(
GLM_INCLUDE_DIR
NAMES GLM/glfw.h
PATHS
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where GLM/glm.h resides")
endif()
# Handle REQUIRD argument, define *_FOUND variable
find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIR)
# Define GLM_LIBRARIES and GLM_INCLUDE_DIRS
if (GLM_FOUND)
set(GLM_INCLUDE_DIRS ${GLM_INCLUDE_DIR})
endif()
# Hide some variables
mark_as_advanced(GLM_INCLUDE_DIR)
+103
View File
@@ -0,0 +1,103 @@
#
# Find SLANG
#
# Try to find SLANG library.
# This module defines the following variables:
# - SLANG_INCLUDE_DIRS
# - SLANG_LIBRARIES
# - SLANG_FOUND
#
# The following variables can be set as arguments for the module.
# - SLANG_ROOT : Root library directory of SLANG
#
# References:
# - https://github.com/progschj/OpenGL-Examples/blob/master/cmake_modules/FindSLANG.cmake
# - https://bitbucket.org/Ident8/cegui-mk2-opengl3-renderer/src/befd47200265/cmake/FindSLANG.cmake
#
# Additional modules
include(FindPackageHandleStandardArgs)
if (WIN32)
set(SLANG_BINARY_PATH ${SLANG_ROOT}/bin/windows-${CMAKE_PLATFORM}/release/)
# Find include files
find_path(
SLANG_INCLUDE_DIR
NAMES slang.h
PATHS
$ENV{PROGRAMFILES}/include
${SLANG_ROOT}
DOC "The directory where SLANG/slang.h resides")
# Find library files
find_library(
SLANG_LIBRARY
NAMES slang.lib
PATHS
$ENV{PROGRAMFILES}/lib
${SLANG_BINARY_PATH})
find_file(
SLANG_BINARY
NAMES slang.dll
PATHS
${SLANG_BINARY_PATH})
find_file(
SLANG_GLSLANG
NAMES slang-glslang.dll
PATHS
${SLANG_BINARY_PATH})
else()
# Find include files
find_path(
SLANG_INCLUDE_DIR
NAMES slang.h
PATHS
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where GL/glfw.h resides")
# Find library files
# Try to use static libraries
find_library(
SLANG_LIBRARY
NAMES slang.a
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
${SLANG_ROOT}/lib
DOC "The SLANG library")
find_file(
SLANG_BINARY
NAMES slang.so
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
${SLANG_ROOT}/lib
)
endif()
# Handle REQUIRD argument, define *_FOUND variable
find_package_handle_standard_args(SLANG DEFAULT_MSG SLANG_INCLUDE_DIR SLANG_LIBRARY SLANG_BINARY SLANG_GLSLANG)
# Define SLANG_LIBRARIES and SLANG_INCLUDE_DIRS
if (SLANG_FOUND)
set(SLANG_BINARIES ${SLANG_BINARY} ${SLANG_GLSLANG})
set(SLANG_LIBRARIES ${SLANG_LIBRARY})
set(SLANG_INCLUDE_DIRS ${SLANG_INCLUDE_DIR})
endif()
# Hide some variables
mark_as_advanced(SLANG_INCLUDE_DIR SLANG_LIBRARY SLANG_GLSLANG SLANG_BINARY)
+53
View File
@@ -0,0 +1,53 @@
#
# Find STB
#
# Try to find STB library.
# This module defines the following variables:
# - STB_INCLUDE_DIRS
# - STB_LIBRARIES
# - STB_FOUND
#
# The following variables can be set as arguments for the module.
# - STB_ROOT : Root library directory of STB
# - STB_USE_STATIC_LIBS : Specifies to use static version of STB library (Windows only)
#
# References:
# - https://github.com/progschj/OpenGL-Examples/blob/master/cmake_modules/FindSTB.cmake
# - https://bitbucket.org/Ident8/cegui-mk2-opengl3-renderer/src/befd47200265/cmake/FindSTB.cmake
#
# Additional modules
include(FindPackageHandleStandardArgs)
if (WIN32)
# Find include files
find_path(
STB_INCLUDE_DIR
NAMES stb.h
PATHS
$ENV{PROGRAMFILES}/include
${STB_ROOT}
DOC "The directory where STB/stb.h resides")
else()
# Find include files
find_path(
STB_INCLUDE_DIR
NAMES stb.h
PATHS
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where STB/stb.h resides")
endif()
# Handle REQUIRD argument, define *_FOUND variable
find_package_handle_standard_args(STB DEFAULT_MSG STB_INCLUDE_DIR)
# Define STB_LIBRARIES and STB_INCLUDE_DIRS
if (STB_FOUND)
set(STB_INCLUDE_DIRS ${STB_INCLUDE_DIR})
endif()
# Hide some variables
mark_as_advanced(STB_INCLUDE_DIR)
+3 -28
View File
@@ -7,8 +7,9 @@ list(APPEND DEPENDENCIES assimp)
set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "")
set(ASSIMP_BUILD_ASSIMP_TOOLS OFF CACHE INTERNAL "")
set(ASSIMP_INSTALL OFF CACHE INTERNAL "")
set(BUILD_SHARED_LIBS ON CACHE INTERNAL "")
add_subdirectory(${ASSIMP_ROOT} ${})
add_subdirectory(${ASSIMP_ROOT} ${ASSIMP_ROOT})
target_compile_definitions(assimp PRIVATE _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
#-------------BOOST----------------
@@ -29,25 +30,13 @@ ExternalProject_Add(boost
list (APPEND EXTRA_CMAKE_ARGS
-DBoost_NO_SYSTEM_PATHS=ON)
#----------------GLM-----------------------
list(APPEND DEPENDENCIES glm)
ExternalProject_Add(glm
SOURCE_DIR ${GLM_ROOT}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND "")
list(APPEND EXTRA_CMAKE_ARGS
-DGLM_INCLUDE_DIRS=${GLM_ROOT}
)
#--------------------JSON------------------
list(APPEND DEPENDENCIES nlohmann_json)
set(JSON_MultipleHeaders ON CACHE INTERNAL "")
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install OFF CACHE INTERNAL "")
add_subdirectory(${JSON_ROOT})
add_subdirectory(${JSON_ROOT} ${JSON_ROOT})
#--------------GLFW------------------------------
list(APPEND DEPENDENCIES glfw)
@@ -59,10 +48,6 @@ set(GLFW_BUILD_INSTALL OFF CACHE BOOL "GLFW lib only" )
add_subdirectory(${GLFW_ROOT} ${GLFW_ROOT})
#---------------STB_IMAGE------------------------
list(APPEND EXTRA_CMAKE_ARGS
-DSTB_INCLUDE_DIRS=${STB_ROOT})
#--------------SLang------------------------------
list(APPEND DEPENDENCIES slang)
string(TOLOWER release_${CMAKE_PLATFORM} SLANG_CONFIG)
@@ -74,9 +59,6 @@ ExternalProject_Add(slang
BUILD_COMMAND msbuild -p:Configuration=Release -p:WarningLevel=0 -p:Platform=${CMAKE_PLATFORM} -p:WindowsTargetPlatformVersion=10.0 ${SLANG_ROOT}/source/slang/slang.vcxproj
INSTALL_COMMAND "")
string(TOLOWER bin/windows-${CMAKE_PLATFORM}/Release/slang.dll SLANG_BINARY)
string(TOLOWER bin/windows-${CMAKE_PLATFORM}/Release/slang-glslang.dll SLANG_GLSLANG)
string(TOLOWER bin/windows-${CMAKE_PLATFORM}/Release/slang.lib SLANG_LIB_PATH)
set(SLANG_LIB_PATH ${SLANG_ROOT}/${SLANG_LIB_PATH})
elseif(UNIX)
ExternalProject_Add(slang
@@ -91,13 +73,6 @@ ExternalProject_Add(slang
set(SLANG_LIB_PATH)
endif()
list(APPEND EXTRA_CMAKE_ARGS
-DSLANG_INCLUDE_DIRS=${EXTERNAL_ROOT}/slang
-DSLANG_LIBRARY=${SLANG_LIB_PATH}
-DSLANG_BINARY=${SLANG_BINARY}
-DSLANG_GLSLANG=${SLANG_GLSLANG})
#----------------SPIR-V-CROSS--------------------
list(APPEND DEPENDENCIES spirv-cross-reflect)
set(SPIRV_CROSS_ENABLE_HLSL OFF CACHE BOOL "")
+2 -2
View File
@@ -146,7 +146,7 @@ VertexStreamComponent createVertexStream(uint32 size, aiVector2D* sourceData, Gf
Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo);
return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT);
}
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PMaterialAsset> materials, Gfx::PGraphics graphics)
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics)
{
for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
{
@@ -176,7 +176,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMesh
{
//data.colorComponent = createVertexStream(mesh->mNumVertices, mesh->mColors[0], graphics);
}
vertexShaderInput->setData(data);
vertexShaderInput->setData(std::move(data));
vertexShaderInput->init(graphics);
Array<uint32> indices(mesh->mNumFaces * 3);
+1 -1
View File
@@ -22,7 +22,7 @@ public:
private:
void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics);
void loadTextures(const aiScene* scene, Gfx::PGraphics graphics, const std::filesystem::path& meshPath);
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, Array<PMaterialAsset> materials, Gfx::PGraphics graphics);
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics);
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
void import(const std::filesystem::path& path);
+5 -4
View File
@@ -54,8 +54,8 @@ namespace Seele
{
_data = new T[other.allocated];
assert(_data != nullptr);
std::memcpy(_data, other._data, sizeof(T) * allocated);
refreshIterators();
std::copy(other.begin(), other.end(), beginIt);
}
Array(Array &&other) noexcept
: allocated(std::move(other.allocated)), arraySize(std::move(other.arraySize))
@@ -68,7 +68,7 @@ namespace Seele
}
Array &operator=(const Array &other) noexcept
{
if (*this != other)
if (this != &other)
{
if (_data != nullptr)
{
@@ -77,14 +77,14 @@ namespace Seele
allocated = other.allocated;
arraySize = other.arraySize;
_data = new T[other.allocated];
std::memcpy(_data, other._data, sizeof(T) * allocated);
refreshIterators();
std::copy(other.begin(), other.end(), beginIt);
}
return *this;
}
Array &operator=(Array &&other) noexcept
{
if (*this != other)
if (this != &other)
{
if (_data != nullptr)
{
@@ -94,6 +94,7 @@ namespace Seele
arraySize = std::move(other.arraySize);
_data = other._data;
other._data = nullptr;
refreshIterators();
}
return *this;
}
+92 -9
View File
@@ -20,12 +20,64 @@ public:
tail = nullptr;
beginIt = Iterator(root);
endIt = Iterator(tail);
size = 0;
_size = 0;
}
List(const List& other)
{
//TODO: improve
for(const auto& it : other)
{
add(it);
}
}
List(List&& other)
: root(std::move(other.root))
, tail(std::move(other.tail))
, beginIt(std::move(other.beginIt))
, endIt(std::move(other.endIt))
, _size(std::move(other._size))
{
}
~List()
{
clear();
}
List& operator=(const List& other)
{
if(this != &other)
{
if(root != nullptr)
{
delete root;
}
if(tail != nullptr)
{
delete tail;
}
_size = 0;
for(const auto& it : other)
{
add(it);
}
}
return *this;
}
List& operator=(List&& other)
{
if(this != &other)
{
if(root != nullptr)
{
clear();
}
root = other.root;
tail = other.tail;
beginIt = other.beginIt;
endIt = other.endIt;
_size = other._size;
}
return *this;
}
template <typename X>
class IteratorBase
{
@@ -44,6 +96,29 @@ public:
: node(i.node)
{
}
IteratorBase(IteratorBase&& i)
: node(std::move(i.node))
{
}
~IteratorBase()
{
}
IteratorBase& operator=(const IteratorBase& other)
{
if(this != &other)
{
node = other.node;
}
return *this;
}
IteratorBase& operator=(IteratorBase&& other)
{
if(this != &other)
{
node = std::move(other.node);
}
return *this;
}
reference operator*() const
{
return node->data;
@@ -129,7 +204,7 @@ public:
Iterator insertedElement(tail);
tail = newTail;
refreshIterators();
size++;
_size++;
return insertedElement;
}
Iterator add(T&& value)
@@ -147,12 +222,12 @@ public:
Iterator insertedElement(tail);
tail = newTail;
refreshIterators();
size++;
_size++;
return insertedElement;
}
Iterator remove(Iterator pos)
{
size--;
_size--;
Node *prev = pos.node->prev;
Node *next = pos.node->next;
if (prev == nullptr)
@@ -177,7 +252,7 @@ public:
}
Iterator insert(Iterator pos, const T &value)
{
size++;
_size++;
if (root == nullptr)
{
root = new Node();
@@ -212,20 +287,28 @@ public:
}
bool empty()
{
return size == 0;
return _size == 0;
}
uint32 length()
uint32 size()
{
return size;
return _size;
}
Iterator begin()
{
return beginIt;
}
const Iterator begin() const
{
return beginIt;
}
Iterator end()
{
return endIt;
}
const Iterator end() const
{
return endIt;
}
private:
void refreshIterators()
@@ -237,6 +320,6 @@ private:
Node *tail;
Iterator beginIt;
Iterator endIt;
uint32 size;
uint32 _size;
};
} // namespace Seele
+117 -2
View File
@@ -27,12 +27,28 @@ private:
Pair<K, V> pair;
Node *leftChild;
Node *rightChild;
Node()
: leftChild(nullptr), rightChild(nullptr), pair(K(), V())
{
}
Node(const K &key)
: leftChild(nullptr), rightChild(nullptr), pair(key, V())
{
}
Node()
: leftChild(nullptr), rightChild(nullptr), pair(K(), V())
Node(const Node& other)
: pair(other.pair.key, other.pair.value)
{
if(other.leftChild != nullptr)
{
leftChild = new Node(*other.leftChild);
}
if(other.rightChild != nullptr)
{
rightChild = new Node(*other.rightChild);
}
}
Node(Node&& other)
: leftChild(std::move(other.leftChild)), rightChild(std::move(other.rightChild))
{
}
~Node()
@@ -46,6 +62,45 @@ private:
delete rightChild;
}
}
Node& operator=(const Node& other)
{
if(this != &other)
{
if(leftChild != nullptr)
{
delete leftChild;
}
if(rightChild != nullptr)
{
delete rightChild;
}
if(other.leftChild != nullptr)
{
leftChild = new Node(*other.leftChild);
}
if(other.rightChild != nullptr)
{
rightChild = new Node(*other.rightChild);
}
}
}
Node& operator=(Node&& other)
{
if(this != &other)
{
if(leftChild != nullptr)
{
delete leftChild;
}
if(rightChild != nullptr)
{
delete rightChild;
}
leftChild = std::move(other.leftChild);
rightChild = std::move(other.rightChild);
}
return *this;
}
};
public:
@@ -53,10 +108,48 @@ public:
: root(nullptr), _size(0)
{
}
Map(const Map& other)
: root(new Node(*other.root)), _size(other._size)
{
refreshIterators();
}
Map(Map&& other)
: root(std::move(other.root)), _size(other._size)
{
refreshIterators();
}
~Map()
{
delete root;
}
Map& operator=(const Map& other)
{
if(this != &other)
{
if(root != nullptr)
{
delete root;
}
root = new Node(*other.root);
_size = other.size;
refreshIterators();
}
return *this;
}
Map& operator=(Map&& other)
{
if(this != &other)
{
if(root != nullptr)
{
delete root;
}
root = new Node(std::move(*other.root));
_size = std::move(other._size);
refreshIterators();
}
return *this;
}
class Iterator
{
public:
@@ -78,6 +171,28 @@ public:
: node(i.node), traversal(i.traversal)
{
}
Iterator(Iterator&& i)
: node(std::move(i.node)), traversal(std::move(i.traversal))
{
}
Iterator& operator=(const Iterator& other)
{
if(this != &other)
{
node = other.node; // No copy, since no ownership
traversal = other.traversal;
}
return *this;
}
Iterator& operator=(Iterator&& other)
{
if(this != &other)
{
node = std::move(other.node);
traversal = std::move(other.traversal);
}
return *this;
}
reference operator*() const
{
return node->pair;
+3 -3
View File
@@ -6,9 +6,9 @@
#include "MeshBatch.h"
#include <boost/crc.hpp>
#define ENABLE_VALIDATION
#ifdef DEBUG
#ifndef ENABLE_VALIDATION
#define ENABLE_VALIDATION 0
#endif
namespace Seele
@@ -483,7 +483,7 @@ public:
virtual void setViewport(Gfx::PViewport viewport) = 0;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0;
virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
virtual void bindDescriptor(Array<Gfx::PDescriptorSet> sets) = 0;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) = 0;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
virtual void draw(const MeshBatchElement& data) = 0;
+4 -5
View File
@@ -10,6 +10,7 @@ BasePassMeshProcessor::BasePassMeshProcessor(const PScene scene, Gfx::PViewport
: MeshProcessor(scene, graphics)
, target(viewport)
, translucentBasePass(translucentBasePass)
, cachedPrimitiveIndex(0)
{
}
@@ -23,7 +24,7 @@ void BasePassMeshProcessor::addMeshBatch(
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets,
Array<Gfx::PDescriptorSet>& descriptorSets,
int32 staticMeshId)
{
const PMaterialAsset material = batch.material;
@@ -42,13 +43,12 @@ void BasePassMeshProcessor::addMeshBatch(
}
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
renderCommand->setViewport(target);
uint32 primitiveDescriptorIndex = 0;
for(uint32 i = 0; i < batch.elements.size(); ++i)
{
pipelineLayout->addDescriptorLayout(2, material->getRenderMaterial()->getDescriptorLayout());
pipelineLayout->create();
descriptorSets[2] = material->getDescriptor();
descriptorSets[3] = cachedPrimitiveSets[primitiveDescriptorIndex++];
descriptorSets[3] = cachedPrimitiveSets[cachedPrimitiveIndex++];
buildMeshDrawCommand(batch,
// primitiveComponent,
renderPass,
@@ -74,6 +74,7 @@ void BasePassMeshProcessor::clearCommands()
{
renderCommands.clear();
cachedPrimitiveSets.clear();
cachedPrimitiveIndex = 0;
}
BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
@@ -140,7 +141,6 @@ void BasePass::beginFrame()
uniformUpdate.size = sizeof(LightEnv);
uniformUpdate.data = (uint8*)&scene->getLightEnvironment();
lightUniform->updateContents(uniformUpdate);
descriptorSets[0]->beginFrame();
descriptorSets[0]->updateBuffer(0, lightUniform);
descriptorSets[0]->writeChanges();
@@ -155,7 +155,6 @@ void BasePass::beginFrame()
uniformUpdate.size = sizeof(ScreenToViewParameter);
uniformUpdate.data = (uint8*)&screenToViewParams;
screenToViewParamBuffer->updateContents(uniformUpdate);
descriptorSets[1]->beginFrame();
descriptorSets[1]->updateBuffer(0, viewParamBuffer);
descriptorSets[1]->updateBuffer(1, screenToViewParamBuffer);
descriptorSets[1]->writeChanges();
+2 -1
View File
@@ -16,13 +16,14 @@ public:
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets,
Array<Gfx::PDescriptorSet>& descriptorSets,
int32 staticMeshId = -1) override;
Array<Gfx::PRenderCommand> getRenderCommands();
void clearCommands();
private:
Array<Gfx::PRenderCommand> renderCommands;
Array<Gfx::PDescriptorSet> cachedPrimitiveSets;
uint32 cachedPrimitiveIndex;
Gfx::PViewport target;
uint8 translucentBasePass;
};
@@ -21,7 +21,7 @@ void MeshProcessor::buildMeshDrawCommand(
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PRenderCommand drawCommand,
Array<Gfx::PDescriptorSet> descriptors,
const Array<Gfx::PDescriptorSet>& descriptors,
Gfx::PVertexShader vertexShader,
Gfx::PControlShader controlShader,
Gfx::PEvaluationShader evaluationShader,
@@ -20,7 +20,7 @@ protected:
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets,
Array<Gfx::PDescriptorSet>& descriptorSets,
int32 staticMeshId = -1) = 0;
void buildMeshDrawCommand(
const MeshBatch& meshBatch,
@@ -28,7 +28,7 @@ protected:
const Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PRenderCommand drawCommand,
Array<Gfx::PDescriptorSet> descriptors,
const Array<Gfx::PDescriptorSet>& descriptors,
Gfx::PVertexShader vertexShader,
Gfx::PControlShader controlShader,
Gfx::PEvaluationShader evaluationShader,
@@ -61,9 +61,9 @@ void StaticMeshVertexInput::init(Gfx::PGraphics graphics)
initDeclaration(graphics, elements);
}
void StaticMeshVertexInput::setData(StaticMeshDataType data)
void StaticMeshVertexInput::setData(StaticMeshDataType&& data)
{
this->data = data;
this->data = std::move(data);
}
IMPLEMENT_VERTEX_INPUT_TYPE(StaticMeshVertexInput, "StaticMeshVertexInput");
+1 -1
View File
@@ -21,7 +21,7 @@ public:
StaticMeshVertexInput(std::string name);
virtual ~StaticMeshVertexInput();
virtual void init(Gfx::PGraphics graphics) override;
void setData(StaticMeshDataType data);
void setData(StaticMeshDataType&& data);
private:
StaticMeshDataType data;
};
@@ -177,7 +177,7 @@ void SecondaryCmdBuffer::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
VkDescriptorSet setHandle = descriptorSet.cast<DescriptorSet>()->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
}
void SecondaryCmdBuffer::bindDescriptor(Array<Gfx::PDescriptorSet> descriptorSets)
void SecondaryCmdBuffer::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets)
{
VkDescriptorSet* sets = new VkDescriptorSet[descriptorSets.size()];
for(uint32 i = 0; i < descriptorSets.size(); ++i)
@@ -80,7 +80,7 @@ public:
virtual void setViewport(Gfx::PViewport viewport) override;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
virtual void bindDescriptor(Array<Gfx::PDescriptorSet> descriptorSets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) override;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
virtual void draw(const MeshBatchElement& data) override;
@@ -41,8 +41,6 @@ void DescriptorLayout::create()
init::DescriptorSetLayoutCreateInfo(bindings.data(), bindings.size());
VK_CHECK(vkCreateDescriptorSetLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
std::cout << "creating descriptorlayout " << layoutHandle << std::endl;
allocator = new DescriptorAllocator(graphics, *this);
boost::crc_32_type result;
@@ -115,7 +113,6 @@ DescriptorSet::~DescriptorSet()
void DescriptorSet::beginFrame()
{
currentFrameSet = (currentFrameSet + 1) % Gfx::numFramesBuffered;
}
void DescriptorSet::endFrame()
@@ -125,41 +122,39 @@ void DescriptorSet::endFrame()
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer)
{
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[currentFrameSet][binding]);
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[Gfx::currentFrameIndex][binding]);
if(vulkanBuffer->isDataEquals(cachedBuffer))
{
return;
}
VkDescriptorBufferInfo bufferInfo = init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize());
bufferInfos.add(bufferInfo);
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], 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);
cachedData[currentFrameSet][binding] = vulkanBuffer.getHandle();
cachedData[Gfx::currentFrameIndex][binding] = vulkanBuffer.getHandle();
}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer)
{
PStructuredBuffer vulkanBuffer = uniformBuffer.cast<StructuredBuffer>();
StructuredBuffer* cachedBuffer = reinterpret_cast<StructuredBuffer*>(cachedData[currentFrameSet][binding]);
StructuredBuffer* cachedBuffer = reinterpret_cast<StructuredBuffer*>(cachedData[Gfx::currentFrameIndex][binding]);
if(vulkanBuffer.getHandle() == cachedBuffer)
{
return;
}
VkDescriptorBufferInfo bufferInfo = init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize());
bufferInfos.add(bufferInfo);
bufferInfos.add(init::DescriptorBufferInfo(vulkanBuffer->getHandle(), 0, vulkanBuffer->getSize()));
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, binding, &bufferInfos.back());
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, binding, &bufferInfos.back());
writeDescriptors.add(writeDescriptor);
cachedData[currentFrameSet][binding] = vulkanBuffer.getHandle();
cachedData[Gfx::currentFrameIndex][binding] = vulkanBuffer.getHandle();
}
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSamplerState samplerState)
{
PSamplerState vulkanSampler = samplerState.cast<SamplerState>();
SamplerState* cachedSampler = reinterpret_cast<SamplerState*>(cachedData[currentFrameSet][binding]);
SamplerState* cachedSampler = reinterpret_cast<SamplerState*>(cachedData[Gfx::currentFrameIndex][binding]);
if(vulkanSampler.getHandle() == cachedSampler)
{
return;
@@ -171,16 +166,16 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSamplerState samplerSt
VK_IMAGE_LAYOUT_UNDEFINED);
imageInfos.add(imageInfo);
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], VK_DESCRIPTOR_TYPE_SAMPLER, binding, &imageInfos.back());
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[Gfx::currentFrameIndex], VK_DESCRIPTOR_TYPE_SAMPLER, binding, &imageInfos.back());
writeDescriptors.add(writeDescriptor);
cachedData[currentFrameSet][binding] = vulkanSampler.getHandle();
cachedData[Gfx::currentFrameIndex][binding] = vulkanSampler.getHandle();
}
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState samplerState)
{
TextureHandle* vulkanTexture = TextureBase::cast(texture);
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[currentFrameSet][binding]);
TextureHandle* cachedTexture = reinterpret_cast<TextureHandle*>(cachedData[Gfx::currentFrameIndex][binding]);
if(vulkanTexture == cachedTexture)
{
return;
@@ -197,14 +192,14 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
imageInfo.sampler = vulkanSampler->sampler;
}
imageInfos.add(imageInfo);
VkWriteDescriptorSet writeDescriptor = init::WriteDescriptorSet(setHandle[currentFrameSet], 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)
{
writeDescriptor.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
}
writeDescriptors.add(writeDescriptor);
cachedData[currentFrameSet][binding] = vulkanTexture;
cachedData[Gfx::currentFrameIndex][binding] = vulkanTexture;
}
bool DescriptorSet::operator<(Gfx::PDescriptorSet other)
@@ -64,7 +64,7 @@ public:
{
return poolHandle;
}
inline DescriptorLayout getLayout() const
inline DescriptorLayout& getLayout() const
{
return layout;
}
@@ -83,7 +83,7 @@ class DescriptorSet : public Gfx::DescriptorSet
{
public:
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
: graphics(graphics), owner(owner), currentFrameSet(0)
: graphics(graphics), owner(owner)
{
}
virtual ~DescriptorSet();
@@ -97,7 +97,7 @@ public:
virtual bool operator<(Gfx::PDescriptorSet other);
inline VkDescriptorSet getHandle() const
{
return setHandle[currentFrameSet];
return setHandle[Gfx::currentFrameIndex];
}
virtual uint32 getSetIndex() const
{
@@ -113,7 +113,6 @@ private:
// would not work anyways, so casts should be safe
Array<void*> cachedData[Gfx::numFramesBuffered];
VkDescriptorSet setHandle[Gfx::numFramesBuffered];
uint32 currentFrameSet;
PDescriptorAllocator owner;
PGraphics graphics;
friend class DescriptorAllocator;
@@ -282,7 +282,8 @@ Array<const char *> Graphics::getRequiredExtensions()
{
extensions.add(glfwExtensions[i]);
}
#ifdef ENABLE_VALIDATION
std::cout << ENABLE_VALIDATION << std::endl;
#if ENABLE_VALIDATION
extensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
#endif // ENABLE_VALIDATION
return extensions;
@@ -308,7 +309,7 @@ void Graphics::initInstance(GraphicsInitializer initInfo)
}
info.enabledExtensionCount = (uint32)extensions.size();
info.ppEnabledExtensionNames = extensions.data();
#ifdef ENABLE_VALIDATION
#if ENABLE_VALIDATION
info.enabledLayerCount = (uint32)initInfo.layers.size();
info.ppEnabledLayerNames = initInfo.layers.data();
#else
@@ -55,6 +55,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
createInfo.stageCount = 0;
VkPipelineTessellationStateCreateInfo tessInfo;
std::memset(&tessInfo, 0, sizeof(VkPipelineTessellationStateCreateInfo));
VkPipelineShaderStageCreateInfo stageInfos[5];
std::memset(stageInfos, 0, sizeof(stageInfos));
@@ -119,7 +120,8 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
Array<VkVertexInputAttributeDescription> attributes;
Map<uint32, uint32> bindingToStream;
Map<uint32, uint32> streamToBinding;
std::memset(bindings.data(), 0, sizeof(VkVertexInputBindingDescription) * 16); // if default allocation size ever changes, this breaks
assert(DEFAULT_ALLOC_SIZE == 16);
std::memset(bindings.data(), 0, sizeof(VkVertexInputBindingDescription) * 16);
std::memset(attributes.data(), 0, sizeof(VkVertexInputAttributeDescription) * 16);
for(auto& element : vertexStreams)
{
@@ -83,7 +83,6 @@ static Gfx::SeDescriptorType getTypeFromKind(slang::TypeReflection::Kind kind)
void Shader::create(const ShaderCreateInfo& createInfo)
{
std::cout << "--------------------------------" << std::endl;
entryPointName = createInfo.entryPoint;
static SlangSession* session = spCreateSession(NULL);
@@ -138,6 +138,10 @@ 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
changeLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
{
changeLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
}
VkImageViewCreateInfo viewInfo =
init::ImageViewCreateInfo();
-1
View File
@@ -47,7 +47,6 @@ void Material::compile()
json j;
stream >> j;
materialName = j["name"].get<std::string>();
std::cout << "Compiling material " << materialName << std::endl;
//Shader file needs to conform to the slang standard, which prohibits _
materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end());
std::ofstream codeStream("./shaders/generated/"+materialName+".slang");
+1 -1
View File
@@ -48,7 +48,7 @@ void MaterialAsset::updateDescriptorData()
descriptorSet->writeChanges();
}
Gfx::PDescriptorSet MaterialAsset::getDescriptor() const
const Gfx::PDescriptorSet MaterialAsset::getDescriptor() const
{
return descriptorSet;
}
+1 -1
View File
@@ -24,7 +24,7 @@ public:
// This needs to be called while the descriptorset is unused
void updateDescriptorData();
Gfx::PDescriptorSet getDescriptor() const;
const Gfx::PDescriptorSet getDescriptor() const;
protected:
//For now its simply the collection of parameters, since there is no point for expressions
Array<PShaderParameter> parameters;
+1 -1
View File
@@ -135,8 +135,8 @@ public:
else
{
object = (RefObject<T> *)registeredObj->value;
object->addRef();
}
object->addRef();
}
explicit RefPtr(RefObject<T> *other)
: object(other)
+1 -1
View File
@@ -33,7 +33,7 @@ void Scene::addActor(PActor actor)
void Scene::addPrimitiveComponent(PPrimitiveComponent comp)
{
primitives.add(comp);
for(auto batch : comp->staticMeshes)
for(auto& batch : comp->staticMeshes)
{
PrimitiveUniformBuffer data;
data.actorWorldPosition = Vector4(comp->getTransform().getPosition(), 1);
+27
View File
@@ -1,5 +1,6 @@
#include "EngineTest.h"
#include "Containers/Array.h"
#include "MinimalEngine.h"
#include <time.h>
#include <chrono>
#define BOOST_TEST_MODULE SeeleEngine
@@ -112,6 +113,32 @@ BOOST_AUTO_TEST_CASE(random_access)
BOOST_CHECK_EQUAL(array[0], 4);
}
class TestStruct
{
public:
uint32 data;
~TestStruct()
{
data = 1;
}
};
DECLARE_REF(TestStruct);
BOOST_AUTO_TEST_CASE(refptr_interaction)
{
uint32* dataPtr;
{
PTestStruct test = new TestStruct();
test->data = 32123;
dataPtr = &test->data;
{
Array<PTestStruct> arr(1);
arr[0] = test;
}
BOOST_CHECK_EQUAL(test->data, 32123);
}
}
/*BOOST_AUTO_TEST_CASE(benchmark)
{
using namespace std::chrono;
-8
View File
@@ -26,10 +26,6 @@ BOOST_AUTO_TEST_CASE(basic_insert)
List<int>::Iterator it = list.find(3);
it = list.insert(it, 1);
BOOST_REQUIRE_EQUAL(*it, 1);
for (auto i : list)
{
std::cout << i << std::endl;
}
BOOST_REQUIRE_EQUAL(list.length(), 4);
}
BOOST_AUTO_TEST_CASE(basic_remove)
@@ -41,10 +37,6 @@ BOOST_AUTO_TEST_CASE(basic_remove)
List<int>::Iterator it = list.find(3);
it = list.remove(it);
BOOST_REQUIRE_EQUAL(*it, 4);
for (auto i : list)
{
std::cout << i << std::endl;
}
BOOST_REQUIRE_EQUAL(list.length(), 2);
}
-3
View File
@@ -31,13 +31,10 @@ BOOST_AUTO_TEST_CASE(for_each)
map[6] = 4;
map[4] = 7;
int count = 0;
std::cout << "Map start" << std::endl;
for(auto it = map.begin(); it != map.end(); ++it)
{
std::cout << (*it).key << std::endl;
count++;
}
std::cout << "Map end" << std::endl;
BOOST_REQUIRE_EQUAL(count, 4);
}