Normalize builtin forward shader bindings
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// XC_BUILTIN_FORWARD_LIT_OPENGL_PS
|
||||
#version 430
|
||||
layout(binding = 1) uniform sampler2D uBaseColorTexture;
|
||||
layout(binding = 2) uniform sampler2D uShadowMapTexture;
|
||||
layout(binding = 0) uniform sampler2D uBaseColorTexture;
|
||||
layout(binding = 1) uniform sampler2D uShadowMapTexture;
|
||||
|
||||
layout(std140, binding = 1) uniform PerObjectConstants {
|
||||
layout(std140, binding = 0) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
@@ -12,11 +12,11 @@ layout(std140, binding = 1) uniform PerObjectConstants {
|
||||
vec4 gMainLightColorAndFlags;
|
||||
};
|
||||
|
||||
layout(std140, binding = 2) uniform MaterialConstants {
|
||||
layout(std140, binding = 1) uniform MaterialConstants {
|
||||
vec4 gBaseColorFactor;
|
||||
};
|
||||
|
||||
layout(std140, binding = 3) uniform ShadowReceiverConstants {
|
||||
layout(std140, binding = 2) uniform ShadowReceiverConstants {
|
||||
mat4 gWorldToShadowMatrix;
|
||||
vec4 gShadowBiasAndTexelSize;
|
||||
vec4 gShadowOptions;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// XC_BUILTIN_FORWARD_LIT_VULKAN_PS
|
||||
#version 450
|
||||
layout(set = 3, binding = 0) uniform texture2D uBaseColorTexture;
|
||||
layout(set = 4, binding = 0) uniform sampler uLinearSampler;
|
||||
layout(set = 6, binding = 0) uniform texture2D uShadowMapTexture;
|
||||
layout(set = 7, binding = 0) uniform sampler uShadowMapSampler;
|
||||
layout(set = 2, binding = 0) uniform texture2D uBaseColorTexture;
|
||||
layout(set = 3, binding = 0) uniform sampler uLinearSampler;
|
||||
layout(set = 5, binding = 0) uniform texture2D uShadowMapTexture;
|
||||
layout(set = 6, binding = 0) uniform sampler uShadowMapSampler;
|
||||
|
||||
layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
|
||||
layout(set = 0, binding = 0, std140) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
@@ -14,11 +14,11 @@ layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
|
||||
vec4 gMainLightColorAndFlags;
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 0, std140) uniform MaterialConstants {
|
||||
layout(set = 1, binding = 0, std140) uniform MaterialConstants {
|
||||
vec4 gBaseColorFactor;
|
||||
};
|
||||
|
||||
layout(set = 5, binding = 0, std140) uniform ShadowReceiverConstants {
|
||||
layout(set = 4, binding = 0, std140) uniform ShadowReceiverConstants {
|
||||
mat4 gWorldToShadowMatrix;
|
||||
vec4 gShadowBiasAndTexelSize;
|
||||
vec4 gShadowOptions;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// XC_BUILTIN_FORWARD_LIT_D3D12_PS
|
||||
Texture2D gBaseColorTexture : register(t1);
|
||||
SamplerState gLinearSampler : register(s1);
|
||||
Texture2D gShadowMapTexture : register(t2);
|
||||
SamplerState gShadowMapSampler : register(s2);
|
||||
Texture2D gBaseColorTexture : register(t0);
|
||||
SamplerState gLinearSampler : register(s0);
|
||||
Texture2D gShadowMapTexture : register(t1);
|
||||
SamplerState gShadowMapSampler : register(s1);
|
||||
|
||||
cbuffer PerObjectConstants : register(b1) {
|
||||
cbuffer PerObjectConstants : register(b0) {
|
||||
float4x4 gProjectionMatrix;
|
||||
float4x4 gViewMatrix;
|
||||
float4x4 gModelMatrix;
|
||||
@@ -13,11 +13,11 @@ cbuffer PerObjectConstants : register(b1) {
|
||||
float4 gMainLightColorAndFlags;
|
||||
};
|
||||
|
||||
cbuffer MaterialConstants : register(b2) {
|
||||
cbuffer MaterialConstants : register(b1) {
|
||||
float4 gBaseColorFactor;
|
||||
};
|
||||
|
||||
cbuffer ShadowReceiverConstants : register(b3) {
|
||||
cbuffer ShadowReceiverConstants : register(b2) {
|
||||
float4x4 gWorldToShadowMatrix;
|
||||
float4 gShadowBiasAndTexelSize;
|
||||
float4 gShadowOptions;
|
||||
|
||||
@@ -13,13 +13,13 @@ Shader "Builtin Forward Lit"
|
||||
Tags { "LightMode" = "ForwardBase" }
|
||||
Resources
|
||||
{
|
||||
PerObjectConstants (ConstantBuffer, 1, 0) [Semantic(PerObject)]
|
||||
MaterialConstants (ConstantBuffer, 2, 0) [Semantic(Material)]
|
||||
BaseColorTexture (Texture2D, 3, 0) [Semantic(BaseColorTexture)]
|
||||
LinearClampSampler (Sampler, 4, 0) [Semantic(LinearClampSampler)]
|
||||
ShadowReceiverConstants (ConstantBuffer, 5, 0) [Semantic(ShadowReceiver)]
|
||||
ShadowMapTexture (Texture2D, 6, 0) [Semantic(ShadowMapTexture)]
|
||||
ShadowMapSampler (Sampler, 7, 0) [Semantic(ShadowMapSampler)]
|
||||
PerObjectConstants (ConstantBuffer, 0, 0) [Semantic(PerObject)]
|
||||
MaterialConstants (ConstantBuffer, 1, 0) [Semantic(Material)]
|
||||
BaseColorTexture (Texture2D, 2, 0) [Semantic(BaseColorTexture)]
|
||||
LinearClampSampler (Sampler, 3, 0) [Semantic(LinearClampSampler)]
|
||||
ShadowReceiverConstants (ConstantBuffer, 4, 0) [Semantic(ShadowReceiver)]
|
||||
ShadowMapTexture (Texture2D, 5, 0) [Semantic(ShadowMapTexture)]
|
||||
ShadowMapSampler (Sampler, 6, 0) [Semantic(ShadowMapSampler)]
|
||||
}
|
||||
HLSLPROGRAM
|
||||
#pragma vertex MainVS
|
||||
|
||||
@@ -4,7 +4,7 @@ layout(location = 0) in vec3 aPosition;
|
||||
layout(location = 1) in vec3 aNormal;
|
||||
layout(location = 2) in vec2 aTexCoord;
|
||||
|
||||
layout(std140, binding = 1) uniform PerObjectConstants {
|
||||
layout(std140, binding = 0) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
|
||||
@@ -4,7 +4,7 @@ layout(location = 0) in vec3 aPosition;
|
||||
layout(location = 1) in vec3 aNormal;
|
||||
layout(location = 2) in vec2 aTexCoord;
|
||||
|
||||
layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
|
||||
layout(set = 0, binding = 0, std140) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// XC_BUILTIN_FORWARD_LIT_D3D12_VS
|
||||
cbuffer PerObjectConstants : register(b1) {
|
||||
cbuffer PerObjectConstants : register(b0) {
|
||||
float4x4 gProjectionMatrix;
|
||||
float4x4 gViewMatrix;
|
||||
float4x4 gModelMatrix;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// XC_BUILTIN_UNLIT_OPENGL_PS
|
||||
#version 430
|
||||
layout(binding = 1) uniform sampler2D uBaseColorTexture;
|
||||
layout(binding = 0) uniform sampler2D uBaseColorTexture;
|
||||
|
||||
layout(std140, binding = 1) uniform PerObjectConstants {
|
||||
layout(std140, binding = 0) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
@@ -11,7 +11,7 @@ layout(std140, binding = 1) uniform PerObjectConstants {
|
||||
vec4 gMainLightColorAndFlags;
|
||||
};
|
||||
|
||||
layout(std140, binding = 2) uniform MaterialConstants {
|
||||
layout(std140, binding = 1) uniform MaterialConstants {
|
||||
vec4 gBaseColorFactor;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// XC_BUILTIN_UNLIT_VULKAN_PS
|
||||
#version 450
|
||||
layout(set = 3, binding = 0) uniform texture2D uBaseColorTexture;
|
||||
layout(set = 4, binding = 0) uniform sampler uLinearSampler;
|
||||
layout(set = 2, binding = 0) uniform texture2D uBaseColorTexture;
|
||||
layout(set = 3, binding = 0) uniform sampler uLinearSampler;
|
||||
|
||||
layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
|
||||
layout(set = 0, binding = 0, std140) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
@@ -12,7 +12,7 @@ layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
|
||||
vec4 gMainLightColorAndFlags;
|
||||
};
|
||||
|
||||
layout(set = 2, binding = 0, std140) uniform MaterialConstants {
|
||||
layout(set = 1, binding = 0, std140) uniform MaterialConstants {
|
||||
vec4 gBaseColorFactor;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// XC_BUILTIN_UNLIT_D3D12_PS
|
||||
Texture2D gBaseColorTexture : register(t1);
|
||||
SamplerState gLinearSampler : register(s1);
|
||||
Texture2D gBaseColorTexture : register(t0);
|
||||
SamplerState gLinearSampler : register(s0);
|
||||
|
||||
cbuffer PerObjectConstants : register(b1) {
|
||||
cbuffer PerObjectConstants : register(b0) {
|
||||
float4x4 gProjectionMatrix;
|
||||
float4x4 gViewMatrix;
|
||||
float4x4 gModelMatrix;
|
||||
@@ -11,7 +11,7 @@ cbuffer PerObjectConstants : register(b1) {
|
||||
float4 gMainLightColorAndFlags;
|
||||
};
|
||||
|
||||
cbuffer MaterialConstants : register(b2) {
|
||||
cbuffer MaterialConstants : register(b1) {
|
||||
float4 gBaseColorFactor;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ Shader "Builtin Unlit"
|
||||
Tags { "LightMode" = "Unlit" }
|
||||
Resources
|
||||
{
|
||||
PerObjectConstants (ConstantBuffer, 1, 0) [Semantic(PerObject)]
|
||||
MaterialConstants (ConstantBuffer, 2, 0) [Semantic(Material)]
|
||||
BaseColorTexture (Texture2D, 3, 0) [Semantic(BaseColorTexture)]
|
||||
LinearClampSampler (Sampler, 4, 0) [Semantic(LinearClampSampler)]
|
||||
PerObjectConstants (ConstantBuffer, 0, 0) [Semantic(PerObject)]
|
||||
MaterialConstants (ConstantBuffer, 1, 0) [Semantic(Material)]
|
||||
BaseColorTexture (Texture2D, 2, 0) [Semantic(BaseColorTexture)]
|
||||
LinearClampSampler (Sampler, 3, 0) [Semantic(LinearClampSampler)]
|
||||
}
|
||||
HLSLPROGRAM
|
||||
#pragma vertex MainVS
|
||||
|
||||
@@ -4,7 +4,7 @@ layout(location = 0) in vec3 aPosition;
|
||||
layout(location = 1) in vec3 aNormal;
|
||||
layout(location = 2) in vec2 aTexCoord;
|
||||
|
||||
layout(std140, binding = 1) uniform PerObjectConstants {
|
||||
layout(std140, binding = 0) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
|
||||
@@ -4,7 +4,7 @@ layout(location = 0) in vec3 aPosition;
|
||||
layout(location = 1) in vec3 aNormal;
|
||||
layout(location = 2) in vec2 aTexCoord;
|
||||
|
||||
layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
|
||||
layout(set = 0, binding = 0, std140) uniform PerObjectConstants {
|
||||
mat4 gProjectionMatrix;
|
||||
mat4 gViewMatrix;
|
||||
mat4 gModelMatrix;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// XC_BUILTIN_UNLIT_D3D12_VS
|
||||
cbuffer PerObjectConstants : register(b1) {
|
||||
cbuffer PerObjectConstants : register(b0) {
|
||||
float4x4 gProjectionMatrix;
|
||||
float4x4 gViewMatrix;
|
||||
float4x4 gModelMatrix;
|
||||
|
||||
@@ -236,37 +236,6 @@ inline BuiltinPassResourceSemantic ResolveBuiltinPassResourceSemantic(
|
||||
return BuiltinPassResourceSemantic::Unknown;
|
||||
}
|
||||
|
||||
inline Containers::Array<Resources::ShaderResourceBindingDesc> BuildLegacyBuiltinForwardPassResourceBindings() {
|
||||
Containers::Array<Resources::ShaderResourceBindingDesc> bindings;
|
||||
bindings.Resize(4);
|
||||
|
||||
bindings[0].name = "PerObjectConstants";
|
||||
bindings[0].type = Resources::ShaderResourceType::ConstantBuffer;
|
||||
bindings[0].set = 1;
|
||||
bindings[0].binding = 0;
|
||||
bindings[0].semantic = "PerObject";
|
||||
|
||||
bindings[1].name = "MaterialConstants";
|
||||
bindings[1].type = Resources::ShaderResourceType::ConstantBuffer;
|
||||
bindings[1].set = 2;
|
||||
bindings[1].binding = 0;
|
||||
bindings[1].semantic = "Material";
|
||||
|
||||
bindings[2].name = "BaseColorTexture";
|
||||
bindings[2].type = Resources::ShaderResourceType::Texture2D;
|
||||
bindings[2].set = 3;
|
||||
bindings[2].binding = 0;
|
||||
bindings[2].semantic = "BaseColorTexture";
|
||||
|
||||
bindings[3].name = "LinearClampSampler";
|
||||
bindings[3].type = Resources::ShaderResourceType::Sampler;
|
||||
bindings[3].set = 4;
|
||||
bindings[3].binding = 0;
|
||||
bindings[3].semantic = "LinearClampSampler";
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
inline bool IsBuiltinPassResourceTypeCompatible(
|
||||
BuiltinPassResourceSemantic semantic,
|
||||
Resources::ShaderResourceType type) {
|
||||
|
||||
@@ -52,6 +52,11 @@ private:
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsDepthFormat(RHI::Format format) {
|
||||
return format == RHI::Format::D24_UNorm_S8_UInt ||
|
||||
format == RHI::Format::D32_Float;
|
||||
}
|
||||
|
||||
bool TryResolveSurfacePassType(
|
||||
const Resources::Material* material,
|
||||
BuiltinMaterialPass& outPass) {
|
||||
@@ -283,7 +288,8 @@ bool BuiltinForwardPipeline::ExecuteForwardOpaquePass(const RenderPassContext& p
|
||||
|
||||
commandList->SetPrimitiveTopology(RHI::PrimitiveTopology::TriangleList);
|
||||
|
||||
if (sceneData.lighting.HasMainDirectionalShadow()) {
|
||||
if (sceneData.lighting.HasMainDirectionalShadow() &&
|
||||
IsDepthFormat(sceneData.lighting.mainDirectionalShadow.shadowMap->GetFormat())) {
|
||||
commandList->TransitionBarrier(
|
||||
sceneData.lighting.mainDirectionalShadow.shadowMap,
|
||||
RHI::ResourceStates::DepthWrite,
|
||||
@@ -310,7 +316,8 @@ bool BuiltinForwardPipeline::ExecuteForwardOpaquePass(const RenderPassContext& p
|
||||
DrawVisibleItem(context, sceneData, visibleItem);
|
||||
}
|
||||
|
||||
if (sceneData.lighting.HasMainDirectionalShadow()) {
|
||||
if (sceneData.lighting.HasMainDirectionalShadow() &&
|
||||
IsDepthFormat(sceneData.lighting.mainDirectionalShadow.shadowMap->GetFormat())) {
|
||||
commandList->TransitionBarrier(
|
||||
sceneData.lighting.mainDirectionalShadow.shadowMap,
|
||||
RHI::ResourceStates::PixelShaderResource,
|
||||
@@ -530,9 +537,9 @@ BuiltinForwardPipeline::PassResourceLayout* BuiltinForwardPipeline::GetOrCreateP
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
Containers::Array<Resources::ShaderResourceBindingDesc> resourceBindings = resolvedShaderPass.pass->resources;
|
||||
const Containers::Array<Resources::ShaderResourceBindingDesc>& resourceBindings = resolvedShaderPass.pass->resources;
|
||||
if (resourceBindings.Empty()) {
|
||||
resourceBindings = BuildLegacyBuiltinForwardPassResourceBindings();
|
||||
return failLayout("BuiltinForwardPipeline requires explicit resource bindings on the resolved shader pass");
|
||||
}
|
||||
|
||||
BuiltinPassResourceBindingPlan bindingPlan = {};
|
||||
@@ -564,38 +571,6 @@ BuiltinForwardPipeline::PassResourceLayout* BuiltinForwardPipeline::GetOrCreateP
|
||||
return failLayout("BuiltinForwardPipeline requires a PerObject resource binding");
|
||||
}
|
||||
|
||||
if (hasAnyResource &&
|
||||
passLayout.firstDescriptorSet > 0 &&
|
||||
!passLayout.setLayouts.empty() &&
|
||||
passLayout.setLayouts[0].bindings.empty()) {
|
||||
BuiltinPassSetLayoutMetadata& compatibilitySet = passLayout.setLayouts[0];
|
||||
if (bindingPlan.usesConstantBuffers) {
|
||||
compatibilitySet.bindings.push_back({
|
||||
0,
|
||||
static_cast<uint32_t>(RHI::DescriptorType::CBV),
|
||||
1,
|
||||
0
|
||||
});
|
||||
}
|
||||
if (bindingPlan.usesTextures) {
|
||||
compatibilitySet.bindings.push_back({
|
||||
0,
|
||||
static_cast<uint32_t>(RHI::DescriptorType::SRV),
|
||||
1,
|
||||
0
|
||||
});
|
||||
}
|
||||
if (bindingPlan.usesSamplers) {
|
||||
compatibilitySet.bindings.push_back({
|
||||
0,
|
||||
static_cast<uint32_t>(RHI::DescriptorType::Sampler),
|
||||
1,
|
||||
0
|
||||
});
|
||||
}
|
||||
RefreshBuiltinPassSetLayoutMetadata(compatibilitySet);
|
||||
}
|
||||
|
||||
std::vector<RHI::DescriptorSetLayoutDesc> nativeSetLayouts(passLayout.setLayouts.size());
|
||||
for (size_t i = 0; i < passLayout.setLayouts.size(); ++i) {
|
||||
nativeSetLayouts[i] = passLayout.setLayouts[i].layout;
|
||||
|
||||
Reference in New Issue
Block a user