Fixing descriptors a little

This commit is contained in:
Dynamitos
2023-11-12 14:46:22 +01:00
parent a9ac3d14a7
commit c1e4891456
8 changed files with 35 additions and 47 deletions
+1 -1
+2 -2
View File
@@ -62,7 +62,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
// TODO: ALIGNMENT RULES
if(type.compare("float") == 0)
{
OFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, 0);
OFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, uniformBinding);
if(uniformBinding == -1)
{
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
@@ -79,7 +79,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
// TODO: ALIGNMENT RULES
else if(type.compare("float3") == 0)
{
OVectorParameter p = new VectorParameter(param.key(), uniformBufferOffset, 0);
OVectorParameter p = new VectorParameter(param.key(), uniformBufferOffset, uniformBinding);
if(uniformBinding == -1)
{
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
+5 -5
View File
@@ -54,10 +54,6 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
aiString texPath;
//TODO make samplers based on used textures
matCode["params"]["textureSampler"] =
{
{"type", "SamplerState"}
};
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
{
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
@@ -66,11 +62,15 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
{"type", "Texture2D"},
{"default", texFilename}
};
matCode["params"]["diffuseSampler"] =
{
{"type", "SamplerState"}
};
matCode["code"].push_back(
{
{ "exp", "Sample" },
{ "texture", "diffuseTexture" },
{ "sampler", "textureSampler" },
{ "sampler", "diffuseSampler" },
{ "coords", "input.texCoords[0]"}
}
);
@@ -331,9 +331,11 @@ Gfx::PDescriptorSet DescriptorAllocator::allocateDescriptorSet()
counts = binding.descriptorCount;
}
}
if (layout.bindings.size() > 0)
{
setCounts.pDescriptorCounts = &counts;
allocInfo.pNext = &setCounts;
}
for(uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex)
{
if(cachedHandles[setIndex] == nullptr)
+16 -32
View File
@@ -27,6 +27,9 @@ uint32 Seele::Vulkan::Shader::getShaderHash() const
return hash;
}
#define CHECK_RESULT(x) {SlangResult r = x; if(r != 0) {throw std::runtime_error(std::format("Error: {0}", r));}}
#define CHECK_DIAGNOSTICS() {if(diagnostics) {std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; assert(false);}}
void Shader::create(const ShaderCreateInfo& createInfo)
{
entryPointName = createInfo.entryPoint;
@@ -58,7 +61,7 @@ void Shader::create(const ShaderCreateInfo& createInfo)
sessionDesc.searchPathCount = searchPaths.size();
Slang::ComPtr<slang::ISession> session;
globalSession->createSession(sessionDesc, session.writeRef());
CHECK_RESULT(globalSession->createSession(sessionDesc, session.writeRef()));
Slang::ComPtr<slang::IBlob> diagnostics;
Array<slang::IComponentType*> modules;
@@ -71,16 +74,10 @@ void Shader::create(const ShaderCreateInfo& createInfo)
{
mainModule = (slang::IModule*)modules.back();
}
if(diagnostics)
{
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
CHECK_DIAGNOSTICS();
}
if(diagnostics)
{
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
CHECK_DIAGNOSTICS();
mainModule->findEntryPointByName(createInfo.entryPoint.c_str(), entrypoint.writeRef());
modules.add(entrypoint);
@@ -88,23 +85,16 @@ void Shader::create(const ShaderCreateInfo& createInfo)
Slang::ComPtr<slang::IComponentType> moduleComposition;
session->createCompositeComponentType(modules.data(), modules.size(), moduleComposition.writeRef(), diagnostics.writeRef());
if(diagnostics)
{
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
CHECK_DIAGNOSTICS();
Slang::ComPtr<slang::IComponentType> linkedProgram;
moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef());
if(diagnostics)
{
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
CHECK_DIAGNOSTICS();
slang::ProgramLayout* reflection = linkedProgram->getLayout(0, diagnostics.writeRef());
if(diagnostics)
{
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
CHECK_DIAGNOSTICS();
Array<slang::SpecializationArg> specialization;
for(const auto& [key, value] : createInfo.typeParameter)
@@ -113,10 +103,8 @@ void Shader::create(const ShaderCreateInfo& createInfo)
}
Slang::ComPtr<slang::IComponentType> specializedComponent;
linkedProgram->specialize(specialization.data(), specialization.size(), specializedComponent.writeRef(), diagnostics.writeRef());
if(diagnostics)
{
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
CHECK_DIAGNOSTICS();
Slang::ComPtr<slang::IBlob> kernelBlob;
specializedComponent->getEntryPointCode(
0,
@@ -124,16 +112,13 @@ void Shader::create(const ShaderCreateInfo& createInfo)
kernelBlob.writeRef(),
diagnostics.writeRef()
);
if(diagnostics)
{
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
}
CHECK_DIAGNOSTICS();
for (uint32 i = 0; i < reflection->getParameterCount(); ++i)
{
slang::VariableLayoutReflection* varLayout = reflection->getParameterByIndex(i);
std::cout << varLayout->getName() << " in space " << varLayout->getBindingSpace() << " index " << varLayout->getBindingIndex() << std::endl;
//std::cout << varLayout->getName() << " in space " << varLayout->getBindingSpace() << " index " << varLayout->getBindingIndex() << std::endl;
}
std::cout << reflection->getGlobalConstantBufferSize() << std::endl;
VkShaderModuleCreateInfo moduleInfo =
{
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
@@ -146,5 +131,4 @@ 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);
std::cout << "Creating Shader" << std::endl;
}
+1 -1
View File
@@ -39,6 +39,7 @@ MaterialInstance::MaterialInstance(uint64 id,
OShaderParameter param;
Serialization::load(buffer, param);
parameters.add(std::move(param));
buffer.rewind();
}
}
@@ -50,7 +51,6 @@ MaterialInstance::~MaterialInstance()
void MaterialInstance::updateDescriptor()
{
Gfx::PDescriptorLayout layout = baseMaterial->getMaterial()->getDescriptorLayout();
layout->reset();
descriptor = layout->allocateDescriptorSet();
for (auto& param : parameters)
{
-2
View File
@@ -79,7 +79,6 @@ std::string ShaderParameter::evaluate(Map<std::string, std::string>& varState) c
void ShaderParameter::save(ArchiveBuffer& buffer) const
{
ShaderExpression::save(buffer);
Serialization::save(buffer, key);
Serialization::save(buffer, byteOffset);
Serialization::save(buffer, binding);
}
@@ -87,7 +86,6 @@ void ShaderParameter::save(ArchiveBuffer& buffer) const
void ShaderParameter::load(ArchiveBuffer& buffer)
{
ShaderExpression::load(buffer);
Serialization::load(buffer, key);
Serialization::load(buffer, byteOffset);
Serialization::load(buffer, binding);
}
+4
View File
@@ -60,6 +60,10 @@ void LightEnvironment::addPointLight(Component::PointLight pointLight)
void LightEnvironment::commit()
{
dirs.add(Component::DirectionalLight{
.color = Vector4(1, 1, 1, 1),
.direction = Vector4(1, 0, 1, 0),
});
lightEnv.numDirectionalLights = dirs.size();
lightEnv.numPointLights = points.size();
lightEnvBuffer->updateContents(DataSource{