It finally works

This commit is contained in:
Dynamitos
2024-04-23 19:11:06 +02:00
parent 80963edfd4
commit 72336aa64f
15 changed files with 31 additions and 74 deletions
+2
View File
@@ -125,6 +125,8 @@ add_subdirectory(src/)
if(WIN32) if(WIN32)
add_custom_target(dll_copy ALL add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor> COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_ROOT}/slang.dll $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_ROOT}/slang-glslang.dll $<TARGET_FILE_DIR:Editor>
COMMAND_EXPAND_LISTS COMMAND_EXPAND_LISTS
DEPENDS Editor) DEPENDS Editor)
elseif(APPLE) elseif(APPLE)
+1 -1
Submodule external/slang updated: 8362c2d46e...484c1e618d
+1 -1
View File
@@ -22,7 +22,7 @@ struct CullingParams
RWTexture2D<uint2> oLightGrid; RWTexture2D<uint2> oLightGrid;
RWTexture2D<uint2> tLightGrid; RWTexture2D<uint2> tLightGrid;
}; };
layout(set=2)
ParameterBlock<CullingParams> pCullingParams; ParameterBlock<CullingParams> pCullingParams;
// Debug // Debug
//Texture2D lightCountHeatMap; //Texture2D lightCountHeatMap;
-6
View File
@@ -65,12 +65,6 @@ struct PrimitiveAttributes
uint cull: SV_CullPrimitive; uint cull: SV_CullPrimitive;
}; };
uint unpackPrimitiveIndices(uint index)
{
uint32_t packed = pScene.primitiveIndices[index / 4];
return (packed >> (index % 4)) & 0xff;
}
[numthreads(MESH_GROUP_SIZE, 1, 1)] [numthreads(MESH_GROUP_SIZE, 1, 1)]
[outputtopology("triangle")] [outputtopology("triangle")]
[shader("mesh")] [shader("mesh")]
+1 -1
View File
@@ -10,7 +10,7 @@ struct ViewParameter
float4 cameraPos_WS; float4 cameraPos_WS;
float2 screenDimensions; float2 screenDimensions;
} }
uniform ParameterBlock<ViewParameter> pViewParams; ParameterBlock<ViewParameter> pViewParams;
float4 clipToView(float4 clip) float4 clipToView(float4 clip)
{ {
-1
View File
@@ -8,5 +8,4 @@ struct DispatchParams
uint pad1; uint pad1;
RWStructuredBuffer<Frustum> frustums; RWStructuredBuffer<Frustum> frustums;
} }
layout(set=1)
ParameterBlock<DispatchParams> pDispatchParams; ParameterBlock<DispatchParams> pDispatchParams;
-1
View File
@@ -63,5 +63,4 @@ struct LightEnv
StructuredBuffer<PointLight> pointLights; StructuredBuffer<PointLight> pointLights;
uint numPointLights; uint numPointLights;
}; };
layout(set=3)
ParameterBlock<LightEnv> pLightEnv; ParameterBlock<LightEnv> pLightEnv;
-1
View File
@@ -8,5 +8,4 @@ interface IMaterial
BRDF prepare(MaterialParameter input); BRDF prepare(MaterialParameter input);
}; };
layout(set=4)
ParameterBlock<IMaterial> pMaterial; ParameterBlock<IMaterial> pMaterial;
+2 -3
View File
@@ -38,9 +38,8 @@ struct Scene
StructuredBuffer<InstanceData> instances; StructuredBuffer<InstanceData> instances;
StructuredBuffer<MeshData> meshData; StructuredBuffer<MeshData> meshData;
StructuredBuffer<MeshletDescription> meshletInfos; StructuredBuffer<MeshletDescription> meshletInfos;
// uint8_t is not valid in DXIL StructuredBuffer<uint8_t> primitiveIndices;
StructuredBuffer<uint32_t> primitiveIndices;
StructuredBuffer<uint32_t> vertexIndices; StructuredBuffer<uint32_t> vertexIndices;
}; };
uniform ParameterBlock<Scene> pScene; ParameterBlock<Scene> pScene;
+2 -2
View File
@@ -8,8 +8,8 @@ namespace Gfx {
struct DescriptorBinding { struct DescriptorBinding {
uint32 binding = 0; uint32 binding = 0;
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER; SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
SeImageViewType textureType; SeImageViewType textureType = SE_IMAGE_VIEW_TYPE_2D;
uint32 descriptorCount = 0x7fff; uint32 descriptorCount = 1;
SeDescriptorBindingFlags bindingFlags = 0; SeDescriptorBindingFlags bindingFlags = 0;
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL; SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
Gfx::SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT; Gfx::SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT;
@@ -123,13 +123,6 @@ void LightCullingPass::publishOutputs()
cullingLayout->addDescriptorLayout(dispatchParamsLayout); cullingLayout->addDescriptorLayout(dispatchParamsLayout);
cullingLayout->addDescriptorLayout(cullingDescriptorLayout); cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
cullingLayout->addDescriptorLayout(lightEnv->getDescriptorLayout()); cullingLayout->addDescriptorLayout(lightEnv->getDescriptorLayout());
Map<std::string, uint32> mapping;
mapping["pViewParams"] = 1;
mapping["pDispatchParams"] = 2;
mapping["pCullingParams"] = 0;
mapping["pLightEnv"] = 3;
cullingLayout->addMapping(mapping);
cullingLayout->create();
ShaderCreateInfo createInfo = { ShaderCreateInfo createInfo = {
.name = "Culling", .name = "Culling",
@@ -139,6 +132,7 @@ void LightCullingPass::publishOutputs()
.rootSignature = cullingLayout, .rootSignature = cullingLayout,
}; };
cullingShader = graphics->createComputeShader(createInfo); cullingShader = graphics->createComputeShader(createInfo);
cullingLayout->create();
Gfx::ComputePipelineCreateInfo pipelineInfo; Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = cullingShader; pipelineInfo.computeShader = cullingShader;
@@ -215,15 +209,9 @@ void LightCullingPass::setupFrustums()
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams"); dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, }); dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, });
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT }); dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT });
dispatchParamsLayout->create();
frustumLayout = graphics->createPipelineLayout("FrustumLayout"); frustumLayout = graphics->createPipelineLayout("FrustumLayout");
frustumLayout->addDescriptorLayout(viewParamsLayout); frustumLayout->addDescriptorLayout(viewParamsLayout);
frustumLayout->addDescriptorLayout(dispatchParamsLayout); frustumLayout->addDescriptorLayout(dispatchParamsLayout);
Map<std::string, uint32> mapping;
mapping["pViewParams"] = 0;
mapping["pDispatchParams"] = 1;
frustumLayout->addMapping(mapping);
frustumLayout->create();
ShaderCreateInfo createInfo = { ShaderCreateInfo createInfo = {
.name = "Frustum", .name = "Frustum",
.mainModule = "ComputeFrustums", .mainModule = "ComputeFrustums",
@@ -233,6 +221,9 @@ void LightCullingPass::setupFrustums()
}; };
std::cout << "Compiling frustumShader" << std::endl; std::cout << "Compiling frustumShader" << std::endl;
frustumShader = graphics->createComputeShader(createInfo); frustumShader = graphics->createComputeShader(createInfo);
// Have to compile shader before finalizing layout as parameters get mapped later
frustumLayout->create();
dispatchParamsLayout->create();
Gfx::ComputePipelineCreateInfo pipelineInfo; Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = frustumShader; pipelineInfo.computeShader = frustumShader;
-13
View File
@@ -81,14 +81,6 @@ void ShaderCompiler::compile()
layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout()); layout->addDescriptorLayout(vd->getInstanceDataLayout());
layout->addDescriptorLayout(mat->getDescriptorLayout()); layout->addDescriptorLayout(mat->getDescriptorLayout());
Map<std::string, uint32> mapping;
mapping["pLightCullingData"] = 1;
mapping["pMaterial"] = 2;
mapping["pViewParams"] = 3;
mapping["pVertexData"] = 4;
mapping["pScene"] = 5;
mapping["pLightEnv"] = 6;
layout->addMapping(mapping);
permutation.setMaterial(mat->getName()); permutation.setMaterial(mat->getName());
createShaders(permutation, std::move(layout)); createShaders(permutation, std::move(layout));
} }
@@ -98,11 +90,6 @@ void ShaderCompiler::compile()
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout); OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout()); layout->addDescriptorLayout(vd->getInstanceDataLayout());
Map<std::string, uint32> mapping;
mapping["pViewParams"] = 1;
mapping["pVertexData"] = 2;
mapping["pScene"] = 3;
layout->addMapping(mapping);
createShaders(permutation, std::move(layout)); createShaders(permutation, std::move(layout));
} }
} }
+2 -14
View File
@@ -28,11 +28,11 @@ uint32 Seele::Vulkan::Shader::getShaderHash() const
return hash; return hash;
} }
void Shader::create(const ShaderCreateInfo& createInfo) void Shader::create(ShaderCreateInfo createInfo)
{ {
Map<std::string, uint32> paramMapping; Map<std::string, uint32> paramMapping;
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_SPIRV, paramMapping); Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_SPIRV, paramMapping);
const_cast<Gfx::PipelineLayout*>(createInfo.rootSignature.getHandle())->addMapping(paramMapping); createInfo.rootSignature->addMapping(paramMapping);
VkShaderModuleCreateInfo moduleInfo = VkShaderModuleCreateInfo moduleInfo =
{ {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
@@ -44,16 +44,4 @@ void Shader::create(const ShaderCreateInfo& createInfo)
VK_CHECK(vkCreateShaderModule(graphics->getDevice(), &moduleInfo, nullptr, &module)); VK_CHECK(vkCreateShaderModule(graphics->getDevice(), &moduleInfo, nullptr, &module));
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash); hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
/*
specializedComponent->getEntryPointCode(
0,
1,
kernelBlob.writeRef(),
diagnostics.writeRef()
);
CHECK_DIAGNOSTICS();
std::ofstream shaderStream(createInfo.name + createInfo.entryPoint + ".glsl");
shaderStream << (char*)kernelBlob->getBufferPointer();
shaderStream.close();
*/
} }
+1 -1
View File
@@ -15,7 +15,7 @@ public:
Shader(PGraphics graphics, VkShaderStageFlags stage); Shader(PGraphics graphics, VkShaderStageFlags stage);
virtual ~Shader(); virtual ~Shader();
void create(const ShaderCreateInfo& createInfo); void create(ShaderCreateInfo createInfo);
constexpr VkShaderModule getModuleHandle() const constexpr VkShaderModule getModuleHandle() const
{ {
+15 -16
View File
@@ -16,13 +16,17 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
} }
slang::SessionDesc sessionDesc; slang::SessionDesc sessionDesc;
sessionDesc.flags = 0; sessionDesc.flags = 0;
slang::CompilerOptionEntry option; slang::CompilerOptionEntry option[2];
option.name = slang::CompilerOptionName::IgnoreCapabilities; option[0].name = slang::CompilerOptionName::DumpIntermediates;
option.value = slang::CompilerOptionValue(); option[0].value = slang::CompilerOptionValue();
option.value.kind = slang::CompilerOptionValueKind::Int; option[0].value.kind = slang::CompilerOptionValueKind::Int;
option.value.intValue0 = 1; option[0].value.intValue0 = 1;
sessionDesc.compilerOptionEntries = &option; option[1].name = slang::CompilerOptionName::IgnoreCapabilities;
sessionDesc.compilerOptionEntryCount = 1; option[1].value = slang::CompilerOptionValue();
option[1].value.kind = slang::CompilerOptionValueKind::Int;
option[1].value.intValue0 = 1;
sessionDesc.compilerOptionEntries = option;
sessionDesc.compilerOptionEntryCount = 2;
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR; sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
Array<slang::PreprocessorMacroDesc> macros; Array<slang::PreprocessorMacroDesc> macros;
for(const auto& [key, val] : createInfo.defines) for(const auto& [key, val] : createInfo.defines)
@@ -37,8 +41,8 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
slang::TargetDesc targetDesc; slang::TargetDesc targetDesc;
targetDesc.profile = globalSession->findProfile("sm_6_6"); targetDesc.profile = globalSession->findProfile("sm_6_6");
targetDesc.format = target; targetDesc.format = target;
targetDesc.compilerOptionEntryCount = 1; targetDesc.compilerOptionEntryCount = 2;
targetDesc.compilerOptionEntries = &option; targetDesc.compilerOptionEntries = option;
sessionDesc.targetCount = 1; sessionDesc.targetCount = 1;
sessionDesc.targets = &targetDesc; sessionDesc.targets = &targetDesc;
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"}; StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
@@ -99,16 +103,11 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
CHECK_DIAGNOSTICS(); CHECK_DIAGNOSTICS();
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef()); slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
CHECK_DIAGNOSTICS(); CHECK_DIAGNOSTICS();
auto entry = signature->findEntryPointByName(createInfo.entryPoint.c_str());
uint32 offset = 0;
if(target == SLANG_DXIL)
{
offset = 1;// idk why
}
for(size_t i = 0; i < signature->getParameterCount(); ++i) for(size_t i = 0; i < signature->getParameterCount(); ++i)
{ {
auto param = signature->getParameterByIndex(i); auto param = signature->getParameterByIndex(i);
paramMapping[param->getName()] = offset++; paramMapping[param->getName()] = param->getBindingIndex();
std::cout << "Parameter " << param->getName() << " index " << param->getBindingIndex() << std::endl;
} }
return kernelBlob; return kernelBlob;
} }