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 -2
View File
@@ -8,8 +8,8 @@ namespace Gfx {
struct DescriptorBinding {
uint32 binding = 0;
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
SeImageViewType textureType;
uint32 descriptorCount = 0x7fff;
SeImageViewType textureType = SE_IMAGE_VIEW_TYPE_2D;
uint32 descriptorCount = 1;
SeDescriptorBindingFlags bindingFlags = 0;
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
Gfx::SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT;
@@ -123,13 +123,6 @@ void LightCullingPass::publishOutputs()
cullingLayout->addDescriptorLayout(dispatchParamsLayout);
cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
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 = {
.name = "Culling",
@@ -139,6 +132,7 @@ void LightCullingPass::publishOutputs()
.rootSignature = cullingLayout,
};
cullingShader = graphics->createComputeShader(createInfo);
cullingLayout->create();
Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = cullingShader;
@@ -215,15 +209,9 @@ void LightCullingPass::setupFrustums()
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
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->create();
frustumLayout = graphics->createPipelineLayout("FrustumLayout");
frustumLayout->addDescriptorLayout(viewParamsLayout);
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
Map<std::string, uint32> mapping;
mapping["pViewParams"] = 0;
mapping["pDispatchParams"] = 1;
frustumLayout->addMapping(mapping);
frustumLayout->create();
ShaderCreateInfo createInfo = {
.name = "Frustum",
.mainModule = "ComputeFrustums",
@@ -233,6 +221,9 @@ void LightCullingPass::setupFrustums()
};
std::cout << "Compiling frustumShader" << std::endl;
frustumShader = graphics->createComputeShader(createInfo);
// Have to compile shader before finalizing layout as parameters get mapped later
frustumLayout->create();
dispatchParamsLayout->create();
Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = frustumShader;
-13
View File
@@ -81,14 +81,6 @@ void ShaderCompiler::compile()
layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout());
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());
createShaders(permutation, std::move(layout));
}
@@ -98,11 +90,6 @@ void ShaderCompiler::compile()
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout());
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));
}
}
+2 -14
View File
@@ -28,11 +28,11 @@ uint32 Seele::Vulkan::Shader::getShaderHash() const
return hash;
}
void Shader::create(const ShaderCreateInfo& createInfo)
void Shader::create(ShaderCreateInfo createInfo)
{
Map<std::string, uint32> 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 =
{
.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));
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);
virtual ~Shader();
void create(const ShaderCreateInfo& createInfo);
void create(ShaderCreateInfo createInfo);
constexpr VkShaderModule getModuleHandle() const
{
+15 -16
View File
@@ -16,13 +16,17 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
}
slang::SessionDesc sessionDesc;
sessionDesc.flags = 0;
slang::CompilerOptionEntry option;
option.name = slang::CompilerOptionName::IgnoreCapabilities;
option.value = slang::CompilerOptionValue();
option.value.kind = slang::CompilerOptionValueKind::Int;
option.value.intValue0 = 1;
sessionDesc.compilerOptionEntries = &option;
sessionDesc.compilerOptionEntryCount = 1;
slang::CompilerOptionEntry option[2];
option[0].name = slang::CompilerOptionName::DumpIntermediates;
option[0].value = slang::CompilerOptionValue();
option[0].value.kind = slang::CompilerOptionValueKind::Int;
option[0].value.intValue0 = 1;
option[1].name = slang::CompilerOptionName::IgnoreCapabilities;
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;
Array<slang::PreprocessorMacroDesc> macros;
for(const auto& [key, val] : createInfo.defines)
@@ -37,8 +41,8 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
slang::TargetDesc targetDesc;
targetDesc.profile = globalSession->findProfile("sm_6_6");
targetDesc.format = target;
targetDesc.compilerOptionEntryCount = 1;
targetDesc.compilerOptionEntries = &option;
targetDesc.compilerOptionEntryCount = 2;
targetDesc.compilerOptionEntries = option;
sessionDesc.targetCount = 1;
sessionDesc.targets = &targetDesc;
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();
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
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)
{
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;
}