RenderTargetGroup GetData, Shader uint support

This commit is contained in:
Simon Lübeß
2022-05-25 22:00:11 +02:00
parent 1418063d68
commit 28f1fad464
19 changed files with 354 additions and 44 deletions
@@ -96,6 +96,9 @@ namespace GlitchyEngine.Renderer
case typeof(Int4):
EnsureTypeMatch(1, 4, .Int);
case typeof(uint32):
EnsureTypeMatch(1, 1, .UInt);
case typeof(Matrix4x3):
EnsureTypeMatch(4, 3, .Float);
case typeof(Matrix3x3):
@@ -102,6 +102,7 @@ namespace GlitchyEngine.Renderer
Bool,
Float,
Int,
UInt
// todo
}
}
@@ -0,0 +1,52 @@
namespace GlitchyEngine.Renderer
{
static class FullscreenQuad
{
//static GeometryBinding s_fullscreenQuadGeometry;
public static void Init()
{
/*s_fullscreenQuadGeometry = new GeometryBinding();
s_fullscreenQuadGeometry.SetPrimitiveTopology(.TriangleList);
using(var quadVertices = new VertexBuffer(typeof(Vector4), 4, .Immutable))
{
Vector4[4] vertices = .(
.(-1,-1, 0, 1),
.(-1, 1, 0, 0),
.( 1, 1, 1, 0),
.( 1,-1, 1, 1)
);
quadVertices.SetData(vertices);
s_fullscreenQuadGeometry.SetVertexBufferSlot(quadVertices, 0);
}
using(var quadIndices = new IndexBuffer(6, .Immutable))
{
uint16[6] indices = .(
0, 1, 2,
2, 3, 0
);
quadIndices.SetData(indices);
s_fullscreenQuadGeometry.SetIndexBuffer(quadIndices);
}
VertexElement[] vertexElements = new .(
VertexElement(.R32G32_Float, "POSITION"),
VertexElement(.R32G32_Float, "TEXCOORD")
);
using (var quadBatchLayout = new VertexLayout(vertexElements, true, TestFullscreenEffect.VertexShader))
{
s_fullscreenQuadGeometry.SetVertexLayout(quadBatchLayout);
}*/
}
public static void Deinit()
{
//s_fullscreenQuadGeometry.ReleaseRef();
}
}
}
+2
View File
@@ -132,6 +132,8 @@ namespace GlitchyEngine.Renderer
public void SetVariable(String name, Int3 value) => SetVariable<Int3>(name, value);
public void SetVariable(String name, Int4 value) => SetVariable<Int4>(name, value);
public void SetVariable(String name, uint32 value) => SetVariable<uint32>(name, value);
public void SetVariable(String name, Color value) => SetVariable<ColorRGBA>(name, value);
public void SetVariable(String name, ColorRGB value) => SetVariable<ColorRGB>(name, value);
public void SetVariable(String name, ColorRGBA value) => SetVariable<ColorRGBA>(name, value);
+34 -3
View File
@@ -88,6 +88,9 @@ namespace GlitchyEngine.Renderer
case None = 0;
case R8_SInt;
case R32_UInt;
case R8G8B8A8_UNorm;
case R8G8B8A8_SNorm;
@@ -104,6 +107,18 @@ namespace GlitchyEngine.Renderer
public bool IsDepth => HasFlag(DepthMarker);
}
public enum ClearColor
{
case Color(ColorRGBA ClearColor);
case UInt(uint32 ClearValue);
case DepthStencil(float Depth, uint8 Stencil);
public static implicit operator ClearColor(ColorRGBA color)
{
return .Color(color);
}
}
public struct TargetDescription
{
public RenderTargetFormat Format = .None;
@@ -113,13 +128,13 @@ namespace GlitchyEngine.Renderer
public bool IsShaderReadable = true;
/// Clear color. For DepthStencilBuffers: R is Depth, G is Stencil
public ColorRGBA ClearColor = .Black;
public ClearColor ClearColor = .Color(.Black);
public SamplerStateDescription SamplerDescription = .();
public this() { }
public this(RenderTargetFormat format, bool isSwapchainTarget = false, bool isShaderReadable = true, ColorRGBA clearColor = .Black, SamplerStateDescription samplerDescription = .())
public this(RenderTargetFormat format, bool isSwapchainTarget = false, bool isShaderReadable = true, ClearColor clearColor = .Color(.(0, 0, 0, 1)), SamplerStateDescription samplerDescription = .())
{
Format = format;
IsSwapchainTarget = isSwapchainTarget;
@@ -179,6 +194,9 @@ namespace GlitchyEngine.Renderer
{
_description = description;
Log.EngineLogger.AssertDebug(_description.Width != 0);
Log.EngineLogger.AssertDebug(_description.Height != 0);
var colorTargets = description.ColorTargetDescriptions;
if (!colorTargets.IsNull && !colorTargets.IsEmpty)
@@ -206,10 +224,12 @@ namespace GlitchyEngine.Renderer
}
_depthTargetDescription = description.DepthTargetDescription;
Log.EngineLogger.AssertDebug(_depthTargetDescription.Format.IsDepth, "Depth target must have depth format.");
if (_depthTargetDescription.Format != .None)
{
Log.EngineLogger.AssertDebug(_depthTargetDescription.Format.IsDepth, "Depth target must have depth format.");
Log.EngineLogger.AssertDebug(_depthTargetDescription.ClearColor case .DepthStencil, "Clear color for depth stencil target must be of type DepthStencil.");
_depthSamplerState = SamplerStateManager.GetSampler(_depthTargetDescription.SamplerDescription);
}
@@ -227,5 +247,16 @@ namespace GlitchyEngine.Renderer
}
protected extern TextureViewBinding PlatformGetViewBinding(int index);
protected extern Result<void> PlatformGetData(void* destination, uint32 elementSize,
uint32 x, uint32 y, uint32 width, uint32 height, int renderTarget, uint32 arraySlice, uint32 mipLevel); // mapType?
public Result<void> GetData<T>(T* data, int renderTarget, uint32 left, uint32 top, uint32 width, uint32 height, uint32 arraySlice = 0, uint32 mipSlice = 0)
{
Log.EngineLogger.AssertDebug(left + width < Width);
Log.EngineLogger.AssertDebug(top + height < Height);
return PlatformGetData(data, (.)sizeof(T), left, top, width, height, renderTarget, arraySlice, mipSlice);
}
}
}
+23 -9
View File
@@ -12,7 +12,7 @@ namespace GlitchyEngine.Renderer
public Matrix ViewProjection;
public Vector3 CameraPosition;
public RenderTarget2D CameraTarget;
public RenderTarget2D CompositionTarget;
public RenderTargetGroup CompositionTarget;
}
struct ObjectConstants
@@ -78,11 +78,12 @@ namespace GlitchyEngine.Renderer
.(RenderTargetFormat.R16G16B16A16_SNorm){SamplerDescription = desc},
.(RenderTargetFormat.R16G16B16A16_SNorm){SamplerDescription = desc},
.(RenderTargetFormat.R32G32B32A32_Float){SamplerDescription = desc},
.(RenderTargetFormat.R8G8B8A8_UNorm){SamplerDescription = desc}
.(RenderTargetFormat.R8G8B8A8_UNorm){SamplerDescription = desc},
.(RenderTargetFormat.R32_UInt){SamplerDescription = desc, ClearColor = ColorRGBA(0, 0, 0, 0)},
),
TargetDescription(.D24_UNorm_S8_UInt){
SamplerDescription = desc,
ClearColor = .(1.0f, 0, 0)
ClearColor = .DepthStencil(1.0f, 0)
});
Target = new RenderTargetGroup(targetDesc);
}
@@ -167,6 +168,7 @@ namespace GlitchyEngine.Renderer
RenderCommand.Init();
Renderer2D.Init();
FullscreenQuad.Init();
InitLineRenderer(effectLibrary);
InitDeferredRenderer(effectLibrary);
@@ -179,7 +181,8 @@ namespace GlitchyEngine.Renderer
DeinitDeferredRenderer();
DeinitLineRenderer();
FullscreenQuad.Deinit();
Renderer2D.Deinit();
_context.ReleaseRef();
@@ -303,7 +306,7 @@ namespace GlitchyEngine.Renderer
//_sceneConstants.Update();
}
public static void BeginScene(Camera camera, Matrix transform, RenderTarget2D renderTarget, RenderTarget2D finalTarget)
public static void BeginScene(Camera camera, Matrix transform, RenderTarget2D renderTarget, RenderTargetGroup finalTarget)
{
Debug.Profiler.ProfileRendererFunction!();
@@ -314,7 +317,7 @@ namespace GlitchyEngine.Renderer
_sceneConstants.CompositionTarget = finalTarget;
}
public static void BeginScene(EditorCamera camera, RenderTarget2D finalTarget)
public static void BeginScene(EditorCamera camera, RenderTargetGroup finalTarget)
{
Debug.Profiler.ProfileRendererFunction!();
@@ -390,6 +393,8 @@ namespace GlitchyEngine.Renderer
entry.Material.SetVariable("Transform", entry.Transform);
entry.Material.SetVariable("EntityId", entry.EntityId);
Matrix3x3 mat = (Matrix3x3)(entry.Transform).Invert().Transpose();
entry.Material.SetVariable("Transform_InvT", mat);
}
@@ -446,7 +451,7 @@ namespace GlitchyEngine.Renderer
RenderCommand.SetBlendState(_gBufferBlend);
RenderCommand.SetRenderTarget(_sceneConstants.CompositionTarget, 0, false);
RenderCommand.SetRenderTargetGroup(_sceneConstants.CompositionTarget, true);
RenderCommand.BindRenderTargets();
// TODO: Postprocessing effects
@@ -491,12 +496,14 @@ namespace GlitchyEngine.Renderer
public GeometryBinding Mesh;
public Material Material;
public Matrix Transform;
public uint32 EntityId;
public this(GeometryBinding mesh, Material material, Matrix transform)
public this(GeometryBinding mesh, Material material, Matrix transform, uint32 id)
{
Mesh = mesh..AddRef();
Material = material..AddRef();
Transform = transform;
EntityId = id;
}
public void Dispose()
@@ -525,7 +532,14 @@ namespace GlitchyEngine.Renderer
{
Debug.Profiler.ProfileRendererFunction!();
_queue.Add(SubmittedMesh(geometry, material, transform));
_queue.Add(SubmittedMesh(geometry, material, transform, 0));
}
public static void Submit(GeometryBinding geometry, Material material, EcsEntity entity, Matrix transform = .Identity)
{
Debug.Profiler.ProfileRendererFunction!();
_queue.Add(SubmittedMesh(geometry, material, transform, entity.[Friend]Index));
}
public static void Submit(SceneLight light, Matrix transform = .Identity)
+2 -1
View File
@@ -21,7 +21,8 @@ namespace GlitchyEngine.Renderer
public extern void Clear(DepthStencilTarget target, ClearOptions options, float depth, uint8 stencil);
public extern void Clear(RenderTargetGroup renderTarget, ClearOptions options, ColorRGBA? color = null, float? depth = null, uint8? stencil = null);
//public extern void Clear(RenderTargetGroup renderTarget, ClearOptions options, ColorRGBA? color = null, float? depth = null, uint8? stencil = null);
public extern void Clear(RenderTargetGroup renderTarget, ClearOptions options, ClearColor? color = null, float? depth = null, uint8? stencil = null);
public void Clear(RenderTarget2D renderTarget, ClearOptions options, ColorRGBA color, float depth, uint8 stencil)
{