Shaders are not compiling anymore...

This commit is contained in:
Dynamitos
2023-12-02 10:55:00 +01:00
parent 9114a6f252
commit 6c156d3bc2
23 changed files with 190 additions and 148 deletions
+1 -1
+1 -2
View File
@@ -17,10 +17,9 @@ ParameterBlock<LightCullingData> pLightCullingData;
[shader("pixel")]
float4 fragmentMain(in FragmentParameter params) : SV_Target
{
MaterialParameter materialParams = params.getMaterialParameter();
LightingParameter lightingParams = params.getLightingParameter();
let brdf = pMaterial.prepare(materialParams);
let brdf = pMaterial.prepare(params.getMaterialParameter());
float3 result = float3(0, 0, 0);
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
{
+1 -1
View File
@@ -30,7 +30,7 @@ struct BlinnPhong : IBRDF
float3 h = lightDir_WS + viewDir_WS;
float specular = dot(normal_WS, h);
return lightDir_WS * 2 + float3(1, 1, 1);//baseColor * (diffuse + specular) * lightColor;
return baseColor * (diffuse + specular) * lightColor;
}
};
+4 -3
View File
@@ -35,14 +35,15 @@ struct Frustum
Plane basePlane;
bool pointInside(float3 point)
{
if (dot(basePlane.n, point) + basePlane.d < 0)
float result = dot(basePlane.n, point) + basePlane.d;
if (0.0f > result)
{
return false;
}
for(int p = 0; p < 4; ++p)
{
float result = dot(sides[p].n, point) + sides[p].d;
if(result < 0)
result = dot(sides[p].n, point) + sides[p].d;
if(0.0f > result)
{
return false;
}
+1 -1
View File
@@ -28,7 +28,7 @@ struct PointLight : ILightEnv
float3 lightDir_WS = position_WS.xyz - params.position_WS;
float d = length(lightDir_WS);
float illuminance = max(1 - d / colorRange.w, 0);
return brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
return illuminance * brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
}
bool insidePlane(Plane plane)
+53 -34
View File
@@ -48,48 +48,67 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
{
aiMaterial* material = scene->mMaterials[i];
json matCode;
std::string materialName = std::format("{0}{1}", baseName, material->GetName().C_Str());
std::string materialName = std::format("{0}{1}{2}", baseName, material->GetName().C_Str(), char(i+'a'));
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later
matCode["name"] = materialName;
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
aiString texPath;
//TODO make samplers based on used textures
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
{
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
matCode["params"]["diffuseTexture"] =
{
{"type", "Texture2D"},
{"default", texFilename}
};
matCode["params"]["diffuseSampler"] =
auto texFilename = std::filesystem::path(texPath.C_Str()).stem();
if (texFilename == "white")
{
{"type", "SamplerState"}
};
matCode["code"].push_back(
matCode["code"].push_back(
{
{ "exp", "BRDF" },
{ "profile", "BlinnPhong" },
{ "values", {
{"baseColor", "float3(1, 1, 1)"}
}}
}
);
}
else
{
AssetImporter::importTexture(TextureImportArgs{
.filePath = meshDirectory / texPath.C_Str(),
.importPath = importPath,
});
matCode["params"]["diffuseTexture"] =
{
{ "exp", "Sample" },
{ "texture", "diffuseTexture" },
{ "sampler", "diffuseSampler" },
{ "coords", "input.texCoords[0]"}
}
);
matCode["code"].push_back(
{"type", "Texture2D"},
{"default", texFilename.string()}
};
matCode["params"]["diffuseSampler"] =
{
{ "exp", "Swizzle" },
{ "target", 0 },
{ "comp", json::array({0, 1, 2}) },
}
);
matCode["code"].push_back(
{
{ "exp", "BRDF" },
{ "profile", "BlinnPhong" },
{ "values", {
{"baseColor", 1}
}}
}
);
{"type", "Sampler"}
};
matCode["code"].push_back(
{
{ "exp", "Sample" },
{ "texture", "diffuseTexture" },
{ "sampler", "diffuseSampler" },
{ "coords", "input.texCoords[0]"}
}
);
matCode["code"].push_back(
{
{ "exp", "Swizzle" },
{ "target", 0 },
{ "comp", json::array({0, 1, 2}) },
}
);
matCode["code"].push_back(
{
{ "exp", "BRDF" },
{ "profile", "BlinnPhong" },
{ "values", {
{"baseColor", 1}
}}
}
);
}
}
else
{
@@ -109,7 +128,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
{
}
std::string outMatFilename = matCode["name"].get<std::string>().append(".json");
std::string outMatFilename = materialName.append(".json");
std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename);
outMatFile << std::setw(4) << matCode;
outMatFile.flush();
+23 -13
View File
@@ -58,6 +58,9 @@ int main()
AssetImporter::importMesh(MeshImportArgs{
.filePath= sourcePath / "old_resources/models/cube.fbx",
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "old_resources/models/sponza/sponza.gltf",
});
//AssetImporter::importMesh(MeshImportArgs{
// .filePath= sourcePath / "old_resources/models/flameThrower.fbx",
// });
@@ -238,21 +241,28 @@ int main()
//window->addView(inspectorView);
sceneView->setFocused();
window->render();
//export game
std::filesystem::create_directories(outputPath);
std::system(std::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" -DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath.generic_string(), binaryPath.generic_string()).c_str());
std::system(std::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str());
std::system(std::format("cmake --build {}", cmakePath.generic_string()).c_str());
std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive);
std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive);
std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive);
while (windowManager->isActive())
{
windowManager->render();
}
vd->~StaticMeshVertexData();
//export game
if (false)
{
std::filesystem::create_directories(outputPath);
std::system(std::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" -DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath.generic_string(), binaryPath.generic_string()).c_str());
std::system(std::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str());
std::system(std::format("cmake --build {}", cmakePath.generic_string()).c_str());
std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive);
std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive);
std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive);
#ifdef WIN32
std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll");
std::filesystem::copy_file("slang.dll", outputPath / "slang.dll");
std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll");
std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll");
std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll");
std::filesystem::copy_file("slang.dll", outputPath / "slang.dll");
std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll");
std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll");
#endif
}
return 0;
}
+7 -34
View File
@@ -3,34 +3,6 @@
using namespace Seele;
using namespace Seele::Gfx;
DescriptorBinding::DescriptorBinding()
: binding(0)
, descriptorType(SE_DESCRIPTOR_TYPE_MAX_ENUM)
, descriptorCount(0x7fff)
, shaderStages(SE_SHADER_STAGE_ALL)
{
}
DescriptorBinding::DescriptorBinding(const DescriptorBinding& other)
: binding(other.binding)
, descriptorType(other.descriptorType)
, descriptorCount(other.descriptorCount)
, shaderStages(other.shaderStages)
{
}
DescriptorBinding& DescriptorBinding::operator=(const DescriptorBinding& other)
{
if (this != &other)
{
binding = other.binding;
descriptorType = other.descriptorType;
descriptorCount = other.descriptorCount;
shaderStages = other.shaderStages;
}
return *this;
}
DescriptorPool::DescriptorPool()
{
}
@@ -77,12 +49,13 @@ void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorTyp
{
descriptorBindings.resize(bindingIndex + 1);
}
DescriptorBinding& binding = descriptorBindings[bindingIndex];
binding.binding = bindingIndex;
binding.descriptorType = type;
binding.descriptorCount = arrayCount;
binding.bindingFlags = bindingFlags;
binding.shaderStages = shaderStages;
descriptorBindings[bindingIndex] = DescriptorBinding{
.binding = bindingIndex,
.descriptorType = type,
.descriptorCount = arrayCount,
.bindingFlags = bindingFlags,
.shaderStages = shaderStages,
};
}
PDescriptorSet DescriptorLayout::allocateDescriptorSet()
+5 -9
View File
@@ -6,17 +6,13 @@ namespace Seele
{
namespace Gfx
{
class DescriptorBinding
struct DescriptorBinding
{
public:
DescriptorBinding();
DescriptorBinding(const DescriptorBinding& other);
DescriptorBinding& operator=(const DescriptorBinding& other);
uint32 binding;
SeDescriptorType descriptorType;
uint32 descriptorCount;
uint32 binding = 0;
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_MAX_ENUM;
uint32 descriptorCount = 0x7fff;
SeDescriptorBindingFlags bindingFlags = 0;
SeShaderStageFlags shaderStages;
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
};
DEFINE_REF(DescriptorBinding)
-1
View File
@@ -1,6 +1,5 @@
#include "Graphics.h"
#include "Shader.h"
#include "Graphics.h"
using namespace Seele::Gfx;
+1 -11
View File
@@ -66,7 +66,6 @@ Allocation::Allocation(PGraphics graphics, PAllocator pool, VkDeviceSize size, u
Allocation::~Allocation()
{
vkFreeMemory(device, allocatedMemory, nullptr);
assert(bytesUsed == 0);
}
OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDeviceSize alignment)
@@ -177,16 +176,6 @@ Allocator::Allocator(PGraphics graphics)
Allocator::~Allocator()
{
for (auto& heap : heaps)
{
for (auto& alloc : heap.allocations)
{
assert(alloc->activeAllocations.empty());
assert(alloc->freeRanges.size() == 1);
}
heap.allocations.clear();
}
graphics = nullptr;
}
OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo)
@@ -272,6 +261,7 @@ StagingBuffer::~StagingBuffer()
graphics->getDedicatedTransferCommands()->getCommands(), buffer);
graphics->getDestructionManager()->queueAllocation(
graphics->getDedicatedTransferCommands()->getCommands(), std::move(allocation));
graphics->getDedicatedTransferCommands()->submitCommands();
}
void* StagingBuffer::map()
+4
View File
@@ -469,6 +469,10 @@ CommandPool::CommandPool(PGraphics graphics, PQueue queue)
CommandPool::~CommandPool()
{
vkDeviceWaitIdle(graphics->getDevice());
for (auto& command : allocatedBuffers)
{
command->checkFence();
}
allocatedRenderCommands.clear();
allocatedComputeCommands.clear();
allocatedBuffers.clear();
+9 -2
View File
@@ -2,6 +2,7 @@
#include "Graphics.h"
#include "Texture.h"
#include "Buffer.h"
#include "Command.h"
using namespace Seele;
using namespace Seele::Vulkan;
@@ -345,8 +346,14 @@ DescriptorPool::DescriptorPool(PGraphics graphics, DescriptorLayout &layout)
DescriptorPool::~DescriptorPool()
{
vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr);
graphics = nullptr;
for (uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex)
{
if (cachedHandles[setIndex] != nullptr && cachedHandles[setIndex]->setHandle != VK_NULL_HANDLE)
{
graphics->getDestructionManager()->queueDescriptorSet(graphics->getGraphicsCommands()->getCommands(), Pair<VkDescriptorSet, VkDescriptorPool>(cachedHandles[setIndex]->setHandle, poolHandle));
}
}
graphics->getDestructionManager()->queueDescriptorPool(graphics->getGraphicsCommands()->getCommands(), poolHandle);
if(nextAlloc)
{
delete nextAlloc;
+11
View File
@@ -32,6 +32,17 @@ Graphics::Graphics()
Graphics::~Graphics()
{
vkDeviceWaitIdle(handle);
graphicsCommands = nullptr;
computeCommands = nullptr;
transferCommands = nullptr;
dedicatedTransferCommands = nullptr;
pipelineCache = nullptr;
allocator = nullptr;
destructionManager = nullptr;
stagingManager = nullptr;
allocatedFramebuffers.clear();
shaderCompiler = nullptr;
vkDestroyDevice(handle, nullptr);
DestroyDebugReportCallbackEXT(instance, nullptr, callback);
vkDestroyInstance(instance, nullptr);
+1 -1
View File
@@ -85,7 +85,6 @@ protected:
OQueue computeQueue;
OQueue transferQueue;
OQueue dedicatedTransferQueue;
OPipelineCache pipelineCache;
thread_local static OCommandPool graphicsCommands;
thread_local static OCommandPool computeCommands;
thread_local static OCommandPool transferCommands;
@@ -96,6 +95,7 @@ protected:
VkDebugReportCallbackEXT callback;
Map<uint32, OFramebuffer> allocatedFramebuffers;
OAllocator allocator;
OPipelineCache pipelineCache;
OStagingManager stagingManager;
ODestructionManager destructionManager;
+2 -2
View File
@@ -37,9 +37,9 @@ PipelineCache::PipelineCache(PGraphics graphics, const std::string& cacheFilePat
PipelineCache::~PipelineCache()
{
VkDeviceSize cacheSize;
vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, nullptr);
VK_CHECK(vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, nullptr));
Array<uint8> cacheData(cacheSize);
vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, cacheData.data());
VK_CHECK(vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, cacheData.data()));
std::ofstream stream(cacheFile, std::ios::binary);
stream.write((char*)cacheData.data(), cacheSize);
stream.flush();
+3 -2
View File
@@ -2,7 +2,8 @@
#include "Graphics.h"
#include "Framebuffer.h"
#include "Texture.h"
#include "RenderPass.h"
#include "Resources.h"
#include "Command.h"
using namespace Seele;
using namespace Seele::Vulkan;
@@ -125,7 +126,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx
RenderPass::~RenderPass()
{
vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr);
graphics->getDestructionManager()->queueRenderPass(graphics->getGraphicsCommands()->getCommands(), renderPass);
}
uint32 RenderPass::getFramebufferHash()
+29 -1
View File
@@ -20,7 +20,7 @@ Semaphore::Semaphore(PGraphics graphics)
Semaphore::~Semaphore()
{
graphics->getDestructionManager()->queueSemaphore(graphics->getGraphicsCommands()->getCommands(), handle);
vkDestroySemaphore(graphics->getDevice(), handle, nullptr);
}
Fence::Fence(PGraphics graphics)
@@ -114,6 +114,21 @@ void DestructionManager::queueSemaphore(PCommand cmd, VkSemaphore sem)
sems[cmd].add(sem);
}
void DestructionManager::queueRenderPass(PCommand cmd, VkRenderPass renderPass)
{
renderPasses[cmd].add(renderPass);
}
void DestructionManager::queueDescriptorPool(PCommand cmd, VkDescriptorPool pool)
{
pools[cmd].add(pool);
}
void DestructionManager::queueDescriptorSet(PCommand cmd, Pair<VkDescriptorSet, VkDescriptorPool> set)
{
sets[cmd].add(set);
}
void DestructionManager::queueAllocation(PCommand cmd, OSubAllocation alloc)
{
allocs[cmd].add(std::move(alloc));
@@ -137,9 +152,22 @@ void DestructionManager::notifyCmdComplete(PCommand cmd)
{
vkDestroySemaphore(graphics->getDevice(), sem, nullptr);
}
for (auto [set, pool] : sets[cmd])
{
vkFreeDescriptorSets(graphics->getDevice(), pool, 1, &set);
}
for (auto pool : pools[cmd])
{
vkDestroyDescriptorPool(graphics->getDevice(), pool, nullptr);
}
for (auto renderPass : renderPasses[cmd])
{
vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr);
}
buffers[cmd].clear();
images[cmd].clear();
views[cmd].clear();
sems[cmd].clear();
renderPasses[cmd].clear();
allocs[cmd].clear();
}
+6
View File
@@ -61,6 +61,9 @@ public:
void queueImage(PCommand cmd, VkImage image);
void queueImageView(PCommand cmd, VkImageView view);
void queueSemaphore(PCommand cmd, VkSemaphore sem);
void queueRenderPass(PCommand cmd, VkRenderPass renderPass);
void queueDescriptorPool(PCommand cmd, VkDescriptorPool pool);
void queueDescriptorSet(PCommand cmd, Pair<VkDescriptorSet, VkDescriptorPool> set);
void queueAllocation(PCommand cmd, OSubAllocation alloc);
void notifyCmdComplete(PCommand cmdbuffer);
private:
@@ -69,6 +72,9 @@ private:
Map<PCommand, List<VkImage>> images;
Map<PCommand, List<VkImageView>> views;
Map<PCommand, List<VkSemaphore>> sems;
Map<PCommand, List<VkRenderPass>> renderPasses;
Map<PCommand, List<VkDescriptorPool>> pools;
Map<PCommand, List<Pair<VkDescriptorSet, VkDescriptorPool>>> sets;
Map<PCommand, List<OSubAllocation>> allocs;
};
DEFINE_REF(DestructionManager)
+4 -7
View File
@@ -55,12 +55,8 @@ void Shader::create(const ShaderCreateInfo& createInfo)
slang::TargetDesc vulkan;
vulkan.profile = globalSession->findProfile("sm_6_6");
vulkan.format = SLANG_SPIRV;
slang::TargetDesc glsl;
glsl.profile = globalSession->findProfile("sm_6_6");
glsl.format = SLANG_GLSL;
slang::TargetDesc targets[2] = { vulkan, glsl };
sessionDesc.targetCount = 2;
sessionDesc.targets = targets;
sessionDesc.targetCount = 1;
sessionDesc.targets = &vulkan;
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
sessionDesc.searchPaths = searchPaths.data();
sessionDesc.searchPathCount = searchPaths.size();
@@ -136,7 +132,7 @@ void Shader::create(const ShaderCreateInfo& createInfo)
hash = CRC::Calculate(entryPointName.data(), entryPointName.size(), CRC::CRC_32());
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
/*
specializedComponent->getEntryPointCode(
0,
1,
@@ -147,4 +143,5 @@ void Shader::create(const ShaderCreateInfo& createInfo)
std::ofstream shaderStream(createInfo.name + createInfo.entryPoint + ".glsl");
shaderStream << (char*)kernelBlob->getBufferPointer();
shaderStream.close();
*/
}
+8 -11
View File
@@ -22,19 +22,16 @@ void Window::addView(PView view)
void Window::render()
{
while(owner->isActive())
gfxHandle->beginFrame();
for(auto& view : views)
{
gfxHandle->beginFrame();
for(auto& view : views)
{
view->beginUpdate();
view->update();
view->commitUpdate();
view->prepareRender();
view->render();
}
gfxHandle->endFrame();
view->beginUpdate();
view->update();
view->commitUpdate();
view->prepareRender();
view->render();
}
gfxHandle->endFrame();
}
Gfx::PWindow Window::getGfxHandle()
+12 -9
View File
@@ -11,19 +11,22 @@ WindowManager::~WindowManager()
{
}
PWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo)
OWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo)
{
OWindow window = new Window(this, graphics->createWindow(createInfo));
PWindow ref = window;
windows.add(std::move(window));
return ref;
windows.add(window);
return window;
}
void WindowManager::render()
{
for (auto& window : windows)
{
window->render();
}
}
void WindowManager::notifyWindowClosed(PWindow window)
{
windows.remove(windows.find([window] (const OWindow& w) { return window == w; }));
if(windows.empty())
{
exit(0);
}
windows.remove(window);
}
+4 -3
View File
@@ -10,15 +10,16 @@ class WindowManager
public:
WindowManager();
~WindowManager();
PWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo);
OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo);
void render();
void notifyWindowClosed(PWindow window);
inline bool isActive() const
bool isActive() const
{
return windows.size();
}
private:
Array<OWindow> windows;
Array<PWindow> windows;
};
DEFINE_REF(WindowManager)
} // namespace Seele