Starts but segfaults sometimes, yay
This commit is contained in:
+14
-8
@@ -105,19 +105,25 @@ add_subdirectory(src/)
|
||||
|
||||
if(MSVC)
|
||||
set(_CRT_SECURE_NO_WARNINGS)
|
||||
# target_compile_options(SeeleEngine PRIVATE /DEBUG:FASTLINK /Zi)
|
||||
target_compile_options(SeeleEngine PRIVATE /DEBUG:FASTLINK /Zi)
|
||||
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()
|
||||
|
||||
add_executable(Seele_unit_tests "")
|
||||
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
|
||||
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>
|
||||
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)
|
||||
DEPENDS SeeleEngine copy-binaries)
|
||||
|
||||
@@ -72,7 +72,7 @@ else()
|
||||
DOC "The directory where GL/nsam.h resides")
|
||||
|
||||
find_file(
|
||||
NSAM_BINARY
|
||||
NSAM_LIBRARY
|
||||
NAMES libGFSDK_Aftermath_Lib.${CMAKE_PLATFORM}.so
|
||||
PATHS
|
||||
/usr/lib64
|
||||
@@ -86,7 +86,7 @@ else()
|
||||
endif()
|
||||
|
||||
# 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
|
||||
if (NSAM_FOUND)
|
||||
|
||||
@@ -18,16 +18,16 @@ struct VertexStageOutput
|
||||
{
|
||||
ShaderAttributeInterpolation shaderAttributeInterpolation : Interpolation;
|
||||
VertexValueCache cache : ShaderCache;
|
||||
float4 position : SV_Position;
|
||||
float4 position : SV_Position;
|
||||
};
|
||||
|
||||
[shader("vertex")]
|
||||
VertexStageOutput vertexMain(
|
||||
VertexShaderInput input)
|
||||
VertexShaderInput input)
|
||||
{
|
||||
VertexStageOutput output;
|
||||
VertexValueCache cache = input.getVertexCache();
|
||||
float3 worldPosition = input.getWorldPosition();
|
||||
float3 worldPosition = input.getWorldPosition();
|
||||
worldPosition += gMaterial.getWorldOffset();
|
||||
float4 clipSpacePosition;
|
||||
|
||||
@@ -50,9 +50,9 @@ float4 fragmentMain(
|
||||
) : SV_Target
|
||||
{
|
||||
MaterialFragmentParameter materialParams = input.getMaterialParameter(position);
|
||||
TMaterial.BRDF brdf = gMaterial.prepare(materialParams);
|
||||
|
||||
float3 viewDir = normalize(materialParams.viewDir);
|
||||
TMaterial.BRDF brdf = gMaterial.prepare(materialParams);
|
||||
|
||||
float3 viewDir = normalize(materialParams.viewDir);
|
||||
|
||||
float3 result = float3(0, 0, 0);
|
||||
|
||||
@@ -61,15 +61,15 @@ float4 fragmentMain(
|
||||
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];
|
||||
uint startOffset = gridValue.x;
|
||||
uint lightCount = gridValue.y;
|
||||
uint startOffset = gridValue.x;
|
||||
uint lightCount = gridValue.y;
|
||||
|
||||
for (int j = 0; j < lightCount; ++j)
|
||||
{
|
||||
uint lightIndex = lightIndexList[startOffset + j];
|
||||
PointLight pointLight = pointLights[lightIndex];
|
||||
uint lightIndex = lightIndexList[startOffset + j];
|
||||
PointLight pointLight = pointLights[lightIndex];
|
||||
result += pointLight.illuminate(materialParams, brdf, viewDir);
|
||||
}
|
||||
return float4(result, 1);
|
||||
|
||||
@@ -78,7 +78,7 @@ ShaderCollection& ShaderMap::createShaders(
|
||||
Array<char> buffer(static_cast<uint32>(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);
|
||||
|
||||
@@ -113,6 +113,7 @@ void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorTyp
|
||||
|
||||
PDescriptorSet DescriptorLayout::allocateDescriptorSet()
|
||||
{
|
||||
std::unique_lock lock(allocatorLock);
|
||||
PDescriptorSet result;
|
||||
allocator->allocateDescriptorSet(result);
|
||||
return result;
|
||||
@@ -120,6 +121,7 @@ PDescriptorSet DescriptorLayout::allocateDescriptorSet()
|
||||
|
||||
void DescriptorLayout::reset()
|
||||
{
|
||||
std::unique_lock lock(allocatorLock);
|
||||
allocator->reset();
|
||||
}
|
||||
|
||||
@@ -129,24 +131,7 @@ void PipelineLayout::addDescriptorLayout(uint32 setIndex, PDescriptorLayout layo
|
||||
{
|
||||
descriptorSetLayouts.resize(setIndex + 1);
|
||||
}
|
||||
// After a second thought, merging descriptor layout bindings is not a good idea
|
||||
/*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;
|
||||
}
|
||||
descriptorSetLayouts[setIndex] = layout;
|
||||
layout->setIndex = setIndex;
|
||||
}
|
||||
|
||||
|
||||
@@ -232,6 +232,7 @@ public:
|
||||
protected:
|
||||
Array<DescriptorBinding> descriptorBindings;
|
||||
PDescriptorAllocator allocator;
|
||||
std::mutex allocatorLock;
|
||||
uint32 setIndex;
|
||||
std::string name;
|
||||
friend class PipelineLayout;
|
||||
|
||||
@@ -144,10 +144,6 @@ void BasePass::beginFrame()
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
for(auto &&meshBatch : passData.staticDrawList)
|
||||
{
|
||||
meshBatch.material->updateDescriptorData();
|
||||
}
|
||||
}
|
||||
|
||||
void BasePass::render()
|
||||
|
||||
@@ -125,10 +125,6 @@ void DepthPrepass::beginFrame()
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
for(auto &&meshBatch : passData.staticDrawList)
|
||||
{
|
||||
meshBatch.material->updateDescriptorData();
|
||||
}
|
||||
}
|
||||
|
||||
void DepthPrepass::render()
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
target_sources(SeeleEngine
|
||||
PRIVATE
|
||||
NsightAftermathGpuCrashTracker.h
|
||||
NsightAftermathGpuCrashTracker.cpp
|
||||
NsightAftermathHelpers.h
|
||||
NsightAftermathShaderDatabase.h
|
||||
NsightAftermathShaderDatabase.cpp
|
||||
VulkanAllocator.h
|
||||
VulkanAllocator.cpp
|
||||
VulkanBuffer.cpp
|
||||
|
||||
@@ -91,7 +91,7 @@ void GpuCrashTracker::OnShaderDebugInfo(const void* pShaderDebugInfo, const uint
|
||||
|
||||
// Get shader debug information identifier
|
||||
GFSDK_Aftermath_ShaderDebugInfoIdentifier identifier = {};
|
||||
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GetShaderDebugInfoIdentifier(
|
||||
AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GetShaderDebugInfoIdentifier(
|
||||
GFSDK_Aftermath_Version_API,
|
||||
pShaderDebugInfo,
|
||||
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.
|
||||
GFSDK_Aftermath_GpuCrashDump_Decoder decoder = {};
|
||||
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_CreateDecoder(
|
||||
AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_CreateDecoder(
|
||||
GFSDK_Aftermath_Version_API,
|
||||
pGpuCrashDump,
|
||||
gpuCrashDumpSize,
|
||||
@@ -133,19 +133,19 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
|
||||
// Use the decoder object to read basic information, like application
|
||||
// name, PID, etc. from the GPU crash dump.
|
||||
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
|
||||
// in the GPU crash dump description.
|
||||
uint32_t applicationNameLength = 0;
|
||||
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GetDescriptionSize(
|
||||
AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetDescriptionSize(
|
||||
decoder,
|
||||
GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName,
|
||||
&applicationNameLength));
|
||||
|
||||
std::vector<char> applicationName(applicationNameLength, '\0');
|
||||
|
||||
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GetDescription(
|
||||
AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetDescription(
|
||||
decoder,
|
||||
GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName,
|
||||
uint32_t(applicationName.size()),
|
||||
@@ -176,7 +176,7 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
|
||||
// Decode the crash dump to a JSON string.
|
||||
// Step 1: Generate the JSON and get the size.
|
||||
uint32_t jsonSize = 0;
|
||||
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GenerateJSON(
|
||||
AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GenerateJSON(
|
||||
decoder,
|
||||
GFSDK_Aftermath_GpuCrashDumpDecoderFlags_ALL_INFO,
|
||||
GFSDK_Aftermath_GpuCrashDumpFormatterFlags_NONE,
|
||||
@@ -188,7 +188,7 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
|
||||
&jsonSize));
|
||||
// Step 2: Allocate a buffer and fetch the generated JSON.
|
||||
std::vector<char> json(jsonSize);
|
||||
AFTERMATH_CHECK_ERROR(PFN_GFSDK_Aftermath_GpuCrashDump_GetJSON(
|
||||
AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetJSON(
|
||||
decoder,
|
||||
uint32_t(json.size()),
|
||||
json.data()));
|
||||
@@ -203,7 +203,7 @@ void GpuCrashTracker::WriteGpuCrashDumpToFile(const void* pGpuCrashDump, const u
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -147,6 +147,7 @@ void CmdBuffer::refreshFence()
|
||||
{
|
||||
descriptor->unbind();
|
||||
}
|
||||
boundDescriptors.clear();
|
||||
state = State::ReadyBegin;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +250,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
|
||||
{
|
||||
auto descriptor = descriptorSet.cast<DescriptorSet>();
|
||||
boundDescriptors.add(descriptor.getHandle());
|
||||
descriptor->bind();
|
||||
descriptor->bind(this);
|
||||
|
||||
VkDescriptorSet setHandle = descriptor->getHandle();
|
||||
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)
|
||||
{
|
||||
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
|
||||
descriptorSet->bind();
|
||||
descriptorSet->bind(this);
|
||||
|
||||
boundDescriptors.add(descriptorSet.getHandle());
|
||||
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
|
||||
@@ -333,7 +334,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
|
||||
{
|
||||
auto descriptor = descriptorSet.cast<DescriptorSet>();
|
||||
boundDescriptors.add(descriptor.getHandle());
|
||||
descriptor->bind();
|
||||
descriptor->bind(this);
|
||||
//std::cout << "Binding descriptor " << descriptor->getHandle() << " to cmd " << handle << std::endl;
|
||||
VkDescriptorSet setHandle = descriptor->getHandle();
|
||||
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>();
|
||||
boundDescriptors.add(descriptorSet.getHandle());
|
||||
descriptorSet->bind();
|
||||
descriptorSet->bind(this);
|
||||
//std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl;
|
||||
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
|
||||
}
|
||||
@@ -393,7 +394,7 @@ PRenderCommand CommandBufferManager::createRenderCommand(const std::string& name
|
||||
for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i)
|
||||
{
|
||||
PRenderCommand cmdBuffer = allocatedRenderCommands[i];
|
||||
if (cmdBuffer->ready)
|
||||
if (cmdBuffer->isReady())
|
||||
{
|
||||
cmdBuffer->begin(activeCmdBuffer);
|
||||
return cmdBuffer;
|
||||
|
||||
@@ -290,7 +290,7 @@ void DescriptorAllocator::allocateDescriptorSet(Gfx::PDescriptorSet &descriptorS
|
||||
//If it hasnt been initialized, allocate it
|
||||
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
|
||||
}
|
||||
cachedHandles[setIndex]->currentlyInUse = true;
|
||||
cachedHandles[setIndex]->allocate();
|
||||
descriptorSet = cachedHandles[setIndex];
|
||||
|
||||
PDescriptorSet vulkanSet = descriptorSet.cast<DescriptorSet>();
|
||||
|
||||
@@ -9,141 +9,148 @@ DECLARE_REF(Graphics)
|
||||
class DescriptorLayout : public Gfx::DescriptorLayout
|
||||
{
|
||||
public:
|
||||
DescriptorLayout(PGraphics graphics, const std::string& name);
|
||||
virtual ~DescriptorLayout();
|
||||
virtual void create();
|
||||
inline VkDescriptorSetLayout getHandle() const
|
||||
{
|
||||
return layoutHandle;
|
||||
}
|
||||
DescriptorLayout(PGraphics graphics, const std::string& name);
|
||||
virtual ~DescriptorLayout();
|
||||
virtual void create();
|
||||
inline VkDescriptorSetLayout getHandle() const
|
||||
{
|
||||
return layoutHandle;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 hash;
|
||||
PGraphics graphics;
|
||||
Array<VkDescriptorSetLayoutBinding> bindings;
|
||||
VkDescriptorSetLayout layoutHandle;
|
||||
std::string name;
|
||||
friend class DescriptorAllocator;
|
||||
uint32 hash;
|
||||
PGraphics graphics;
|
||||
Array<VkDescriptorSetLayoutBinding> bindings;
|
||||
VkDescriptorSetLayout layoutHandle;
|
||||
std::string name;
|
||||
friend class DescriptorAllocator;
|
||||
};
|
||||
DEFINE_REF(DescriptorLayout)
|
||||
class PipelineLayout : public Gfx::PipelineLayout
|
||||
{
|
||||
public:
|
||||
PipelineLayout(PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
, layoutHash(0)
|
||||
, layoutHandle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
virtual ~PipelineLayout();
|
||||
virtual void create();
|
||||
virtual void reset();
|
||||
inline VkPipelineLayout getHandle() const
|
||||
{
|
||||
return layoutHandle;
|
||||
}
|
||||
virtual uint32 getHash() const
|
||||
{
|
||||
return layoutHash;
|
||||
}
|
||||
PipelineLayout(PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
, layoutHash(0)
|
||||
, layoutHandle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
virtual ~PipelineLayout();
|
||||
virtual void create();
|
||||
virtual void reset();
|
||||
inline VkPipelineLayout getHandle() const
|
||||
{
|
||||
return layoutHandle;
|
||||
}
|
||||
virtual uint32 getHash() const
|
||||
{
|
||||
return layoutHash;
|
||||
}
|
||||
|
||||
private:
|
||||
Array<VkDescriptorSetLayout> vulkanDescriptorLayouts;
|
||||
PGraphics graphics;
|
||||
uint32 layoutHash;
|
||||
VkPipelineLayout layoutHandle;
|
||||
Array<VkDescriptorSetLayout> vulkanDescriptorLayouts;
|
||||
PGraphics graphics;
|
||||
uint32 layoutHash;
|
||||
VkPipelineLayout layoutHandle;
|
||||
};
|
||||
DEFINE_REF(PipelineLayout)
|
||||
|
||||
|
||||
DECLARE_REF(SecondaryCmdBuffer)
|
||||
class DescriptorSet : public Gfx::DescriptorSet
|
||||
{
|
||||
public:
|
||||
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
|
||||
: setHandle(VK_NULL_HANDLE)
|
||||
, graphics(graphics)
|
||||
, owner(owner)
|
||||
, currentlyBound(false)
|
||||
, currentlyInUse(false)
|
||||
{
|
||||
}
|
||||
virtual ~DescriptorSet();
|
||||
virtual void writeChanges();
|
||||
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer);
|
||||
virtual void updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer);
|
||||
virtual void updateSampler(uint32_t binding, Gfx::PSamplerState samplerState);
|
||||
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState sampler = nullptr);
|
||||
virtual bool operator<(Gfx::PDescriptorSet other);
|
||||
|
||||
inline bool isCurrentlyBound() const
|
||||
{
|
||||
return currentlyBound;
|
||||
}
|
||||
inline bool isCurrentlyInUse() const
|
||||
{
|
||||
return currentlyInUse;
|
||||
}
|
||||
void bind()
|
||||
{
|
||||
currentlyBound = true;
|
||||
}
|
||||
void unbind()
|
||||
{
|
||||
currentlyBound = false;
|
||||
}
|
||||
void free()
|
||||
{
|
||||
currentlyInUse = false;
|
||||
}
|
||||
inline VkDescriptorSet getHandle() const
|
||||
{
|
||||
return setHandle;
|
||||
}
|
||||
virtual uint32 getSetIndex() const;
|
||||
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
|
||||
: setHandle(VK_NULL_HANDLE)
|
||||
, graphics(graphics)
|
||||
, owner(owner)
|
||||
, boundBuffer(nullptr)
|
||||
, currentlyBound(false)
|
||||
, currentlyInUse(false)
|
||||
{
|
||||
}
|
||||
virtual ~DescriptorSet();
|
||||
virtual void writeChanges();
|
||||
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer);
|
||||
virtual void updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer);
|
||||
virtual void updateSampler(uint32_t binding, Gfx::PSamplerState samplerState);
|
||||
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState sampler = nullptr);
|
||||
virtual bool operator<(Gfx::PDescriptorSet other);
|
||||
|
||||
inline bool isCurrentlyBound() const
|
||||
{
|
||||
return currentlyBound;
|
||||
}
|
||||
inline bool isCurrentlyInUse() const
|
||||
{
|
||||
return currentlyInUse;
|
||||
}
|
||||
void bind(PSecondaryCmdBuffer cmdBuffer)
|
||||
{
|
||||
boundBuffer = cmdBuffer;
|
||||
currentlyBound = true;
|
||||
}
|
||||
void unbind()
|
||||
{
|
||||
boundBuffer = nullptr;
|
||||
currentlyBound = false;
|
||||
}
|
||||
void allocate()
|
||||
{
|
||||
currentlyInUse = true;
|
||||
}
|
||||
void free()
|
||||
{
|
||||
currentlyInUse = false;
|
||||
}
|
||||
inline VkDescriptorSet getHandle() const
|
||||
{
|
||||
return setHandle;
|
||||
}
|
||||
virtual uint32 getSetIndex() const;
|
||||
|
||||
private:
|
||||
List<VkDescriptorImageInfo> imageInfos;
|
||||
List<VkDescriptorBufferInfo> bufferInfos;
|
||||
Array<VkWriteDescriptorSet> writeDescriptors;
|
||||
// contains the previously bound resources at every binding
|
||||
// since the layout is fixed, trying to bind a texture to a buffer
|
||||
// would not work anyways, so casts should be safe
|
||||
Array<void*> cachedData;
|
||||
VkDescriptorSet setHandle;
|
||||
PGraphics graphics;
|
||||
PDescriptorAllocator owner;
|
||||
//PCmdBuffer currentlyBound;
|
||||
bool currentlyBound;
|
||||
bool currentlyInUse;
|
||||
friend class DescriptorAllocator;
|
||||
friend class CmdBuffer;
|
||||
friend class SecondaryCmdBuffer;
|
||||
List<VkDescriptorImageInfo> imageInfos;
|
||||
List<VkDescriptorBufferInfo> bufferInfos;
|
||||
Array<VkWriteDescriptorSet> writeDescriptors;
|
||||
// contains the previously bound resources at every binding
|
||||
// since the layout is fixed, trying to bind a texture to a buffer
|
||||
// would not work anyways, so casts should be safe
|
||||
Array<void*> cachedData;
|
||||
VkDescriptorSet setHandle;
|
||||
PGraphics graphics;
|
||||
PDescriptorAllocator owner;
|
||||
PSecondaryCmdBuffer boundBuffer;
|
||||
bool currentlyBound;
|
||||
bool currentlyInUse;
|
||||
friend class DescriptorAllocator;
|
||||
friend class CmdBuffer;
|
||||
friend class SecondaryCmdBuffer;
|
||||
};
|
||||
DEFINE_REF(DescriptorSet)
|
||||
|
||||
class DescriptorAllocator : public Gfx::DescriptorAllocator
|
||||
{
|
||||
public:
|
||||
DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout);
|
||||
virtual ~DescriptorAllocator();
|
||||
virtual void allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet);
|
||||
virtual void reset();
|
||||
DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout);
|
||||
virtual ~DescriptorAllocator();
|
||||
virtual void allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet);
|
||||
virtual void reset();
|
||||
|
||||
inline VkDescriptorPool getHandle() const
|
||||
{
|
||||
return poolHandle;
|
||||
}
|
||||
inline DescriptorLayout& getLayout() const
|
||||
{
|
||||
return layout;
|
||||
}
|
||||
inline VkDescriptorPool getHandle() const
|
||||
{
|
||||
return poolHandle;
|
||||
}
|
||||
inline DescriptorLayout& getLayout() const
|
||||
{
|
||||
return layout;
|
||||
}
|
||||
|
||||
private:
|
||||
PGraphics graphics;
|
||||
DescriptorLayout &layout;
|
||||
const static int maxSets = 512;
|
||||
StaticArray<PDescriptorSet, maxSets> cachedHandles;
|
||||
VkDescriptorPool poolHandle;
|
||||
PGraphics graphics;
|
||||
DescriptorLayout &layout;
|
||||
const static int maxSets = 512;
|
||||
StaticArray<PDescriptorSet, maxSets> cachedHandles;
|
||||
VkDescriptorPool poolHandle;
|
||||
};
|
||||
DEFINE_REF(DescriptorAllocator)
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -414,7 +414,7 @@ void Graphics::setupDebugCallback()
|
||||
|
||||
VK_CHECK(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback));
|
||||
|
||||
//crashTracker.Initialize();
|
||||
crashTracker.Initialize();
|
||||
}
|
||||
|
||||
void Graphics::pickPhysicalDevice()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "VulkanGraphicsResources.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "NsightAftermathGpuCrashTracker.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -98,7 +99,7 @@ protected:
|
||||
Map<uint32, PFramebuffer> allocatedFramebuffers;
|
||||
PAllocator allocator;
|
||||
PStagingManager stagingManager;
|
||||
//GpuCrashTracker crashTracker;
|
||||
GpuCrashTracker crashTracker;
|
||||
|
||||
friend class Window;
|
||||
};
|
||||
|
||||
@@ -22,7 +22,6 @@ Queue::~Queue()
|
||||
|
||||
void Queue::submitCommandBuffer(PCmdBuffer cmdBuffer, uint32 numSignalSemaphores, VkSemaphore *signalSemaphores)
|
||||
{
|
||||
|
||||
std::scoped_lock lck(queueLock);
|
||||
assert(cmdBuffer->state == CmdBuffer::State::Ended);
|
||||
|
||||
|
||||
@@ -87,6 +87,16 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
char const* diagnostics = spGetDiagnosticOutput(request);
|
||||
std::cout << "Compile error for shader " << createInfo.name << 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;
|
||||
}
|
||||
size_t dataSize = 0;
|
||||
|
||||
@@ -56,77 +56,56 @@ void BlinnPhong::generateMaterialCode(std::ofstream& codeStream, json codeJson)
|
||||
{
|
||||
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
|
||||
{
|
||||
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)");
|
||||
accessorStream << "}";
|
||||
accessorStream << "\t}\n";
|
||||
|
||||
accessorStream << "float getMetallic(MaterialFragmentParameter input) {\n";
|
||||
accessorStream << "\tfloat getMetallic(MaterialFragmentParameter input) {\n";
|
||||
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)");
|
||||
accessorStream << "}";
|
||||
accessorStream << "\t}\n";
|
||||
|
||||
accessorStream << "float getSpecular(MaterialFragmentParameter input) {\n";
|
||||
accessorStream << "\tfloat getSpecular(MaterialFragmentParameter input) {\n";
|
||||
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");
|
||||
accessorStream << "}";
|
||||
accessorStream << "\t}\n";
|
||||
|
||||
accessorStream << "float getSheen(MaterialFragmentParameter input) {\n";
|
||||
accessorStream << "\tfloat getSheen(MaterialFragmentParameter input) {\n";
|
||||
generateAccessor(accessorStream, "sheen", "0.f");
|
||||
accessorStream << "}";
|
||||
accessorStream << "\t}\n";
|
||||
|
||||
/*accessorStream << "float getSpecularTint(MaterialFragmentParameter input) {\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";
|
||||
accessorStream << "\tfloat3 getWorldOffset() {\n";
|
||||
generateAccessor(accessorStream, "worldOffset", "0.f");
|
||||
accessorStream << "}";
|
||||
accessorStream << "\t}\n";
|
||||
|
||||
codeStream << accessorStream.str();
|
||||
|
||||
codeStream << "typedef " << name << " BRDF;" << std::endl;
|
||||
codeStream << name << " prepare(MaterialFragmentParameter geometry){" << std::endl;
|
||||
codeStream << name << " result;" << std::endl;
|
||||
codeStream << "result.baseColor = getBaseColor(geometry);" << std::endl;
|
||||
codeStream << "result.metallic = getMetallic(geometry);" << std::endl;
|
||||
codeStream << "result.normal = getNormal(geometry);" << std::endl;
|
||||
codeStream << "result.specular = getSpecular(geometry);" << std::endl;
|
||||
codeStream << "result.roughness = getRoughness(geometry);" << std::endl;
|
||||
codeStream << "result.sheen = getSheen(geometry);" << std::endl;
|
||||
codeStream << "return result;" << std::endl;
|
||||
codeStream << "}" << std::endl;
|
||||
codeStream << "\ttypedef " << name << " BRDF;" << std::endl;
|
||||
codeStream << "\t" << name << " prepare(MaterialFragmentParameter geometry) {" << std::endl;
|
||||
codeStream << "\t\t" << name << " result;" << std::endl;
|
||||
codeStream << "\t\tresult.baseColor = getBaseColor(geometry);" << std::endl;
|
||||
codeStream << "\t\tresult.metallic = getMetallic(geometry);" << std::endl;
|
||||
codeStream << "\t\tresult.normal = getNormal(geometry);" << std::endl;
|
||||
codeStream << "\t\tresult.specular = getSpecular(geometry);" << std::endl;
|
||||
codeStream << "\t\tresult.roughness = getRoughness(geometry);" << std::endl;
|
||||
codeStream << "\t\tresult.sheen = getSheen(geometry);" << std::endl;
|
||||
codeStream << "\t\treturn result;" << std::endl;
|
||||
codeStream << "\t}" << std::endl;
|
||||
}
|
||||
|
||||
IMPLEMENT_BRDF(BlinnPhong)
|
||||
@@ -56,9 +56,9 @@ void Material::compile()
|
||||
codeStream << "import VERTEX_INPUT_IMPORT;" << std::endl;
|
||||
codeStream << "import Material;" << 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 bindingCounter = 0; // Uniform buffers are always binding 0
|
||||
uniformBinding = -1;
|
||||
@@ -69,7 +69,7 @@ void Material::compile()
|
||||
if(type.compare("float") == 0)
|
||||
{
|
||||
PFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, 0);
|
||||
codeStream << "layout(offset = " << uniformBufferOffset << ")";
|
||||
codeStream << "\tlayout(offset = " << uniformBufferOffset << ")";
|
||||
if(uniformBinding == -1)
|
||||
{
|
||||
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
@@ -85,7 +85,7 @@ void Material::compile()
|
||||
else if(type.compare("float3") == 0)
|
||||
{
|
||||
PVectorParameter p = new VectorParameter(param.key(), uniformBufferOffset, 0);
|
||||
codeStream << "layout(offset = " << uniformBufferOffset << ")";
|
||||
codeStream << "\tlayout(offset = " << uniformBufferOffset << ")";
|
||||
if(uniformBinding == -1)
|
||||
{
|
||||
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
@@ -105,7 +105,6 @@ void Material::compile()
|
||||
if(defaultValue != param.value().end())
|
||||
{
|
||||
std::string defaultString = defaultValue.value().get<std::string>();
|
||||
std::cout << "Texture parameter " << defaultString << std::endl;
|
||||
p->data = AssetRegistry::findTexture(defaultString);
|
||||
}
|
||||
else
|
||||
@@ -127,7 +126,7 @@ void Material::compile()
|
||||
{
|
||||
std::cout << "Error unsupported parameter type" << std::endl;
|
||||
}
|
||||
codeStream << type << " " << param.key() << ";\n";
|
||||
codeStream << "\t" << type << " " << param.key() << ";\n";
|
||||
}
|
||||
uniformDataSize = uniformBufferOffset;
|
||||
if(uniformDataSize != 0)
|
||||
|
||||
@@ -150,7 +150,14 @@ bool Transform::equals(const Transform &other, float tolerance)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -191,5 +198,5 @@ Transform Transform::operator*(const Transform &other) const
|
||||
{
|
||||
Transform outTransform;
|
||||
multiply(&outTransform, this, &other);
|
||||
return std::move(outTransform);
|
||||
return outTransform;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ Scene::~Scene()
|
||||
void Scene::tick(double deltaTime)
|
||||
{
|
||||
updater->runUpdates(static_cast<float>(deltaTime));
|
||||
for(auto &&meshBatch : staticMeshes)
|
||||
{
|
||||
meshBatch.material->updateDescriptorData();
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::addActor(PActor actor)
|
||||
|
||||
Reference in New Issue
Block a user