Starts but segfaults sometimes, yay

This commit is contained in:
2021-10-16 12:59:11 +02:00
parent b1d8ef4120
commit 528b79812e
20 changed files with 226 additions and 230 deletions
+14 -8
View File
@@ -105,19 +105,25 @@ add_subdirectory(src/)
if(MSVC) if(MSVC)
set(_CRT_SECURE_NO_WARNINGS) set(_CRT_SECURE_NO_WARNINGS)
# target_compile_options(SeeleEngine PRIVATE /DEBUG:FASTLINK /Zi) target_compile_options(SeeleEngine PRIVATE /DEBUG:FASTLINK /Zi)
else() else()
target_compile_options(SeeleEngine PRIVATE -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines) target_compile_options(SeeleEngine PRIVATE -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines)
endif() endif()
add_executable(Seele_unit_tests "") add_executable(Seele_unit_tests "")
add_subdirectory(test/) add_subdirectory(test/)
if(WIN32)
add_custom_target(copy-binaries ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_BINARIES} $<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>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_BINARIES} $<TARGET_FILE_DIR:SeeleEngine>)
else()
add_custom_target(copy-binaries ALL COMMAND "")
endif()
add_custom_target(copy-runtime-files ALL 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_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:SeeleEngine>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_BINARIES} $<TARGET_FILE_DIR:SeeleEngine> DEPENDS SeeleEngine copy-binaries)
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>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_BINARIES} $<TARGET_FILE_DIR:SeeleEngine>
DEPENDS SeeleEngine)
+2 -2
View File
@@ -72,7 +72,7 @@ else()
DOC "The directory where GL/nsam.h resides") DOC "The directory where GL/nsam.h resides")
find_file( find_file(
NSAM_BINARY NSAM_LIBRARY
NAMES libGFSDK_Aftermath_Lib.${CMAKE_PLATFORM}.so NAMES libGFSDK_Aftermath_Lib.${CMAKE_PLATFORM}.so
PATHS PATHS
/usr/lib64 /usr/lib64
@@ -86,7 +86,7 @@ else()
endif() endif()
# Handle REQUIRD argument, define *_FOUND variable # Handle REQUIRD argument, define *_FOUND variable
find_package_handle_standard_args(NSAM DEFAULT_MSG NSAM_INCLUDE_DIR NSAM_BINARY) find_package_handle_standard_args(NSAM DEFAULT_MSG NSAM_INCLUDE_DIR NSAM_LIBRARY)
# Define NSAM_LIBRARIES and NSAM_INCLUDE_DIRS # Define NSAM_LIBRARIES and NSAM_INCLUDE_DIRS
if (NSAM_FOUND) if (NSAM_FOUND)
+11 -11
View File
@@ -18,16 +18,16 @@ struct VertexStageOutput
{ {
ShaderAttributeInterpolation shaderAttributeInterpolation : Interpolation; ShaderAttributeInterpolation shaderAttributeInterpolation : Interpolation;
VertexValueCache cache : ShaderCache; VertexValueCache cache : ShaderCache;
float4 position : SV_Position; float4 position : SV_Position;
}; };
[shader("vertex")] [shader("vertex")]
VertexStageOutput vertexMain( VertexStageOutput vertexMain(
VertexShaderInput input) VertexShaderInput input)
{ {
VertexStageOutput output; VertexStageOutput output;
VertexValueCache cache = input.getVertexCache(); VertexValueCache cache = input.getVertexCache();
float3 worldPosition = input.getWorldPosition(); float3 worldPosition = input.getWorldPosition();
worldPosition += gMaterial.getWorldOffset(); worldPosition += gMaterial.getWorldOffset();
float4 clipSpacePosition; float4 clipSpacePosition;
@@ -50,9 +50,9 @@ float4 fragmentMain(
) : SV_Target ) : SV_Target
{ {
MaterialFragmentParameter materialParams = input.getMaterialParameter(position); MaterialFragmentParameter materialParams = input.getMaterialParameter(position);
TMaterial.BRDF brdf = gMaterial.prepare(materialParams); TMaterial.BRDF brdf = gMaterial.prepare(materialParams);
float3 viewDir = normalize(materialParams.viewDir); float3 viewDir = normalize(materialParams.viewDir);
float3 result = float3(0, 0, 0); float3 result = float3(0, 0, 0);
@@ -61,15 +61,15 @@ float4 fragmentMain(
result += directionalLights[i].illuminate(materialParams, brdf, viewDir); result += directionalLights[i].illuminate(materialParams, brdf, viewDir);
} }
uint2 tileIndex = uint2(floor(position.xy / BLOCK_SIZE)); uint2 tileIndex = uint2(floor(position.xy / BLOCK_SIZE));
uint2 gridValue = lightGrid[tileIndex]; uint2 gridValue = lightGrid[tileIndex];
uint startOffset = gridValue.x; uint startOffset = gridValue.x;
uint lightCount = gridValue.y; uint lightCount = gridValue.y;
for (int j = 0; j < lightCount; ++j) for (int j = 0; j < lightCount; ++j)
{ {
uint lightIndex = lightIndexList[startOffset + j]; uint lightIndex = lightIndexList[startOffset + j];
PointLight pointLight = pointLights[lightIndex]; PointLight pointLight = pointLights[lightIndex];
result += pointLight.illuminate(materialParams, brdf, viewDir); result += pointLight.illuminate(materialParams, brdf, viewDir);
} }
return float4(result, 1); return float4(result, 1);
+4 -19
View File
@@ -78,7 +78,7 @@ ShaderCollection& ShaderMap::createShaders(
Array<char> buffer(static_cast<uint32>(fileSize)); Array<char> buffer(static_cast<uint32>(fileSize));
codeStream.read(buffer.data(), fileSize); codeStream.read(buffer.data(), fileSize);
createInfo.shaderCode.add(std::string(buffer.data())); createInfo.shaderCode.add(std::string(buffer.data(), 0, fileSize));
collection.vertexShader = graphics->createVertexShader(createInfo); collection.vertexShader = graphics->createVertexShader(createInfo);
@@ -113,6 +113,7 @@ void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorTyp
PDescriptorSet DescriptorLayout::allocateDescriptorSet() PDescriptorSet DescriptorLayout::allocateDescriptorSet()
{ {
std::unique_lock lock(allocatorLock);
PDescriptorSet result; PDescriptorSet result;
allocator->allocateDescriptorSet(result); allocator->allocateDescriptorSet(result);
return result; return result;
@@ -120,6 +121,7 @@ PDescriptorSet DescriptorLayout::allocateDescriptorSet()
void DescriptorLayout::reset() void DescriptorLayout::reset()
{ {
std::unique_lock lock(allocatorLock);
allocator->reset(); allocator->reset();
} }
@@ -129,24 +131,7 @@ void PipelineLayout::addDescriptorLayout(uint32 setIndex, PDescriptorLayout layo
{ {
descriptorSetLayouts.resize(setIndex + 1); descriptorSetLayouts.resize(setIndex + 1);
} }
// After a second thought, merging descriptor layout bindings is not a good idea descriptorSetLayouts[setIndex] = layout;
/*if (descriptorSetLayouts[setIndex] != nullptr)
{
auto &thisBindings = descriptorSetLayouts[setIndex]->descriptorBindings;
auto &otherBindings = layout->descriptorBindings;
thisBindings.resize(otherBindings.size());
for (size_t i = 0; i < otherBindings.size(); ++i)
{
if (otherBindings[i].descriptorType != SE_DESCRIPTOR_TYPE_MAX_ENUM)
{
thisBindings[i] = otherBindings[i];
}
}
}
else*/
{
descriptorSetLayouts[setIndex] = layout;
}
layout->setIndex = setIndex; layout->setIndex = setIndex;
} }
+1
View File
@@ -232,6 +232,7 @@ public:
protected: protected:
Array<DescriptorBinding> descriptorBindings; Array<DescriptorBinding> descriptorBindings;
PDescriptorAllocator allocator; PDescriptorAllocator allocator;
std::mutex allocatorLock;
uint32 setIndex; uint32 setIndex;
std::string name; std::string name;
friend class PipelineLayout; friend class PipelineLayout;
@@ -144,10 +144,6 @@ void BasePass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet(); descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
for(auto &&meshBatch : passData.staticDrawList)
{
meshBatch.material->updateDescriptorData();
}
} }
void BasePass::render() void BasePass::render()
@@ -125,10 +125,6 @@ void DepthPrepass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet(); descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
for(auto &&meshBatch : passData.staticDrawList)
{
meshBatch.material->updateDescriptorData();
}
} }
void DepthPrepass::render() void DepthPrepass::render()
@@ -1,5 +1,10 @@
target_sources(SeeleEngine target_sources(SeeleEngine
PRIVATE PRIVATE
NsightAftermathGpuCrashTracker.h
NsightAftermathGpuCrashTracker.cpp
NsightAftermathHelpers.h
NsightAftermathShaderDatabase.h
NsightAftermathShaderDatabase.cpp
VulkanAllocator.h VulkanAllocator.h
VulkanAllocator.cpp VulkanAllocator.cpp
VulkanBuffer.cpp VulkanBuffer.cpp
@@ -91,7 +91,7 @@ void GpuCrashTracker::OnShaderDebugInfo(const void* pShaderDebugInfo, const uint
// Get shader debug information identifier // Get shader debug information identifier
GFSDK_Aftermath_ShaderDebugInfoIdentifier identifier = {}; GFSDK_Aftermath_ShaderDebugInfoIdentifier identifier = {};
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GetShaderDebugInfoIdentifier( AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GetShaderDebugInfoIdentifier(
GFSDK_Aftermath_Version_API, GFSDK_Aftermath_Version_API,
pShaderDebugInfo, pShaderDebugInfo,
shaderDebugInfoSize, shaderDebugInfoSize,
@@ -124,7 +124,7 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
{ {
// Create a GPU crash dump decoder object for the GPU crash dump. // Create a GPU crash dump decoder object for the GPU crash dump.
GFSDK_Aftermath_GpuCrashDump_Decoder decoder = {}; GFSDK_Aftermath_GpuCrashDump_Decoder decoder = {};
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_CreateDecoder( AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_CreateDecoder(
GFSDK_Aftermath_Version_API, GFSDK_Aftermath_Version_API,
pGpuCrashDump, pGpuCrashDump,
gpuCrashDumpSize, gpuCrashDumpSize,
@@ -133,19 +133,19 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
// Use the decoder object to read basic information, like application // Use the decoder object to read basic information, like application
// name, PID, etc. from the GPU crash dump. // name, PID, etc. from the GPU crash dump.
GFSDK_Aftermath_GpuCrashDump_BaseInfo baseInfo = {}; GFSDK_Aftermath_GpuCrashDump_BaseInfo baseInfo = {};
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GetBaseInfo(decoder, &baseInfo)); AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetBaseInfo(decoder, &baseInfo));
// Use the decoder object to query the application name that was set // Use the decoder object to query the application name that was set
// in the GPU crash dump description. // in the GPU crash dump description.
uint32_t applicationNameLength = 0; uint32_t applicationNameLength = 0;
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GetDescriptionSize( AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetDescriptionSize(
decoder, decoder,
GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName, GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName,
&applicationNameLength)); &applicationNameLength));
std::vector<char> applicationName(applicationNameLength, '\0'); std::vector<char> applicationName(applicationNameLength, '\0');
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GetDescription( AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetDescription(
decoder, decoder,
GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName, GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName,
uint32_t(applicationName.size()), uint32_t(applicationName.size()),
@@ -176,7 +176,7 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
// Decode the crash dump to a JSON string. // Decode the crash dump to a JSON string.
// Step 1: Generate the JSON and get the size. // Step 1: Generate the JSON and get the size.
uint32_t jsonSize = 0; uint32_t jsonSize = 0;
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GenerateJSON( AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GenerateJSON(
decoder, decoder,
GFSDK_Aftermath_GpuCrashDumpDecoderFlags_ALL_INFO, GFSDK_Aftermath_GpuCrashDumpDecoderFlags_ALL_INFO,
GFSDK_Aftermath_GpuCrashDumpFormatterFlags_NONE, GFSDK_Aftermath_GpuCrashDumpFormatterFlags_NONE,
@@ -188,7 +188,7 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
&jsonSize)); &jsonSize));
// Step 2: Allocate a buffer and fetch the generated JSON. // Step 2: Allocate a buffer and fetch the generated JSON.
std::vector<char> json(jsonSize); std::vector<char> json(jsonSize);
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GetJSON( AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetJSON(
decoder, decoder,
uint32_t(json.size()), uint32_t(json.size()),
json.data())); json.data()));
@@ -203,7 +203,7 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
} }
// Destroy the GPU crash dump decoder object. // Destroy the GPU crash dump decoder object.
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_DestroyDecoder(decoder)); AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_DestroyDecoder(decoder));
} }
// Helper for writing shader debug information to a file // Helper for writing shader debug information to a file
@@ -147,6 +147,7 @@ void CmdBuffer::refreshFence()
{ {
descriptor->unbind(); descriptor->unbind();
} }
boundDescriptors.clear();
state = State::ReadyBegin; state = State::ReadyBegin;
} }
} }
@@ -249,7 +250,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
{ {
auto descriptor = descriptorSet.cast<DescriptorSet>(); auto descriptor = descriptorSet.cast<DescriptorSet>();
boundDescriptors.add(descriptor.getHandle()); boundDescriptors.add(descriptor.getHandle());
descriptor->bind(); descriptor->bind(this);
VkDescriptorSet setHandle = descriptor->getHandle(); VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
@@ -260,7 +261,7 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
for(uint32 i = 0; i < descriptorSets.size(); ++i) for(uint32 i = 0; i < descriptorSets.size(); ++i)
{ {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
descriptorSet->bind(); descriptorSet->bind(this);
boundDescriptors.add(descriptorSet.getHandle()); boundDescriptors.add(descriptorSet.getHandle());
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
@@ -333,7 +334,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
{ {
auto descriptor = descriptorSet.cast<DescriptorSet>(); auto descriptor = descriptorSet.cast<DescriptorSet>();
boundDescriptors.add(descriptor.getHandle()); boundDescriptors.add(descriptor.getHandle());
descriptor->bind(); descriptor->bind(this);
//std::cout << "Binding descriptor " << descriptor->getHandle() << " to cmd " << handle << std::endl; //std::cout << "Binding descriptor " << descriptor->getHandle() << " to cmd " << handle << std::endl;
VkDescriptorSet setHandle = descriptor->getHandle(); VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
@@ -346,7 +347,7 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
{ {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
boundDescriptors.add(descriptorSet.getHandle()); boundDescriptors.add(descriptorSet.getHandle());
descriptorSet->bind(); descriptorSet->bind(this);
//std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; //std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl;
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
} }
@@ -393,7 +394,7 @@ PRenderCommand CommandBufferManager::createRenderCommand(const std::string& name
for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i) for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i)
{ {
PRenderCommand cmdBuffer = allocatedRenderCommands[i]; PRenderCommand cmdBuffer = allocatedRenderCommands[i];
if (cmdBuffer->ready) if (cmdBuffer->isReady())
{ {
cmdBuffer->begin(activeCmdBuffer); cmdBuffer->begin(activeCmdBuffer);
return cmdBuffer; return cmdBuffer;
@@ -290,7 +290,7 @@ void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorS
//If it hasnt been initialized, allocate it //If it hasnt been initialized, allocate it
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle)); VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
} }
cachedHandles[setIndex]->currentlyInUse = true; cachedHandles[setIndex]->allocate();
descriptorSet = cachedHandles[setIndex]; descriptorSet = cachedHandles[setIndex];
PDescriptorSet vulkanSet = descriptorSet.cast<DescriptorSet>(); PDescriptorSet vulkanSet = descriptorSet.cast<DescriptorSet>();
+116 -109
View File
@@ -9,141 +9,148 @@ DECLARE_REF(Graphics)
class DescriptorLayout : public Gfx::DescriptorLayout class DescriptorLayout : public Gfx::DescriptorLayout
{ {
public: public:
DescriptorLayout(PGraphics graphics, const std::string& name); DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout(); virtual ~DescriptorLayout();
virtual void create(); virtual void create();
inline VkDescriptorSetLayout getHandle() const inline VkDescriptorSetLayout getHandle() const
{ {
return layoutHandle; return layoutHandle;
} }
private: private:
uint32 hash; uint32 hash;
PGraphics graphics; PGraphics graphics;
Array<VkDescriptorSetLayoutBinding> bindings; Array<VkDescriptorSetLayoutBinding> bindings;
VkDescriptorSetLayout layoutHandle; VkDescriptorSetLayout layoutHandle;
std::string name; std::string name;
friend class DescriptorAllocator; friend class DescriptorAllocator;
}; };
DEFINE_REF(DescriptorLayout) DEFINE_REF(DescriptorLayout)
class PipelineLayout : public Gfx::PipelineLayout class PipelineLayout : public Gfx::PipelineLayout
{ {
public: public:
PipelineLayout(PGraphics graphics) PipelineLayout(PGraphics graphics)
: graphics(graphics) : graphics(graphics)
, layoutHash(0) , layoutHash(0)
, layoutHandle(VK_NULL_HANDLE) , layoutHandle(VK_NULL_HANDLE)
{ {
} }
virtual ~PipelineLayout(); virtual ~PipelineLayout();
virtual void create(); virtual void create();
virtual void reset(); virtual void reset();
inline VkPipelineLayout getHandle() const inline VkPipelineLayout getHandle() const
{ {
return layoutHandle; return layoutHandle;
} }
virtual uint32 getHash() const virtual uint32 getHash() const
{ {
return layoutHash; return layoutHash;
} }
private: private:
Array<VkDescriptorSetLayout> vulkanDescriptorLayouts; Array<VkDescriptorSetLayout> vulkanDescriptorLayouts;
PGraphics graphics; PGraphics graphics;
uint32 layoutHash; uint32 layoutHash;
VkPipelineLayout layoutHandle; VkPipelineLayout layoutHandle;
}; };
DEFINE_REF(PipelineLayout) DEFINE_REF(PipelineLayout)
DECLARE_REF(SecondaryCmdBuffer)
class DescriptorSet : public Gfx::DescriptorSet class DescriptorSet : public Gfx::DescriptorSet
{ {
public: public:
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner) DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
: setHandle(VK_NULL_HANDLE) : setHandle(VK_NULL_HANDLE)
, graphics(graphics) , graphics(graphics)
, owner(owner) , owner(owner)
, currentlyBound(false) , boundBuffer(nullptr)
, currentlyInUse(false) , currentlyBound(false)
{ , currentlyInUse(false)
} {
virtual ~DescriptorSet(); }
virtual void writeChanges(); virtual ~DescriptorSet();
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer); virtual void writeChanges();
virtual void updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer); virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer);
virtual void updateSampler(uint32_t binding, Gfx::PSamplerState samplerState); virtual void updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer);
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState sampler = nullptr); virtual void updateSampler(uint32_t binding, Gfx::PSamplerState samplerState);
virtual bool operator<(Gfx::PDescriptorSet other); virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState sampler = nullptr);
virtual bool operator<(Gfx::PDescriptorSet other);
inline bool isCurrentlyBound() const
{ inline bool isCurrentlyBound() const
return currentlyBound; {
} return currentlyBound;
inline bool isCurrentlyInUse() const }
{ inline bool isCurrentlyInUse() const
return currentlyInUse; {
} return currentlyInUse;
void bind() }
{ void bind(PSecondaryCmdBuffer cmdBuffer)
currentlyBound = true; {
} boundBuffer = cmdBuffer;
void unbind() currentlyBound = true;
{ }
currentlyBound = false; void unbind()
} {
void free() boundBuffer = nullptr;
{ currentlyBound = false;
currentlyInUse = false; }
} void allocate()
inline VkDescriptorSet getHandle() const {
{ currentlyInUse = true;
return setHandle; }
} void free()
virtual uint32 getSetIndex() const; {
currentlyInUse = false;
}
inline VkDescriptorSet getHandle() const
{
return setHandle;
}
virtual uint32 getSetIndex() const;
private: private:
List<VkDescriptorImageInfo> imageInfos; List<VkDescriptorImageInfo> imageInfos;
List<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
// would not work anyways, so casts should be safe // would not work anyways, so casts should be safe
Array<void*> cachedData; Array<void*> cachedData;
VkDescriptorSet setHandle; VkDescriptorSet setHandle;
PGraphics graphics; PGraphics graphics;
PDescriptorAllocator owner; PDescriptorAllocator owner;
//PCmdBuffer currentlyBound; PSecondaryCmdBuffer boundBuffer;
bool currentlyBound; bool currentlyBound;
bool currentlyInUse; bool currentlyInUse;
friend class DescriptorAllocator; friend class DescriptorAllocator;
friend class CmdBuffer; friend class CmdBuffer;
friend class SecondaryCmdBuffer; friend class SecondaryCmdBuffer;
}; };
DEFINE_REF(DescriptorSet) DEFINE_REF(DescriptorSet)
class DescriptorAllocator : public Gfx::DescriptorAllocator class DescriptorAllocator : public Gfx::DescriptorAllocator
{ {
public: public:
DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout); DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout);
virtual ~DescriptorAllocator(); virtual ~DescriptorAllocator();
virtual void allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet); virtual void allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet);
virtual void reset(); virtual void reset();
inline VkDescriptorPool getHandle() const inline VkDescriptorPool getHandle() const
{ {
return poolHandle; return poolHandle;
} }
inline DescriptorLayout& getLayout() const inline DescriptorLayout& getLayout() const
{ {
return layout; return layout;
} }
private: private:
PGraphics graphics; PGraphics graphics;
DescriptorLayout &layout; DescriptorLayout &layout;
const static int maxSets = 512; const static int maxSets = 512;
StaticArray<PDescriptorSet, maxSets> cachedHandles; StaticArray<PDescriptorSet, maxSets> cachedHandles;
VkDescriptorPool poolHandle; VkDescriptorPool poolHandle;
}; };
DEFINE_REF(DescriptorAllocator) DEFINE_REF(DescriptorAllocator)
} // namespace Vulkan } // namespace Vulkan
@@ -414,7 +414,7 @@ void Graphics::setupDebugCallback()
VK_CHECK(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback)); VK_CHECK(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback));
//crashTracker.Initialize(); crashTracker.Initialize();
} }
void Graphics::pickPhysicalDevice() void Graphics::pickPhysicalDevice()
+2 -1
View File
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "VulkanGraphicsResources.h" #include "VulkanGraphicsResources.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "NsightAftermathGpuCrashTracker.h"
namespace Seele namespace Seele
{ {
@@ -98,7 +99,7 @@ protected:
Map<uint32, PFramebuffer> allocatedFramebuffers; Map<uint32, PFramebuffer> allocatedFramebuffers;
PAllocator allocator; PAllocator allocator;
PStagingManager stagingManager; PStagingManager stagingManager;
//GpuCrashTracker crashTracker; GpuCrashTracker crashTracker;
friend class Window; friend class Window;
}; };
@@ -22,7 +22,6 @@ Queue::~Queue()
void Queue::submitCommandBuffer(PCmdBuffer cmdBuffer, uint32 numSignalSemaphores, VkSemaphore *signalSemaphores) void Queue::submitCommandBuffer(PCmdBuffer cmdBuffer, uint32 numSignalSemaphores, VkSemaphore *signalSemaphores)
{ {
std::scoped_lock lck(queueLock); std::scoped_lock lck(queueLock);
assert(cmdBuffer->state == CmdBuffer::State::Ended); assert(cmdBuffer->state == CmdBuffer::State::Ended);
@@ -87,6 +87,16 @@ void Shader::create(const ShaderCreateInfo& createInfo)
char const* diagnostics = spGetDiagnosticOutput(request); char const* diagnostics = spGetDiagnosticOutput(request);
std::cout << "Compile error for shader " << createInfo.name << std::endl; std::cout << "Compile error for shader " << createInfo.name << std::endl;
std::cout << diagnostics << std::endl; std::cout << diagnostics << std::endl;
std::cout << "Defines: " << std::endl;
for(auto define : createInfo.defines)
{
std::cout << define.key << ": " << define.value << std::endl;
}
std::cout << "For shader code: " << std::endl;
for(auto code : createInfo.shaderCode)
{
std::cout << code << std::endl;
}
return; return;
} }
size_t dataSize = 0; size_t dataSize = 0;
+27 -48
View File
@@ -56,77 +56,56 @@ void BlinnPhong::generateMaterialCode(std::ofstream& codeStream, json codeJson)
{ {
for(auto code : codeJson[key].items()) for(auto code : codeJson[key].items())
{ {
accessorStream << code.value().get<std::string>() << ";" << std::endl; accessorStream << "\t\t" << code.value().get<std::string>() << ";" << std::endl;
} }
} }
else else
{ {
accessorStream << "return " << defaultVal << ";"; accessorStream << "\t\treturn " << defaultVal << ";\n";
} }
}; };
accessorStream << "float3 getBaseColor(MaterialFragmentParameter input) {\n"; accessorStream << "\tfloat3 getBaseColor(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "baseColor", "float3(0.5f, 0.5f, 0.5f)"); generateAccessor(accessorStream, "baseColor", "float3(0.5f, 0.5f, 0.5f)");
accessorStream << "}"; accessorStream << "\t}\n";
accessorStream << "float getMetallic(MaterialFragmentParameter input) {\n"; accessorStream << "\tfloat getMetallic(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "metallic", "0.f"); generateAccessor(accessorStream, "metallic", "0.f");
accessorStream << "}"; accessorStream << "\t}\n";
accessorStream << "float3 getNormal(MaterialFragmentParameter input) {\n"; accessorStream << "\tfloat3 getNormal(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "normal", "float3(0, 1, 0)"); generateAccessor(accessorStream, "normal", "float3(0, 1, 0)");
accessorStream << "}"; accessorStream << "\t}\n";
accessorStream << "float getSpecular(MaterialFragmentParameter input) {\n"; accessorStream << "\tfloat getSpecular(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "specular", "0.f"); generateAccessor(accessorStream, "specular", "0.f");
accessorStream << "}"; accessorStream << "\t}\n";
accessorStream << "float getRoughness(MaterialFragmentParameter input) {\n"; accessorStream << "\tfloat getRoughness(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "roughness", "0.f"); generateAccessor(accessorStream, "roughness", "0.f");
accessorStream << "}"; accessorStream << "\t}\n";
accessorStream << "float getSheen(MaterialFragmentParameter input) {\n"; accessorStream << "\tfloat getSheen(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "sheen", "0.f"); generateAccessor(accessorStream, "sheen", "0.f");
accessorStream << "}"; accessorStream << "\t}\n";
/*accessorStream << "float getSpecularTint(MaterialFragmentParameter input) {\n"; accessorStream << "\tfloat3 getWorldOffset() {\n";
generateAccessor(accessorStream, "specularTint", "0.f");
accessorStream << "}";
accessorStream << "float getAnisotropic(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "anisotropic", "0.f");
accessorStream << "}";
accessorStream << "float getSheenTint(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "sheenTint", "0.f");
accessorStream << "}";
accessorStream << "float getClearCoat(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "clearCoat", "0.f");
accessorStream << "}";
accessorStream << "float getClearCoatGloss(MaterialFragmentParameter input) {\n";
generateAccessor(accessorStream, "clearCoatGloss", "0.f");
accessorStream << "}";*/
accessorStream << "float3 getWorldOffset() {\n";
generateAccessor(accessorStream, "worldOffset", "0.f"); generateAccessor(accessorStream, "worldOffset", "0.f");
accessorStream << "}"; accessorStream << "\t}\n";
codeStream << accessorStream.str(); codeStream << accessorStream.str();
codeStream << "typedef " << name << " BRDF;" << std::endl; codeStream << "\ttypedef " << name << " BRDF;" << std::endl;
codeStream << name << " prepare(MaterialFragmentParameter geometry){" << std::endl; codeStream << "\t" << name << " prepare(MaterialFragmentParameter geometry) {" << std::endl;
codeStream << name << " result;" << std::endl; codeStream << "\t\t" << name << " result;" << std::endl;
codeStream << "result.baseColor = getBaseColor(geometry);" << std::endl; codeStream << "\t\tresult.baseColor = getBaseColor(geometry);" << std::endl;
codeStream << "result.metallic = getMetallic(geometry);" << std::endl; codeStream << "\t\tresult.metallic = getMetallic(geometry);" << std::endl;
codeStream << "result.normal = getNormal(geometry);" << std::endl; codeStream << "\t\tresult.normal = getNormal(geometry);" << std::endl;
codeStream << "result.specular = getSpecular(geometry);" << std::endl; codeStream << "\t\tresult.specular = getSpecular(geometry);" << std::endl;
codeStream << "result.roughness = getRoughness(geometry);" << std::endl; codeStream << "\t\tresult.roughness = getRoughness(geometry);" << std::endl;
codeStream << "result.sheen = getSheen(geometry);" << std::endl; codeStream << "\t\tresult.sheen = getSheen(geometry);" << std::endl;
codeStream << "return result;" << std::endl; codeStream << "\t\treturn result;" << std::endl;
codeStream << "}" << std::endl; codeStream << "\t}" << std::endl;
} }
IMPLEMENT_BRDF(BlinnPhong) IMPLEMENT_BRDF(BlinnPhong)
+5 -6
View File
@@ -56,9 +56,9 @@ void Material::compile()
codeStream << "import VERTEX_INPUT_IMPORT;" << std::endl; codeStream << "import VERTEX_INPUT_IMPORT;" << std::endl;
codeStream << "import Material;" << std::endl; codeStream << "import Material;" << std::endl;
codeStream << "import BRDF;" << std::endl; codeStream << "import BRDF;" << std::endl;
codeStream << "import MaterialParameter;" << std::endl; codeStream << "import MaterialParameter;" << std::endl << std::endl;
codeStream << "struct " << materialName << ": IMaterial {" << std::endl; codeStream << "struct " << materialName << " : IMaterial {" << std::endl;
uint32 uniformBufferOffset = 0; uint32 uniformBufferOffset = 0;
uint32 bindingCounter = 0; // Uniform buffers are always binding 0 uint32 bindingCounter = 0; // Uniform buffers are always binding 0
uniformBinding = -1; uniformBinding = -1;
@@ -69,7 +69,7 @@ void Material::compile()
if(type.compare("float") == 0) if(type.compare("float") == 0)
{ {
PFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, 0); PFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, 0);
codeStream << "layout(offset = " << uniformBufferOffset << ")"; codeStream << "\tlayout(offset = " << uniformBufferOffset << ")";
if(uniformBinding == -1) if(uniformBinding == -1)
{ {
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
@@ -85,7 +85,7 @@ void Material::compile()
else if(type.compare("float3") == 0) else if(type.compare("float3") == 0)
{ {
PVectorParameter p = new VectorParameter(param.key(), uniformBufferOffset, 0); PVectorParameter p = new VectorParameter(param.key(), uniformBufferOffset, 0);
codeStream << "layout(offset = " << uniformBufferOffset << ")"; codeStream << "\tlayout(offset = " << uniformBufferOffset << ")";
if(uniformBinding == -1) if(uniformBinding == -1)
{ {
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
@@ -105,7 +105,6 @@ void Material::compile()
if(defaultValue != param.value().end()) if(defaultValue != param.value().end())
{ {
std::string defaultString = 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); p->data = AssetRegistry::findTexture(defaultString);
} }
else else
@@ -127,7 +126,7 @@ void Material::compile()
{ {
std::cout << "Error unsupported parameter type" << std::endl; std::cout << "Error unsupported parameter type" << std::endl;
} }
codeStream << type << " " << param.key() << ";\n"; codeStream << "\t" << type << " " << param.key() << ";\n";
} }
uniformDataSize = uniformBufferOffset; uniformDataSize = uniformBufferOffset;
if(uniformDataSize != 0) if(uniformDataSize != 0)
+9 -2
View File
@@ -150,7 +150,14 @@ bool Transform::equals(const Transform &other, float tolerance)
{ {
return false; return false;
} }
if (abs(rotation.x - other.rotation.x) <= tolerance && abs(rotation.y - other.rotation.y) <= tolerance && abs(rotation.z - other.rotation.z) <= tolerance && abs(rotation.w - other.rotation.w) <= tolerance || abs(rotation.x + other.rotation.x) <= tolerance && abs(rotation.y + other.rotation.y) <= tolerance && abs(rotation.z + other.rotation.z) <= tolerance && abs(rotation.w - other.rotation.w) <= tolerance) if ((abs(rotation.x - other.rotation.x) <= tolerance
&& abs(rotation.y - other.rotation.y) <= tolerance
&& abs(rotation.z - other.rotation.z) <= tolerance
&& abs(rotation.w - other.rotation.w) <= tolerance)
|| (abs(rotation.x + other.rotation.x) <= tolerance
&& abs(rotation.y + other.rotation.y) <= tolerance
&& abs(rotation.z + other.rotation.z) <= tolerance
&& abs(rotation.w + other.rotation.w) <= tolerance))
{ {
return false; return false;
} }
@@ -191,5 +198,5 @@ Transform Transform::operator*(const Transform &other) const
{ {
Transform outTransform; Transform outTransform;
multiply(&outTransform, this, &other); multiply(&outTransform, this, &other);
return std::move(outTransform); return outTransform;
} }
+4
View File
@@ -38,6 +38,10 @@ Scene::~Scene()
void Scene::tick(double deltaTime) void Scene::tick(double deltaTime)
{ {
updater->runUpdates(static_cast<float>(deltaTime)); updater->runUpdates(static_cast<float>(deltaTime));
for(auto &&meshBatch : staticMeshes)
{
meshBatch.material->updateDescriptorData();
}
} }
void Scene::addActor(PActor actor) void Scene::addActor(PActor actor)