Adding combined image samplers

This commit is contained in:
Dynamitos
2024-04-26 11:42:28 +02:00
parent 54cd77beb2
commit 93ab9e38f0
9 changed files with 55 additions and 23 deletions
+4 -1
View File
@@ -3,4 +3,7 @@
url = https://github.com/d-bahr/CRCpp.git url = https://github.com/d-bahr/CRCpp.git
[submodule "external/vcpkg"] [submodule "external/vcpkg"]
path = external/vcpkg path = external/vcpkg
url = https://github.com/Microsoft/vcpkg.git url = https://github.com/Microsoft/vcpkg.git
[submodule "external/slang"]
path = external/slang
url = git@github.com:shader-slang/slang.git
+2 -3
View File
@@ -28,7 +28,7 @@
"name": "RelWithDebInfo", "name": "RelWithDebInfo",
"generator": "Visual Studio 17 2022 Win64", "generator": "Visual Studio 17 2022 Win64",
"configurationType": "RelWithDebInfo", "configurationType": "RelWithDebInfo",
"buildRoot": "${CMAKE_CURRENT_SOURCE_DIR}/cmake", "buildRoot": "C:/Users/Dynamitos/Seele/build/",
"installRoot": "C:/Program Files/Seele", "installRoot": "C:/Program Files/Seele",
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildCommandArgs": "", "buildCommandArgs": "",
@@ -59,8 +59,7 @@
"buildCommandArgs": "", "buildCommandArgs": "",
"ctestCommandArgs": "", "ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64" ], "inheritEnvironments": [ "msvc_x64" ],
"intelliSenseMode": "windows-msvc-x64", "intelliSenseMode": "windows-msvc-x64"
"variables": []
} }
] ]
} }
Vendored Submodule
+1
Submodule external/slang added at 52dcb5bd44
+21 -1
View File
@@ -121,6 +121,23 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
parameters.add(p->key); parameters.add(p->key);
expressions.add(std::move(p)); expressions.add(std::move(p));
} }
else if (type.compare("Sampler2D") == 0)
{
OCombinedTextureParameter p = new CombinedTextureParameter(param.key(), 0, bindingCounter);
layout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = bindingCounter++, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER, });
p->sampler = graphics->createSampler({});
if (defaultValue != param.value().end())
{
std::string defaultString = defaultValue.value().get<std::string>();
p->data = AssetRegistry::findTexture(defaultString);
}
if (p->data == nullptr)
{
p->data = AssetRegistry::findTexture(""); // this will return placeholder texture
}
parameters.add(p->key);
expressions.add(std::move(p));
}
else else
{ {
std::cout << "Error unsupported parameter type" << std::endl; std::cout << "Error unsupported parameter type" << std::endl;
@@ -206,7 +223,10 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
OSampleExpression p = new SampleExpression(); OSampleExpression p = new SampleExpression();
std::string name = fmt::format("{0}", key++); std::string name = fmt::format("{0}", key++);
p->key = name; p->key = name;
p->inputs["texture"].source = referenceExpression(obj["texture"]); if (obj.contains("texture"))
{
p->inputs["texture"].source = referenceExpression(obj["texture"]);
}
p->inputs["sampler"].source = referenceExpression(obj["sampler"]); p->inputs["sampler"].source = referenceExpression(obj["sampler"]);
p->inputs["coords"].source = referenceExpression(obj["coords"]); p->inputs["coords"].source = referenceExpression(obj["coords"]);
expressions.add(std::move(p)); expressions.add(std::move(p));
+4 -14
View File
@@ -77,18 +77,13 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
}); });
matCode["params"]["diffuseTexture"] = matCode["params"]["diffuseTexture"] =
{ {
{"type", "Texture2D"}, {"type", "Sampler2D"},
{"default", fmt::format("{0}/{1}", importPath, texFilename.string())} {"default", fmt::format("{0}/{1}", importPath, texFilename.string())}
}; };
matCode["params"]["diffuseSampler"] =
{
{"type", "Sampler"}
};
matCode["code"].push_back( matCode["code"].push_back(
{ {
{ "exp", "Sample" }, { "exp", "Sample" },
{ "texture", "diffuseTexture" }, { "sampler", "diffuseTexture" },
{ "sampler", "diffuseSampler" },
{ "coords", "input.texCoords"} { "coords", "input.texCoords"}
} }
); );
@@ -122,18 +117,13 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
}); });
matCode["params"]["normalTexture"] = matCode["params"]["normalTexture"] =
{ {
{"type", "Texture2D"}, {"type", "Sampler2D"},
{"default", fmt::format("{0}/{1}", importPath, texFilename.string())} {"default", fmt::format("{0}/{1}", importPath, texFilename.string())}
}; };
matCode["params"]["normalSampler"] =
{
{"type", "Sampler"}
};
matCode["code"].push_back( matCode["code"].push_back(
{ {
{ "exp", "Sample" }, { "exp", "Sample" },
{ "texture", "normalTexture" }, { "sampler", "normalTexture" },
{ "sampler", "normalSampler" },
{ "coords", "input.texCoords" } { "coords", "input.texCoords" }
} }
); );
+8
View File
@@ -81,10 +81,18 @@ struct Map : public Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocat
{ {
return Super::remove(key); return Super::remove(key);
} }
constexpr bool exists(const key_type& key) const
{
return Super::find(key) != Super::end();
}
constexpr bool exists(const key_type& key) constexpr bool exists(const key_type& key)
{ {
return Super::find(key) != Super::end(); return Super::find(key) != Super::end();
} }
constexpr bool contains(const key_type& key) const
{
return exists(key);
}
constexpr bool contains(const key_type& key) constexpr bool contains(const key_type& key)
{ {
return exists(key); return exists(key);
+5 -1
View File
@@ -314,7 +314,7 @@ protected:
constexpr iterator find(const key_type& key) const constexpr iterator find(const key_type& key) const
{ {
Node* it = root; Node* it = root;
while (!equal(it->data, key)) while (it != nullptr && !equal(it->data, key))
{ {
if (comp(key, keyFun(it->data))) if (comp(key, keyFun(it->data)))
{ {
@@ -325,6 +325,10 @@ protected:
it = it->rightChild; it = it->rightChild;
} }
} }
if (it == nullptr)
{
return end();
}
return iterator(it); return iterator(it);
} }
constexpr Pair<iterator, bool> insert(const NodeData& data) constexpr Pair<iterator, bool> insert(const NodeData& data)
+1 -1
View File
@@ -21,7 +21,7 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
option[0].value = slang::CompilerOptionValue(); option[0].value = slang::CompilerOptionValue();
option[0].value.kind = slang::CompilerOptionValueKind::Int; option[0].value.kind = slang::CompilerOptionValueKind::Int;
option[0].value.intValue0 = 1; option[0].value.intValue0 = 1;
option[1].name = slang::CompilerOptionName::IgnoreCapabilities; option[1].name = slang::CompilerOptionName::EmitSpirvViaGLSL;
option[1].value = slang::CompilerOptionValue(); option[1].value = slang::CompilerOptionValue();
option[1].value.kind = slang::CompilerOptionValueKind::Int; option[1].value.kind = slang::CompilerOptionValueKind::Int;
option[1].value.intValue0 = 1; option[1].value.intValue0 = 1;
+9 -2
View File
@@ -246,7 +246,7 @@ void CombinedTextureParameter::updateDescriptorSet(Gfx::PDescriptorSet descripto
void CombinedTextureParameter::generateDeclaration(std::ofstream& stream) const void CombinedTextureParameter::generateDeclaration(std::ofstream& stream) const
{ {
stream << "\tTexture2D " << key << ";\n"; stream << "\tSampler2D " << key << ";\n";
} }
void CombinedTextureParameter::save(ArchiveBuffer& buffer) const void CombinedTextureParameter::save(ArchiveBuffer& buffer) const
@@ -408,7 +408,14 @@ std::string SampleExpression::evaluate(Map<std::string, std::string>& varState)
{ {
std::string varName = fmt::format("exp_{}", key); std::string varName = fmt::format("exp_{}", key);
varState[key] = varName; varState[key] = varName;
return fmt::format("let {} = {}.Sample({}, {});\n", varName, varState[inputs.at("texture").source], varState[inputs.at("sampler").source], varState[inputs.at("coords").source]); if (inputs.contains("texture"))
{
return fmt::format("let {} = {}.Sample({}, {});\n", varName, varState[inputs.at("texture").source], varState[inputs.at("sampler").source], varState[inputs.at("coords").source]);
}
else
{
return fmt::format("let {} = {}.Sample({});\n", varName, varState[inputs.at("sampler").source], varState[inputs.at("coords").source]);
}
} }
void SampleExpression::save(ArchiveBuffer& buffer) const void SampleExpression::save(ArchiveBuffer& buffer) const