refactor(srp): bind managed fullscreen auxiliary inputs through render graph
This commit is contained in:
@@ -14,12 +14,21 @@ namespace XCEngine.Rendering
|
||||
|
||||
public sealed class RenderGraphRasterPassBuilder
|
||||
{
|
||||
private struct TextureBindingRequest
|
||||
{
|
||||
public string shaderResourceName;
|
||||
public RenderGraphTextureHandle texture;
|
||||
public bool isDepth;
|
||||
}
|
||||
|
||||
private readonly ScriptableRenderContext m_context;
|
||||
private readonly string m_passName;
|
||||
private readonly List<RenderGraphTextureHandle> m_readTextures =
|
||||
new List<RenderGraphTextureHandle>();
|
||||
private readonly List<RenderGraphTextureHandle> m_readDepthTextures =
|
||||
new List<RenderGraphTextureHandle>();
|
||||
private readonly List<TextureBindingRequest> m_textureBindings =
|
||||
new List<TextureBindingRequest>();
|
||||
private readonly List<RenderGraphTextureHandle> m_colorAttachments =
|
||||
new List<RenderGraphTextureHandle>();
|
||||
private RenderGraphTextureHandle m_sourceColorTexture;
|
||||
@@ -74,22 +83,40 @@ namespace XCEngine.Rendering
|
||||
public RenderGraphRasterPassBuilder UseTexture(
|
||||
RenderGraphTextureHandle texture)
|
||||
{
|
||||
if (texture.isValid)
|
||||
{
|
||||
m_readTextures.Add(texture);
|
||||
}
|
||||
|
||||
AddReadTexture(
|
||||
texture,
|
||||
isDepth: false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RenderGraphRasterPassBuilder UseDepthTexture(
|
||||
RenderGraphTextureHandle texture)
|
||||
{
|
||||
if (texture.isValid)
|
||||
{
|
||||
m_readDepthTextures.Add(texture);
|
||||
}
|
||||
AddReadTexture(
|
||||
texture,
|
||||
isDepth: true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RenderGraphRasterPassBuilder BindTexture(
|
||||
string shaderResourceName,
|
||||
RenderGraphTextureHandle texture)
|
||||
{
|
||||
AddTextureBinding(
|
||||
shaderResourceName,
|
||||
texture,
|
||||
isDepth: false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RenderGraphRasterPassBuilder BindDepthTexture(
|
||||
string shaderResourceName,
|
||||
RenderGraphTextureHandle texture)
|
||||
{
|
||||
AddTextureBinding(
|
||||
shaderResourceName,
|
||||
texture,
|
||||
isDepth: true);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -224,6 +251,29 @@ namespace XCEngine.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_textureBindings.Count; ++i)
|
||||
{
|
||||
TextureBindingRequest binding =
|
||||
m_textureBindings[i];
|
||||
if (!binding.texture.isValid ||
|
||||
string.IsNullOrEmpty(
|
||||
binding.shaderResourceName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!InternalCalls
|
||||
.Rendering_ScriptableRenderContext_AddRasterPassTextureBinding(
|
||||
m_context.nativeHandle,
|
||||
nativePassHandle,
|
||||
binding.shaderResourceName,
|
||||
binding.texture.nativeIndex,
|
||||
binding.isDepth))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_colorAttachments.Count; ++i)
|
||||
{
|
||||
RenderGraphTextureHandle colorAttachment =
|
||||
@@ -304,6 +354,80 @@ namespace XCEngine.Rendering
|
||||
RenderGraphRasterPassExecutionKind.None;
|
||||
}
|
||||
|
||||
private void AddReadTexture(
|
||||
RenderGraphTextureHandle texture,
|
||||
bool isDepth)
|
||||
{
|
||||
if (!texture.isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<RenderGraphTextureHandle> readList =
|
||||
isDepth
|
||||
? m_readDepthTextures
|
||||
: m_readTextures;
|
||||
for (int i = 0; i < readList.Count; ++i)
|
||||
{
|
||||
if (readList[i].nativeIndex ==
|
||||
texture.nativeIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
readList.Add(texture);
|
||||
}
|
||||
|
||||
private void AddTextureBinding(
|
||||
string shaderResourceName,
|
||||
RenderGraphTextureHandle texture,
|
||||
bool isDepth)
|
||||
{
|
||||
if (string.IsNullOrEmpty(shaderResourceName))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Shader resource name cannot be null or empty.",
|
||||
nameof(shaderResourceName));
|
||||
}
|
||||
|
||||
if (!texture.isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AddReadTexture(
|
||||
texture,
|
||||
isDepth);
|
||||
|
||||
for (int i = 0; i < m_textureBindings.Count; ++i)
|
||||
{
|
||||
TextureBindingRequest existingBinding =
|
||||
m_textureBindings[i];
|
||||
if (!string.Equals(
|
||||
existingBinding.shaderResourceName,
|
||||
shaderResourceName,
|
||||
StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
existingBinding.texture = texture;
|
||||
existingBinding.isDepth = isDepth;
|
||||
m_textureBindings[i] = existingBinding;
|
||||
return;
|
||||
}
|
||||
|
||||
m_textureBindings.Add(
|
||||
new TextureBindingRequest
|
||||
{
|
||||
shaderResourceName =
|
||||
shaderResourceName,
|
||||
texture = texture,
|
||||
isDepth = isDepth
|
||||
});
|
||||
}
|
||||
|
||||
private bool HasAnyColorAttachment()
|
||||
{
|
||||
for (int i = 0; i < m_colorAttachments.Count; ++i)
|
||||
|
||||
Reference in New Issue
Block a user