Formalize builtin shader resource contracts
This commit is contained in:
@@ -87,32 +87,16 @@ inline bool TryCollectShaderPassResourceBindings(
|
||||
Containers::Array<Resources::ShaderResourceBindingDesc>& outBindings) {
|
||||
outBindings.Clear();
|
||||
|
||||
if (!pass.resources.Empty()) {
|
||||
outBindings.Reserve(pass.resources.Size());
|
||||
for (const Resources::ShaderResourceBindingDesc& binding : pass.resources) {
|
||||
outBindings.PushBack(binding);
|
||||
}
|
||||
return true;
|
||||
if (pass.resources.Empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryBuildImplicitBuiltinPassResourceBindings(pass, outBindings);
|
||||
}
|
||||
|
||||
inline Containers::String ResolveLegacyHlslBindingDeclarationAlias(
|
||||
const Resources::ShaderResourceBindingDesc& binding) {
|
||||
switch (ResolveBuiltinPassResourceSemantic(binding)) {
|
||||
case BuiltinPassResourceSemantic::BaseColorTexture:
|
||||
return "gBaseColorTexture";
|
||||
case BuiltinPassResourceSemantic::ShadowMapTexture:
|
||||
return "gShadowMapTexture";
|
||||
case BuiltinPassResourceSemantic::LinearClampSampler:
|
||||
return "gLinearSampler";
|
||||
case BuiltinPassResourceSemantic::ShadowMapSampler:
|
||||
return "gShadowMapSampler";
|
||||
case BuiltinPassResourceSemantic::Unknown:
|
||||
default:
|
||||
return Containers::String();
|
||||
outBindings.Reserve(pass.resources.Size());
|
||||
for (const Resources::ShaderResourceBindingDesc& binding : pass.resources) {
|
||||
outBindings.PushBack(binding);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool TryRewriteHlslRegisterBindingWithName(
|
||||
@@ -201,37 +185,6 @@ inline bool TryRewriteHlslRegisterBinding(
|
||||
return true;
|
||||
}
|
||||
|
||||
const Containers::String legacyAlias = ResolveLegacyHlslBindingDeclarationAlias(binding);
|
||||
if (legacyAlias != binding.name &&
|
||||
TryRewriteHlslRegisterBindingWithName(
|
||||
sourceText,
|
||||
legacyAlias,
|
||||
registerPrefix,
|
||||
binding.binding,
|
||||
binding.set,
|
||||
includeRegisterSpace,
|
||||
binding.type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((binding.type == Resources::ShaderResourceType::Texture2D ||
|
||||
binding.type == Resources::ShaderResourceType::TextureCube ||
|
||||
binding.type == Resources::ShaderResourceType::Sampler)) {
|
||||
const Containers::String prefixedName = Containers::String("g") + binding.name;
|
||||
if (prefixedName != binding.name &&
|
||||
prefixedName != legacyAlias &&
|
||||
TryRewriteHlslRegisterBindingWithName(
|
||||
sourceText,
|
||||
prefixedName,
|
||||
registerPrefix,
|
||||
binding.binding,
|
||||
binding.set,
|
||||
includeRegisterSpace,
|
||||
binding.type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -243,21 +196,18 @@ inline bool TryBuildRuntimeShaderBindings(
|
||||
outBindings.Clear();
|
||||
outIncludeRegisterSpace = false;
|
||||
|
||||
if (!TryCollectShaderPassResourceBindings(pass, outBindings)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (backend == Resources::ShaderBackend::Vulkan) {
|
||||
outIncludeRegisterSpace = true;
|
||||
return TryCollectShaderPassResourceBindings(pass, outBindings);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (backend != Resources::ShaderBackend::D3D12 &&
|
||||
backend != Resources::ShaderBackend::OpenGL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pass.resources.Empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryBuildImplicitBuiltinPassResourceBindings(pass, outBindings)) {
|
||||
outBindings.Clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "ShaderFileUtils.h"
|
||||
|
||||
#include <XCEngine/Core/Asset/ResourceManager.h>
|
||||
#include <XCEngine/Rendering/Builtin/BuiltinPassLayoutUtils.h>
|
||||
#include <XCEngine/Resources/BuiltinResources.h>
|
||||
#include <XCEngine/Resources/Shader/ShaderLoader.h>
|
||||
|
||||
@@ -207,6 +208,14 @@ ShaderPass BuildConcretePass(
|
||||
for (const ShaderResourceBindingDesc& resourceBinding : pass.resources) {
|
||||
shaderPass.resources.PushBack(resourceBinding);
|
||||
}
|
||||
if (shaderPass.resources.Empty()) {
|
||||
Containers::Array<ShaderResourceBindingDesc> defaultBindings;
|
||||
if (::XCEngine::Rendering::TryBuildBuiltinPassDefaultResourceBindings(shaderPass, defaultBindings)) {
|
||||
for (const ShaderResourceBindingDesc& resourceBinding : defaultBindings) {
|
||||
shaderPass.resources.PushBack(resourceBinding);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const ShaderKeywordDeclaration& keywordDeclaration : pass.keywordDeclarations) {
|
||||
shaderPass.keywordDeclarations.PushBack(keywordDeclaration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user