Fixing descriptors a little
This commit is contained in:
Vendored
+1
-1
Submodule external/slang updated: 4547125ce9...79677b8387
@@ -62,7 +62,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
// TODO: ALIGNMENT RULES
|
// TODO: ALIGNMENT RULES
|
||||||
if(type.compare("float") == 0)
|
if(type.compare("float") == 0)
|
||||||
{
|
{
|
||||||
OFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, 0);
|
OFloatParameter p = new FloatParameter(param.key(), uniformBufferOffset, uniformBinding);
|
||||||
if(uniformBinding == -1)
|
if(uniformBinding == -1)
|
||||||
{
|
{
|
||||||
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
@@ -79,7 +79,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
// TODO: ALIGNMENT RULES
|
// TODO: ALIGNMENT RULES
|
||||||
else if(type.compare("float3") == 0)
|
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)
|
if(uniformBinding == -1)
|
||||||
{
|
{
|
||||||
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
layout->addDescriptorBinding(bindingCounter, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
|
|||||||
@@ -54,10 +54,6 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
|
|||||||
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
|
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
|
||||||
aiString texPath;
|
aiString texPath;
|
||||||
//TODO make samplers based on used textures
|
//TODO make samplers based on used textures
|
||||||
matCode["params"]["textureSampler"] =
|
|
||||||
{
|
|
||||||
{"type", "SamplerState"}
|
|
||||||
};
|
|
||||||
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
|
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
|
||||||
{
|
{
|
||||||
std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string();
|
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"},
|
{"type", "Texture2D"},
|
||||||
{"default", texFilename}
|
{"default", texFilename}
|
||||||
};
|
};
|
||||||
|
matCode["params"]["diffuseSampler"] =
|
||||||
|
{
|
||||||
|
{"type", "SamplerState"}
|
||||||
|
};
|
||||||
matCode["code"].push_back(
|
matCode["code"].push_back(
|
||||||
{
|
{
|
||||||
{ "exp", "Sample" },
|
{ "exp", "Sample" },
|
||||||
{ "texture", "diffuseTexture" },
|
{ "texture", "diffuseTexture" },
|
||||||
{ "sampler", "textureSampler" },
|
{ "sampler", "diffuseSampler" },
|
||||||
{ "coords", "input.texCoords[0]"}
|
{ "coords", "input.texCoords[0]"}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -331,9 +331,11 @@ Gfx::PDescriptorSet DescriptorAllocator::allocateDescriptorSet()
|
|||||||
counts = binding.descriptorCount;
|
counts = binding.descriptorCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (layout.bindings.size() > 0)
|
||||||
|
{
|
||||||
setCounts.pDescriptorCounts = &counts;
|
setCounts.pDescriptorCounts = &counts;
|
||||||
allocInfo.pNext = &setCounts;
|
allocInfo.pNext = &setCounts;
|
||||||
|
}
|
||||||
for(uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex)
|
for(uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex)
|
||||||
{
|
{
|
||||||
if(cachedHandles[setIndex] == nullptr)
|
if(cachedHandles[setIndex] == nullptr)
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ uint32 Seele::Vulkan::Shader::getShaderHash() const
|
|||||||
return hash;
|
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)
|
void Shader::create(const ShaderCreateInfo& createInfo)
|
||||||
{
|
{
|
||||||
entryPointName = createInfo.entryPoint;
|
entryPointName = createInfo.entryPoint;
|
||||||
@@ -58,7 +61,7 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
|||||||
sessionDesc.searchPathCount = searchPaths.size();
|
sessionDesc.searchPathCount = searchPaths.size();
|
||||||
|
|
||||||
Slang::ComPtr<slang::ISession> session;
|
Slang::ComPtr<slang::ISession> session;
|
||||||
globalSession->createSession(sessionDesc, session.writeRef());
|
CHECK_RESULT(globalSession->createSession(sessionDesc, session.writeRef()));
|
||||||
|
|
||||||
Slang::ComPtr<slang::IBlob> diagnostics;
|
Slang::ComPtr<slang::IBlob> diagnostics;
|
||||||
Array<slang::IComponentType*> modules;
|
Array<slang::IComponentType*> modules;
|
||||||
@@ -71,16 +74,10 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
|||||||
{
|
{
|
||||||
mainModule = (slang::IModule*)modules.back();
|
mainModule = (slang::IModule*)modules.back();
|
||||||
}
|
}
|
||||||
if(diagnostics)
|
CHECK_DIAGNOSTICS();
|
||||||
{
|
|
||||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(diagnostics)
|
CHECK_DIAGNOSTICS();
|
||||||
{
|
|
||||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
mainModule->findEntryPointByName(createInfo.entryPoint.c_str(), entrypoint.writeRef());
|
mainModule->findEntryPointByName(createInfo.entryPoint.c_str(), entrypoint.writeRef());
|
||||||
modules.add(entrypoint);
|
modules.add(entrypoint);
|
||||||
@@ -88,23 +85,16 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
|||||||
Slang::ComPtr<slang::IComponentType> moduleComposition;
|
Slang::ComPtr<slang::IComponentType> moduleComposition;
|
||||||
session->createCompositeComponentType(modules.data(), modules.size(), moduleComposition.writeRef(), diagnostics.writeRef());
|
session->createCompositeComponentType(modules.data(), modules.size(), moduleComposition.writeRef(), diagnostics.writeRef());
|
||||||
|
|
||||||
if(diagnostics)
|
CHECK_DIAGNOSTICS();
|
||||||
{
|
|
||||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Slang::ComPtr<slang::IComponentType> linkedProgram;
|
Slang::ComPtr<slang::IComponentType> linkedProgram;
|
||||||
moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef());
|
moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef());
|
||||||
if(diagnostics)
|
|
||||||
{
|
CHECK_DIAGNOSTICS();
|
||||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
slang::ProgramLayout* reflection = linkedProgram->getLayout(0, diagnostics.writeRef());
|
slang::ProgramLayout* reflection = linkedProgram->getLayout(0, diagnostics.writeRef());
|
||||||
if(diagnostics)
|
|
||||||
{
|
CHECK_DIAGNOSTICS();
|
||||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Array<slang::SpecializationArg> specialization;
|
Array<slang::SpecializationArg> specialization;
|
||||||
for(const auto& [key, value] : createInfo.typeParameter)
|
for(const auto& [key, value] : createInfo.typeParameter)
|
||||||
@@ -113,10 +103,8 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
|||||||
}
|
}
|
||||||
Slang::ComPtr<slang::IComponentType> specializedComponent;
|
Slang::ComPtr<slang::IComponentType> specializedComponent;
|
||||||
linkedProgram->specialize(specialization.data(), specialization.size(), specializedComponent.writeRef(), diagnostics.writeRef());
|
linkedProgram->specialize(specialization.data(), specialization.size(), specializedComponent.writeRef(), diagnostics.writeRef());
|
||||||
if(diagnostics)
|
CHECK_DIAGNOSTICS();
|
||||||
{
|
|
||||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
|
||||||
}
|
|
||||||
Slang::ComPtr<slang::IBlob> kernelBlob;
|
Slang::ComPtr<slang::IBlob> kernelBlob;
|
||||||
specializedComponent->getEntryPointCode(
|
specializedComponent->getEntryPointCode(
|
||||||
0,
|
0,
|
||||||
@@ -124,16 +112,13 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
|||||||
kernelBlob.writeRef(),
|
kernelBlob.writeRef(),
|
||||||
diagnostics.writeRef()
|
diagnostics.writeRef()
|
||||||
);
|
);
|
||||||
if(diagnostics)
|
CHECK_DIAGNOSTICS();
|
||||||
{
|
|
||||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
|
||||||
}
|
|
||||||
for (uint32 i = 0; i < reflection->getParameterCount(); ++i)
|
for (uint32 i = 0; i < reflection->getParameterCount(); ++i)
|
||||||
{
|
{
|
||||||
slang::VariableLayoutReflection* varLayout = reflection->getParameterByIndex(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 =
|
VkShaderModuleCreateInfo moduleInfo =
|
||||||
{
|
{
|
||||||
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
.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(entryPointName.data(), entryPointName.size(), CRC::CRC_32());
|
||||||
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
|
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
|
||||||
std::cout << "Creating Shader" << std::endl;
|
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,7 @@ MaterialInstance::MaterialInstance(uint64 id,
|
|||||||
OShaderParameter param;
|
OShaderParameter param;
|
||||||
Serialization::load(buffer, param);
|
Serialization::load(buffer, param);
|
||||||
parameters.add(std::move(param));
|
parameters.add(std::move(param));
|
||||||
|
buffer.rewind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +51,6 @@ MaterialInstance::~MaterialInstance()
|
|||||||
void MaterialInstance::updateDescriptor()
|
void MaterialInstance::updateDescriptor()
|
||||||
{
|
{
|
||||||
Gfx::PDescriptorLayout layout = baseMaterial->getMaterial()->getDescriptorLayout();
|
Gfx::PDescriptorLayout layout = baseMaterial->getMaterial()->getDescriptorLayout();
|
||||||
layout->reset();
|
|
||||||
descriptor = layout->allocateDescriptorSet();
|
descriptor = layout->allocateDescriptorSet();
|
||||||
for (auto& param : parameters)
|
for (auto& param : parameters)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ std::string ShaderParameter::evaluate(Map<std::string, std::string>& varState) c
|
|||||||
void ShaderParameter::save(ArchiveBuffer& buffer) const
|
void ShaderParameter::save(ArchiveBuffer& buffer) const
|
||||||
{
|
{
|
||||||
ShaderExpression::save(buffer);
|
ShaderExpression::save(buffer);
|
||||||
Serialization::save(buffer, key);
|
|
||||||
Serialization::save(buffer, byteOffset);
|
Serialization::save(buffer, byteOffset);
|
||||||
Serialization::save(buffer, binding);
|
Serialization::save(buffer, binding);
|
||||||
}
|
}
|
||||||
@@ -87,7 +86,6 @@ void ShaderParameter::save(ArchiveBuffer& buffer) const
|
|||||||
void ShaderParameter::load(ArchiveBuffer& buffer)
|
void ShaderParameter::load(ArchiveBuffer& buffer)
|
||||||
{
|
{
|
||||||
ShaderExpression::load(buffer);
|
ShaderExpression::load(buffer);
|
||||||
Serialization::load(buffer, key);
|
|
||||||
Serialization::load(buffer, byteOffset);
|
Serialization::load(buffer, byteOffset);
|
||||||
Serialization::load(buffer, binding);
|
Serialization::load(buffer, binding);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ void LightEnvironment::addPointLight(Component::PointLight pointLight)
|
|||||||
|
|
||||||
void LightEnvironment::commit()
|
void LightEnvironment::commit()
|
||||||
{
|
{
|
||||||
|
dirs.add(Component::DirectionalLight{
|
||||||
|
.color = Vector4(1, 1, 1, 1),
|
||||||
|
.direction = Vector4(1, 0, 1, 0),
|
||||||
|
});
|
||||||
lightEnv.numDirectionalLights = dirs.size();
|
lightEnv.numDirectionalLights = dirs.size();
|
||||||
lightEnv.numPointLights = points.size();
|
lightEnv.numPointLights = points.size();
|
||||||
lightEnvBuffer->updateContents(DataSource{
|
lightEnvBuffer->updateContents(DataSource{
|
||||||
|
|||||||
Reference in New Issue
Block a user