Instrumentation

This commit is contained in:
Simon Lübeß
2022-01-14 21:49:15 +01:00
parent 78faf4cb81
commit 06469f3350
44 changed files with 481 additions and 30 deletions
+7 -1
View File
@@ -3,7 +3,7 @@ Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", DirectXTK = "*", F
[Project]
Name = "GlitchyEngine"
ProcessorMacros = ["GE_GRAPHICS_DX11", "GE_PROFILE", "GE_SHADER_MATRIX_MISMATCH_IS_ERROR", "GE_SHADER_VAR_TYPE_MISMATCH_IS_ERROR", "GE_SHADER_UNUSED_VARIABLE_IS_WARNING", "GE_WINDOWS"]
ProcessorMacros = ["GE_GRAPHICS_DX11", "GE_SHADER_MATRIX_MISMATCH_IS_ERROR", "GE_SHADER_VAR_TYPE_MISMATCH_IS_ERROR", "GE_SHADER_UNUSED_VARIABLE_IS_WARNING", "GE_WINDOWS"]
[Configs.Paranoid.Win32]
PreprocessorMacros = ["DEBUG", "PARANOID", "GE_WINDOWS"]
@@ -14,8 +14,14 @@ PreprocessorMacros = ["DEBUG", "PARANOID", "GE_WINDOWS"]
[Configs.Release.Win32]
PreprocessorMacros = ["RELEASE", "GE_WINDOWS"]
[Configs.Release.Win64]
PreprocessorMacros = ["RELEASE", "GE_PROFILE"]
[Configs.Test.Win32]
PreprocessorMacros = ["TEST", "GE_WINDOWS"]
[Configs.Test.Win64]
PreprocessorMacros = ["TEST", "GE_WINDOWS"]
[Configs.Debug.Win64]
PreprocessorMacros = ["DEBUG", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES"]
+27 -2
View File
@@ -2,6 +2,7 @@ using System;
using GlitchyEngine.Events;
using GlitchyEngine.ImGui;
using GlitchyEngine.Renderer;
using GlitchyEngine.Debug;
namespace GlitchyEngine
{
@@ -34,6 +35,8 @@ namespace GlitchyEngine
public this()
{
Profiler.ProfileFunction!();
Log.EngineLogger.Assert(s_Instance == null, "Tried to create a second application.");
s_Instance = this;
@@ -57,6 +60,8 @@ namespace GlitchyEngine
public ~this()
{
Profiler.ProfileFunction!();
delete _layerStack;
SamplerStateManager.Uninit();
Renderer.Deinit();
@@ -65,6 +70,8 @@ namespace GlitchyEngine
public void OnEvent(Event e)
{
Debug.Profiler.ProfileFunction!();
if(!_running)
return;
@@ -90,8 +97,12 @@ namespace GlitchyEngine
public void Run()
{
Debug.Profiler.ProfileFunction!();
while(_running)
{
Debug.Profiler.ProfileScope!("Loop");
if(allowFrame)
{
_gameTime.NewFrame();
@@ -110,6 +121,8 @@ namespace GlitchyEngine
if(allowFrame && !_isMinimized)
{
Debug.Profiler.ProfileScope!("Update Layers");
for(Layer layer in _layerStack)
layer.Update(_gameTime);
}
@@ -125,9 +138,21 @@ namespace GlitchyEngine
}
}
public void PushLayer(Layer ownLayer) => _layerStack.PushLayer(ownLayer);
public void PushLayer(Layer ownLayer)
{
Profiler.ProfileFunction!();
public void PushOverlay(Layer ownOverlay) => _layerStack.PushOverlay(ownOverlay);
_layerStack.PushLayer(ownLayer);
ownLayer.OnAttach();
}
public void PushOverlay(Layer ownOverlay)
{
Profiler.ProfileFunction!();
_layerStack.PushOverlay(ownOverlay);
ownOverlay.OnAttach();
}
public bool OnWindowClose(WindowCloseEvent e)
{
+34
View File
@@ -36,6 +36,40 @@ namespace GlitchyEngine.Debug
{
scope:mixin PerformanceTimer(scopeName)
}
// Extension
#if !GE_PROFILE_RENDERER
[SkipCall]
#endif
public static mixin ProfileRendererFunction()
{
scope:mixin PerformanceTimer()
}
#if !GE_PROFILE_RENDERER
[SkipCall]
#endif
public static mixin ProfileRendererScope(char8* scopeName)
{
scope:mixin PerformanceTimer(scopeName)
}
#if !GE_PROFILE_RESOURCES
[SkipCall]
#endif
public static mixin ProfileResourceFunction()
{
scope:mixin PerformanceTimer()
}
#if !GE_PROFILE_RESOURCES
[SkipCall]
#endif
public static mixin ProfileResourceScope(char8* scopeName)
{
scope:mixin PerformanceTimer(scopeName)
}
}
class PerformanceTimer
+14 -1
View File
@@ -20,6 +20,8 @@ namespace GlitchyEngine.ImGui
public override void OnAttach()
{
Debug.Profiler.ProfileFunction!();
//ImGuiImplWin32.EnableDpiAwareness();
Log.EngineLogger.Trace("Initializing ImGui...");
@@ -56,6 +58,8 @@ namespace GlitchyEngine.ImGui
public override void OnDetach()
{
Debug.Profiler.ProfileFunction!();
ImGuiImplDX11.Shutdown();
ImGuiImplWin32.Shutdown();
ImGui.DestroyContext();
@@ -184,6 +188,8 @@ namespace GlitchyEngine.ImGui
public void Begin()
{
Debug.Profiler.ProfileFunction!();
// Todo:
//var v = DirectX.ImmediateContext;
//v.OutputMerger.SetRenderTargets(1, &DirectX.BackBufferTarget, null);
@@ -198,11 +204,16 @@ namespace GlitchyEngine.ImGui
bool showDemo = true;
public void ImGuiRender()
{
Debug.Profiler.ProfileFunction!();
Begin();
{
Debug.Profiler.ProfileScope!("ImGuiRenderEvent");
var event = scope ImGuiRenderEvent();
Application.Get().OnEvent(event);
}
//ImGui.ShowDemoWindow(&showDemo);
End();
@@ -210,6 +221,8 @@ namespace GlitchyEngine.ImGui
public void End()
{
Debug.Profiler.ProfileFunction!();
ImGui.IO* io = ImGui.GetIO();
let window = Application.Get().Window;
-2
View File
@@ -29,7 +29,6 @@ namespace GlitchyEngine
public void PushLayer(Layer ownLayer)
{
_layers.Insert(_insertIndex++, ownLayer);
ownLayer.OnAttach();
}
/**
@@ -40,7 +39,6 @@ namespace GlitchyEngine
public void PushOverlay(Layer ownOverlay)
{
_layers.Add(ownOverlay);
ownOverlay.OnAttach();
}
/**
@@ -23,6 +23,8 @@ namespace GlitchyEngine
public this(float aspectRatio, bool rotation = false)
{
Debug.Profiler.ProfileFunction!();
_aspectRatio = aspectRatio;
_rotation = rotation;
@@ -35,6 +37,8 @@ namespace GlitchyEngine
public void Update(GameTime gameTime)
{
Debug.Profiler.ProfileFunction!();
if(Application.Get().Window.IsActive)
{
Vector3 movement = .();
@@ -82,6 +86,8 @@ namespace GlitchyEngine
public void OnEvent(Event e)
{
Debug.Profiler.ProfileFunction!();
EventDispatcher dispatcher = EventDispatcher(e);
dispatcher.Dispatch<MouseScrolledEvent>(scope => OnMouseScrolled);
dispatcher.Dispatch<WindowResizeEvent>(scope => OnWindowResized);
@@ -89,6 +95,8 @@ namespace GlitchyEngine
private bool OnMouseScrolled(MouseScrolledEvent e)
{
Debug.Profiler.ProfileFunction!();
_zoomLevel -= e.YOffset * 0.25f;
_zoomLevel = Math.Max(_zoomLevel, 0.25f);
@@ -100,6 +108,8 @@ namespace GlitchyEngine
private bool OnWindowResized(WindowResizeEvent e)
{
Debug.Profiler.ProfileFunction!();
_aspectRatio = (float)e.Width / (float)e.Height;
UpdateCamera();
@@ -109,6 +119,8 @@ namespace GlitchyEngine
private void UpdateCamera()
{
Debug.Profiler.ProfileFunction!();
_camera.Left = -_aspectRatio * _zoomLevel;
_camera.Right = _aspectRatio * _zoomLevel;
_camera.Top = _zoomLevel;
@@ -83,6 +83,8 @@ namespace GlitchyEngine
public this(float aspectRatio)
{
Debug.Profiler.ProfileFunction!();
_aspectRatio = aspectRatio;
_camera = new PerspectiveCamera();
@@ -94,6 +96,8 @@ namespace GlitchyEngine
public void Update(GameTime gameTime)
{
Debug.Profiler.ProfileFunction!();
if(Application.Get().Window.IsActive)
{
Vector3 movement = .();
@@ -150,12 +154,16 @@ namespace GlitchyEngine
public void OnEvent(Event e)
{
Debug.Profiler.ProfileFunction!();
EventDispatcher dispatcher = EventDispatcher(e);
dispatcher.Dispatch<WindowResizeEvent>(scope => OnWindowResized);
}
private bool OnWindowResized(WindowResizeEvent e)
{
Debug.Profiler.ProfileFunction!();
_aspectRatio = (float)e.Width / (float)e.Height;
UpdateCamera();
@@ -165,6 +173,8 @@ namespace GlitchyEngine
private void UpdateCamera()
{
Debug.Profiler.ProfileFunction!();
_camera.AspectRatio = _aspectRatio;
_camera.FovY = _fovY;
_camera.Rotation = _cameraRotation;
@@ -21,6 +21,8 @@ namespace GlitchyEngine.Platform.DX11
internal static void Dx11Init()
{
Debug.Profiler.ProfileFunction!();
if(!IsDx11Initialized)
{
Log.EngineLogger.Trace("Creating D3D11 Device and Context...");
@@ -33,10 +35,18 @@ namespace GlitchyEngine.Platform.DX11
FeatureLevel[] levels = scope .(.Level_11_0);
FeatureLevel deviceLevel = ?;
var deviceResult = D3D11.CreateDevice(null, .Hardware, 0, deviceFlags, levels, &NativeDevice, &deviceLevel, &NativeContext);
HResult deviceResult;
{
Debug.Profiler.ProfileScope!("D3D11.CreateDevice");
deviceResult = D3D11.CreateDevice(null, .Hardware, 0, deviceFlags, levels, &NativeDevice, &deviceLevel, &NativeContext);
}
Log.EngineLogger.Assert(deviceResult.Succeeded, scope $"Failed to create D3D11 Device. Message({(int32)deviceResult}): {deviceResult}");
#if DEBUG
{
Debug.Profiler.ProfileScope!("Query for ID3D11Debug");
if(NativeDevice.QueryInterface<ID3D11Debug>(out DebugDevice).Succeeded)
{
ID3D11InfoQueue* infoQueue;
@@ -48,6 +58,7 @@ namespace GlitchyEngine.Platform.DX11
infoQueue.Release();
}
}
}
#endif
Log.EngineLogger.Trace($"D3D11 Device and Context created (Feature level: {deviceLevel})");
@@ -63,6 +74,8 @@ namespace GlitchyEngine.Platform.DX11
internal static void Dx11Release()
{
Debug.Profiler.ProfileFunction!();
NativeDevice.Release();
NativeContext.Release();
DebugDevice.ReportLiveDeviceObjects(.Detail);
@@ -17,6 +17,8 @@ namespace GlitchyEngine.Renderer
protected override void PlatformCreateBlendState()
{
Debug.Profiler.ProfileResourceFunction!();
BlendDescription nativeDesc = .Default;
nativeDesc.IndependentBlendEnable = _desc.IndependentBlendEnable;
nativeDesc.AlphaToCoverageEnable = _desc.AlphaToCoverageEnable;
@@ -60,6 +60,8 @@ namespace GlitchyEngine.Renderer
private Result<void> InternalCreateBuffer(void* data, uint32 byteLength, uint32 dstByteOffset)
{
Debug.Profiler.ProfileResourceFunction!();
nativeDescription = (.)_description;
uint8* byteData = (.)data;
@@ -84,6 +86,8 @@ namespace GlitchyEngine.Renderer
protected override Result<void> PlatformSetData(void* data, uint32 byteLength, uint32 dstByteOffset, GlitchyEngine.Renderer.MapType mapType)
{
Debug.Profiler.ProfileResourceFunction!();
if(nativeBuffer == null)
{
// We can pass the data while creating the buffer, so we can return here.
@@ -12,6 +12,8 @@ namespace GlitchyEngine.Renderer
internal void PlatformFetchNativeBuffers()
{
Debug.Profiler.ProfileRendererFunction!();
for(let buffer in _buffers)
{
nativeBuffers[buffer.Index] = buffer.Buffer.nativeBuffer;
@@ -12,6 +12,8 @@ namespace GlitchyEngine.Renderer
{
internal this(ConstantBuffer constantBuffer, ID3D11ShaderReflectionVariable* variableReflection)
{
Debug.Profiler.ProfileResourceFunction!();
_constantBuffer = constantBuffer;
HResult result = variableReflection.GetDescription(let variableDescription);
@@ -51,6 +53,8 @@ namespace GlitchyEngine.Renderer
{
internal this(ID3D11ShaderReflectionConstantBuffer* bufferReflection)
{
Debug.Profiler.ProfileResourceFunction!();
Reflect(bufferReflection);
ConstructBuffer();
@@ -60,6 +64,8 @@ namespace GlitchyEngine.Renderer
private void Reflect(ID3D11ShaderReflectionConstantBuffer* bufferReflection)
{
Debug.Profiler.ProfileResourceFunction!();
HResult result = bufferReflection.GetDescription(let bufferDescription);
Log.EngineLogger.Assert(result.Succeeded, scope $"Failed to get buffer description. Error({(int)result}): {result}");
@@ -47,6 +47,8 @@ namespace GlitchyEngine.Renderer
public this(GEDSSDesc description)
{
Debug.Profiler.ProfileResourceFunction!();
_description = description;
nativeDescription = (.)description;
@@ -36,6 +36,8 @@ namespace GlitchyEngine.Renderer
protected override void PlatformCreate()
{
Debug.Profiler.ProfileResourceFunction!();
Texture2DDescription desc = .();
desc.Format = (.)_format;
desc.ArraySize = 1;
@@ -12,6 +12,8 @@ namespace GlitchyEngine.Renderer
{
protected override void Compile(String vsPath, String vsEntry, String psPath, String psEntry)
{
Debug.Profiler.ProfileResourceFunction!();
// Todo: macros
VertexShader = new VertexShader(vsPath, vsEntry);
PixelShader = new PixelShader(psPath, psEntry);
@@ -31,6 +31,8 @@ namespace GlitchyEngine.Renderer
protected override void PlatformSetVertexBuffer(VertexBufferBinding binding, uint32 slot)
{
Debug.Profiler.ProfileResourceFunction!();
Log.EngineLogger.Assert(slot < nativeBuffers.Count, "The buffer slot has to be in the range from 0 to 31.");
VertexBuffer vertexBuffer = binding.Buffer;
@@ -59,12 +61,16 @@ namespace GlitchyEngine.Renderer
protected override void PlatformSetVertexLayout(VertexLayout vertexLayout)
{
Debug.Profiler.ProfileResourceFunction!();
nativeVertexLayout?.Release();
nativeVertexLayout = vertexLayout?.nativeLayout..AddRef();
}
protected override void PlatformSetIndexBuffer(IndexBuffer indexBuffer)
{
Debug.Profiler.ProfileResourceFunction!();
Log.EngineLogger.Assert(indexBuffer.nativeDescription.BindFlags.HasFlag(.IndexBuffer),
scope $"Buffer ({indexBuffer.nativeBuffer.GetDebugName(.. scope .())}) must have IndexBuffer-flag set to be bound as an index buffer.");
@@ -79,6 +85,8 @@ namespace GlitchyEngine.Renderer
public override void Bind()
{
Debug.Profiler.ProfileRendererFunction!();
NativeContext.InputAssembler.SetVertexBuffers(0, nativeBuffers.Count, &nativeBuffers, &bufferStrides, &bufferOffsets);
NativeContext.InputAssembler.SetInputLayout(_vertexLayout.nativeLayout);
NativeContext.InputAssembler.SetPrimitiveTopology((.)_primitiveTopology);
@@ -89,6 +97,8 @@ namespace GlitchyEngine.Renderer
public override void Unbind()
{
Debug.Profiler.ProfileRendererFunction!();
ID3D11Buffer*[nativeBuffers.Count] nullBuffers = .();
uint32[nativeBuffers.Count] zeroStrides = .();
uint32[nativeBuffers.Count] zeroOffsets = .();
@@ -38,6 +38,8 @@ namespace GlitchyEngine.Renderer
public this(Windows.HWnd windowHandle)
{
Debug.Profiler.ProfileFunction!();
nativeWindowHandle = windowHandle;
_swapChain = new SwapChain(this);
@@ -47,6 +49,8 @@ namespace GlitchyEngine.Renderer
public ~this()
{
Debug.Profiler.ProfileFunction!();
delete _swapChain;
Dx11Release();
@@ -54,6 +58,8 @@ namespace GlitchyEngine.Renderer
public override void Init()
{
Debug.Profiler.ProfileFunction!();
Dx11Init();
SwapChain.Init();
@@ -177,6 +183,8 @@ namespace GlitchyEngine.Renderer
*/
private void BindShaderToStage<TShader>(TShader shader) where TShader : Shader
{
Debug.Profiler.ProfileRendererFunction!();
uint32 _firstTexture = D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT;
uint32 _textureCount = 0;
@@ -16,6 +16,8 @@ namespace GlitchyEngine.Renderer
public override void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null)
{
Debug.Profiler.ProfileRendererFunction!();
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "ps_5_0", DefaultCompileFlags, out nativeCode);
var result = NativeDevice.CreatePixelShader(nativeCode.GetBufferPointer(), nativeCode.GetBufferSize(), null, &nativeShader);
@@ -54,6 +54,8 @@ namespace GlitchyEngine.Renderer
public override this(GlitchyEngine.Renderer.RasterizerStateDescription description)
{
Debug.Profiler.ProfileRendererFunction!();
_description = description;
nativeDescription = (.)_description;
@@ -19,6 +19,8 @@ namespace GlitchyEngine.Renderer
private void ReleaseAndNullify()
{
Debug.Profiler.ProfileResourceFunction!();
ReleaseAndNullify!(_nativeTexture);
ReleaseAndNullify!(_nativeResourceView);
ReleaseAndNullify!(_nativeRenderTargetView);
@@ -28,6 +30,8 @@ namespace GlitchyEngine.Renderer
public override void Resize(uint32 width, uint32 height)
{
Debug.Profiler.ProfileResourceFunction!();
ReleaseAndNullify();
_description.Width = width;
@@ -38,6 +42,8 @@ namespace GlitchyEngine.Renderer
protected override void PlatformApplyChanges()
{
Debug.Profiler.ProfileResourceFunction!();
ReleaseAndNullify();
PlatformCreateTexture();
@@ -62,6 +68,8 @@ namespace GlitchyEngine.Renderer
private void PlatformCreateTexture()
{
Debug.Profiler.ProfileResourceFunction!();
Texture2DDescription desc = .()
{
Width = _description.Width,
@@ -87,6 +95,8 @@ namespace GlitchyEngine.Renderer
private void CreateViews()
{
Debug.Profiler.ProfileResourceFunction!();
var result = NativeDevice.CreateShaderResourceView(_nativeTexture, null, &_nativeResourceView);
Log.EngineLogger.Assert(result.Succeeded, "Failed to create resource view");
@@ -24,7 +24,7 @@ namespace GlitchyEngine.Renderer
public override void Init()
{
Debug.Profiler.ProfileFunction!();
}
private mixin RtOrBackbuffer(RenderTarget2D renderTarget)
@@ -34,11 +34,15 @@ namespace GlitchyEngine.Renderer
public override void Clear(RenderTarget2D renderTarget, ColorRGBA color)
{
Debug.Profiler.ProfileRendererFunction!();
NativeContext.ClearRenderTargetView(RtOrBackbuffer!(renderTarget)._nativeRenderTargetView, color);
}
public override void Clear(DepthStencilTarget target, ClearOptions clearOptions, float depth, uint8 stencil)
{
Debug.Profiler.ProfileRendererFunction!();
if(target == null)
return;
@@ -59,16 +63,22 @@ namespace GlitchyEngine.Renderer
public override void SetRenderTarget(RenderTarget2D renderTarget, int slot, bool setDepthBuffer)
{
Debug.Profiler.ProfileRendererFunction!();
_context.SetRenderTarget(renderTarget, slot, setDepthBuffer);
}
public override void SetDepthStencilTarget(DepthStencilTarget target)
{
Debug.Profiler.ProfileRendererFunction!();
_context.SetDepthStencilTarget(target);
}
public override void BindRenderTargets()
{
Debug.Profiler.ProfileRendererFunction!();
_context.BindRenderTargets();
}
@@ -76,6 +86,8 @@ namespace GlitchyEngine.Renderer
public override void SetRasterizerState(RasterizerState rasterizerState)
{
Debug.Profiler.ProfileRendererFunction!();
SetReference!(_currentRasterizerState, rasterizerState);
NativeContext.Rasterizer.SetState(_currentRasterizerState.nativeRasterizerState);
}
@@ -84,6 +96,8 @@ namespace GlitchyEngine.Renderer
public override void SetBlendState(BlendState blendState, ColorRGBA blendFactor)
{
Debug.Profiler.ProfileRendererFunction!();
SetReference!(_currentBlendState, blendState);
NativeContext.OutputMerger.SetBlendState(_currentBlendState.nativeBlendState, blendFactor);
}
@@ -92,12 +106,16 @@ namespace GlitchyEngine.Renderer
public override void SetDepthStencilState(DepthStencilState depthStencilState, uint8 stencilReference)
{
Debug.Profiler.ProfileRendererFunction!();
SetReference!(_currentDepthStencilState, depthStencilState);
NativeContext.OutputMerger.SetDepthStencilState(_currentDepthStencilState.nativeDepthStencilState, stencilReference);
}
public override void DrawIndexed(GeometryBinding geometry)
{
Debug.Profiler.ProfileRendererFunction!();
if(geometry.IsIndexed)
_context.DrawIndexed(geometry.IndexCount, geometry.IndexByteOffset, 0);
else
@@ -106,11 +124,15 @@ namespace GlitchyEngine.Renderer
public override void DrawIndexedInstanced(GeometryBinding geometry)
{
Debug.Profiler.ProfileRendererFunction!();
NativeContext.DrawIndexedInstanced(geometry.IndexCount, geometry.InstanceCount, geometry.IndexByteOffset, 0, 0);
}
public override void SetViewport(Viewport viewport)
{
Debug.Profiler.ProfileRendererFunction!();
_context.SetViewport(viewport);
}
}
@@ -111,6 +111,8 @@ namespace GlitchyEngine.Renderer
protected override void PlatformCreateSamplerState()
{
Debug.Profiler.ProfileResourceFunction!();
_desc.ToNative(var nativeDesc);
HResult result = NativeDevice.CreateSamplerState(ref nativeDesc, &nativeSamplerState);
@@ -27,6 +27,8 @@ namespace GlitchyEngine.Renderer
internal static void PlattformCompileShaderFromSource(String code, ShaderDefine[] macros, String entryPoint, String target, ShaderCompileFlags compileFlags, out ID3DBlob* shaderBlob)
{
Debug.Profiler.ProfileResourceFunction!();
ShaderMacro* nativeMacros = macros == null ? null : new:ScopedAlloc! ShaderMacro[macros.Count]*;
for(int i < macros?.Count ?? 0)
@@ -51,6 +53,8 @@ namespace GlitchyEngine.Renderer
protected internal void Reflect(ID3DBlob* shaderCode)
{
Debug.Profiler.ProfileResourceFunction!();
ID3D11ShaderReflection* reflection = null;
var result = D3DCompiler.D3DReflect(shaderCode.GetBufferPointer(), shaderCode.GetBufferSize(), &reflection);
if(result.Failed)
@@ -17,6 +17,8 @@ namespace GlitchyEngine.Renderer
public this(GraphicsContext context)
{
Debug.Profiler.ProfileFunction!();
_context = context;
SetResolutionFromWindow();
@@ -24,6 +26,8 @@ namespace GlitchyEngine.Renderer
public ~this()
{
Debug.Profiler.ProfileFunction!();
nativeDxgiDevice?.Release();
nativeSwapChain?.Release();
}
@@ -38,11 +42,15 @@ namespace GlitchyEngine.Renderer
public override void Init()
{
Debug.Profiler.ProfileFunction!();
ApplyChanges();
}
public override void ApplyChanges()
{
Debug.Profiler.ProfileFunction!();
if(!_changed)
return;
@@ -54,6 +62,8 @@ namespace GlitchyEngine.Renderer
*/
public void UpdateSwapchain()
{
Debug.Profiler.ProfileFunction!();
Log.EngineLogger.Trace($"Updating swap chain ({_width}, {_height})");
uint32 backBufferCount = 2;
@@ -112,12 +122,16 @@ namespace GlitchyEngine.Renderer
internal void GetBackbuffer(out ID3D11Texture2D* texture)
{
Debug.Profiler.ProfileResourceFunction!();
var result = nativeSwapChain.GetBuffer<ID3D11Texture2D>(0, out texture);
Log.EngineLogger.Assert(result.Succeeded, "Failed to get backbuffer.");
}
public override void Present()
{
Debug.Profiler.ProfileFunction!();
nativeSwapChain.Present(Application.Get().Window.IsVSync ? 1 : 0, .None);
}
}
@@ -34,6 +34,8 @@ namespace GlitchyEngine.Renderer
*/
protected bool LoadResourcePlatform<T>(StringView path, ref T* texture) where T : ID3D11Resource
{
Debug.Profiler.ProfileResourceFunction!();
((ID3D11Resource*)texture)?.Release();
nativeResourceView?.Release();
@@ -92,6 +94,8 @@ namespace GlitchyEngine.Renderer
protected override void LoadTexturePlatform()
{
Debug.Profiler.ProfileResourceFunction!();
LoadResourcePlatform(_path, ref nativeTexture);
let resType = nativeTexture.GetResourceType();
@@ -102,12 +106,16 @@ namespace GlitchyEngine.Renderer
protected override void CreateTexturePlatform(Texture2DDesc desc, bool isRenderTarget, void* data, uint32 linePitch)
{
Debug.Profiler.ProfileResourceFunction!();
PrepareTexturePlatform(desc, isRenderTarget);
InternalCreateTexture(data, linePitch, 0);
}
private void InternalCreateTexture(void* data, uint32 linePitch, uint32 slicePitch)
{
Debug.Profiler.ProfileResourceFunction!();
SubresourceData resData = .(data, linePitch, slicePitch);
// If data is null, set subresourceData null
@@ -122,6 +130,8 @@ namespace GlitchyEngine.Renderer
protected override void PrepareTexturePlatform(Texture2DDesc desc, bool isRenderTarget)
{
Debug.Profiler.ProfileResourceFunction!();
nativeTexture?.Release();
nativeTexture = null;
nativeResourceView?.Release();
@@ -137,6 +147,8 @@ namespace GlitchyEngine.Renderer
protected override System.Result<void> PlatformSetData(void* data, uint32 elementSize, uint32 destX,
uint32 destY, uint32 destWidth, uint32 destHeight, uint32 arraySlice, uint32 mipLevel, GlitchyEngine.Renderer.MapType mapType)
{
Debug.Profiler.ProfileResourceFunction!();
if(nativeTexture == null)
{
if(destX == 0 && destY == 0 && destWidth == nativeDesc.Width && destHeight == nativeDesc.Height)
@@ -189,6 +201,8 @@ namespace GlitchyEngine.Renderer
ResourceBox sourceBox = default, uint32 destX = 0, uint32 destY = 0,
uint32 srcArraySlice = 0, uint32 srcMipSlice = 0, uint32 destArraySlice = 0, uint32 destMipSlice = 0)
{
Debug.Profiler.ProfileResourceFunction!();
Log.EngineLogger.AssertDebug(source != destination || srcArraySlice != destArraySlice
|| srcMipSlice != destMipSlice, "Cannot copy from and to the same sub resource.");
@@ -215,6 +229,8 @@ namespace GlitchyEngine.Renderer
public override void CopyTo(Texture2D destination)
{
Debug.Profiler.ProfileResourceFunction!();
if(nativeTexture == null)
return;
@@ -252,6 +268,8 @@ namespace GlitchyEngine.Renderer
protected override void LoadTexturePlatform()
{
Debug.Profiler.ProfileResourceFunction!();
LoadResourcePlatform(_path, ref nativeTexture);
let resType = nativeTexture.GetResourceType();
@@ -37,6 +37,8 @@ namespace GlitchyEngine.Renderer
protected override void CreateNativeLayout()
{
Debug.Profiler.ProfileResourceFunction!();
var nativeElements = scope InputElementDescription[_elements.Count];
ToNativeLayout(_elements, nativeElements);
@@ -17,6 +17,8 @@ namespace GlitchyEngine.Renderer
public override void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null)
{
Debug.Profiler.ProfileResourceFunction!();
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "vs_5_0", DefaultCompileFlags, out nativeCode);
var result = NativeDevice.CreateVertexShader(nativeCode.GetBufferPointer(), nativeCode.GetBufferSize(), null, &nativeShader);
@@ -163,6 +163,8 @@ namespace GlitchyEngine
public override static void NewFrame()
{
Debug.Profiler.ProfileFunction!();
Swap!(CurrentState, LastState);
// Get current keyboard state
@@ -160,6 +160,8 @@ namespace GlitchyEngine
public override this(WindowDescription desc)
{
Debug.Profiler.ProfileFunction!();
_minMaxInfo.MaximumTrackingSize.x = int32.MaxValue;
_minMaxInfo.MaximumTrackingSize.y = int32.MaxValue;
@@ -174,6 +176,8 @@ namespace GlitchyEngine
public ~this()
{
Debug.Profiler.ProfileFunction!();
if(!DestroyWindow(_windowHandle))
{
HResult res = (.)GetLastError();
@@ -188,6 +192,8 @@ namespace GlitchyEngine
private void Init(WindowDescription desc)
{
Debug.Profiler.ProfileFunction!();
Log.EngineLogger.Trace($"Creating window \"{desc.Title}\" ({desc.Width}, {desc.Height})...");
_instanceHandle = (.)GetModuleHandleW(null);
@@ -497,6 +503,8 @@ namespace GlitchyEngine
public override void Update()
{
Debug.Profiler.ProfileFunction!();
Message message = .();
while (PeekMessageW(&message, 0, 0, 0, .Remove))
{
+5
View File
@@ -1,5 +1,6 @@
using System;
using GlitchLog;
using GlitchyEngine.Debug;
using System.Diagnostics;
namespace GlitchyEngine
@@ -11,6 +12,8 @@ namespace GlitchyEngine
public static int Main(String[] args)
{
Debug.Profiler.BeginProfiling();
Log.EngineLogger.Info("Initializing Application...");
Stopwatch initWatch = scope Stopwatch();
@@ -30,6 +33,8 @@ namespace GlitchyEngine
Log.EngineLogger.Info("Application uninitialized.");
Debug.Profiler.EndProfiling();
return 0;
}
}
+7
View File
@@ -80,11 +80,18 @@ namespace GlitchyEngine.Renderer
public this(BlendStateDescription desc)
{
Debug.Profiler.ProfileResourceFunction!();
_desc = desc;
PlatformCreateBlendState();
}
public ~this()
{
Debug.Profiler.ProfileResourceFunction!();
}
protected extern void PlatformCreateBlendState();
}
}
@@ -15,6 +15,8 @@ namespace GlitchyEngine.Renderer
[AllowAppend]
public this()
{
Debug.Profiler.ProfileResourceFunction!();
// Todo: append allocate as soon as it's fixed
let buffers = new List<BufferEntry>();
let strToBuf = new Dictionary<String, BufferEntry*>();
@@ -25,6 +27,11 @@ namespace GlitchyEngine.Renderer
_idxToBuf = idxToBuf;
}
public ~this()
{
Debug.Profiler.ProfileResourceFunction!();
}
mixin DeleteBufferEntries(List<BufferEntry> entries)
{
if(entries == null)
@@ -54,6 +61,8 @@ namespace GlitchyEngine.Renderer
public BufferEntry* TryGetBufferEntry(String name)
{
Debug.Profiler.ProfileResourceFunction!();
if(_strToBuf.TryGetValue(name, let buffer))
{
return buffer;
@@ -64,6 +73,8 @@ namespace GlitchyEngine.Renderer
public BufferEntry* TryGetBufferEntry(int index)
{
Debug.Profiler.ProfileResourceFunction!();
if(_idxToBuf.TryGetValue(index, let buffer))
{
return buffer;
@@ -80,6 +91,8 @@ namespace GlitchyEngine.Renderer
*/
public bool TryReplaceBuffer(int idx, Buffer buffer)
{
Debug.Profiler.ProfileResourceFunction!();
if(_idxToBuf.TryGetValue(idx, let bufferEntry))
{
Log.EngineLogger.Assert(idx == bufferEntry.Index);
@@ -105,6 +118,8 @@ namespace GlitchyEngine.Renderer
*/
public bool TryReplaceBuffer(String name, Buffer buffer)
{
Debug.Profiler.ProfileResourceFunction!();
if(_strToBuf.TryGetValue(name, let bufferEntry))
{
Log.EngineLogger.AssertDebug(name == bufferEntry.Name);
@@ -129,6 +144,8 @@ namespace GlitchyEngine.Renderer
public void Add(BufferEntry entry)
{
Debug.Profiler.ProfileResourceFunction!();
BufferEntry copy = (new String(entry.Name), entry.Index, entry.Buffer..AddRef());
_buffers.Add(copy);
@@ -146,6 +163,8 @@ namespace GlitchyEngine.Renderer
*/
int GetIndexOfBuffer(Buffer buffer)
{
Debug.Profiler.ProfileResourceFunction!();
for(int i < _buffers.Count)
{
// Only check for reference equality.
@@ -165,6 +184,8 @@ namespace GlitchyEngine.Renderer
*/
String GetNameOfBuffer(Buffer buffer)
{
Debug.Profiler.ProfileResourceFunction!();
for(int i < _buffers.Count)
{
// Only check for reference equality.
+40
View File
@@ -25,6 +25,8 @@ namespace GlitchyEngine.Renderer
public void Add(Effect effect, String effectName = null)
{
Debug.Profiler.ProfileResourceFunction!();
String name;
if(effectName == null)
@@ -51,6 +53,8 @@ namespace GlitchyEngine.Renderer
*/
public Effect Load(String filepath, String effectName = null)
{
Debug.Profiler.ProfileResourceFunction!();
String name = effectName;
if(name == null)
@@ -80,6 +84,8 @@ namespace GlitchyEngine.Renderer
public Effect Get(String effectName)
{
Debug.Profiler.ProfileResourceFunction!();
Log.EngineLogger.AssertDebug(Exists(effectName), "Effect not found!");
return _effects.GetValue(effectName).Get()..AddRef();
@@ -137,6 +143,8 @@ namespace GlitchyEngine.Renderer
public this(String filename, String vsEntry, String psEntry, String shaderName = null)
{
Debug.Profiler.ProfileResourceFunction!();
CompileFromFile(filename, vsEntry, psEntry);
if(shaderName == null)
@@ -152,6 +160,8 @@ namespace GlitchyEngine.Renderer
public this(String filename, String shaderName = null)
{
Debug.Profiler.ProfileResourceFunction!();
String fileContent = scope String();
String vsName = scope String();
String psName = scope String();
@@ -175,6 +185,8 @@ namespace GlitchyEngine.Renderer
public this(String shaderName, String vsPath, String vsEntry, String psPath, String psEntry)
{
Debug.Profiler.ProfileResourceFunction!();
Compile(vsPath, vsEntry, psPath, psEntry);
_name = new String(shaderName);
@@ -182,6 +194,8 @@ namespace GlitchyEngine.Renderer
public ~this()
{
Debug.Profiler.ProfileResourceFunction!();
for(let entry in _textures)
{
entry.value.Texture?.ReleaseRef();
@@ -190,6 +204,8 @@ namespace GlitchyEngine.Renderer
public void SetTexture(String name, Texture texture)
{
Debug.Profiler.ProfileRendererFunction!();
ref TextureEntry entry = ref _textures[name];
entry.Texture?.ReleaseRef();
@@ -199,6 +215,8 @@ namespace GlitchyEngine.Renderer
private void ApplyTextures()
{
Debug.Profiler.ProfileRendererFunction!();
for(let (name, entry) in _textures)
{
entry.VsSlot?.Texture?.ReleaseRef();
@@ -213,6 +231,8 @@ namespace GlitchyEngine.Renderer
private void ApplyChanges()
{
Debug.Profiler.ProfileRendererFunction!();
for(let buffer in _bufferCollection)
{
if(let cbuffer = buffer.Buffer as ConstantBuffer)
@@ -224,6 +244,8 @@ namespace GlitchyEngine.Renderer
public void Bind(GraphicsContext context)
{
Debug.Profiler.ProfileRendererFunction!();
ApplyTextures();
ApplyChanges();
@@ -235,6 +257,8 @@ namespace GlitchyEngine.Renderer
private void CompileFromFile(String filename, String vsEntry, String psEntry)
{
Debug.Profiler.ProfileResourceFunction!();
let vs = Shader.FromFile!<VertexShader>(filename, vsEntry);
VertexShader = vs;
vs.ReleaseRef();
@@ -245,6 +269,8 @@ namespace GlitchyEngine.Renderer
private void Compile(String fileContent, String vsEntry, String psEntry)
{
Debug.Profiler.ProfileResourceFunction!();
// TODO: vsEntry and psEntry could be empty (which is a valid case.)
let vs = new VertexShader(fileContent, vsEntry);
VertexShader = vs;
@@ -265,6 +291,8 @@ namespace GlitchyEngine.Renderer
*/
private static void ProcessFile(String filename, String fileContent, String vsName, String psName)
{
Debug.Profiler.ProfileResourceFunction!();
File.ReadAllText(filename, fileContent, true);
// append line ending just in case the file doesn't end with one.
fileContent.Append('\n');
@@ -324,6 +352,8 @@ namespace GlitchyEngine.Renderer
private void MergeResources()
{
Debug.Profiler.ProfileResourceFunction!();
MergeConstantBuffers();
MergeBufferVariables();
MergeTextures();
@@ -331,6 +361,8 @@ namespace GlitchyEngine.Renderer
private void MergeConstantBuffers()
{
Debug.Profiler.ProfileResourceFunction!();
_bufferCollection = new BufferCollection();
HashSet<String> bufferNames = scope HashSet<String>();
@@ -374,6 +406,8 @@ namespace GlitchyEngine.Renderer
private void MergeBufferVariables()
{
Debug.Profiler.ProfileResourceFunction!();
_variables = new BufferVariableCollection(false);
for(let buffer in _bufferCollection)
@@ -390,6 +424,8 @@ namespace GlitchyEngine.Renderer
private void AddShaderBuffers(Shader shader, HashSet<String> bufferNames)
{
Debug.Profiler.ProfileResourceFunction!();
if(shader != null)
{
for(let buffer in shader.Buffers)
@@ -402,6 +438,8 @@ namespace GlitchyEngine.Renderer
/// Merges the texture slots of all shaders into one dictionary.
private void MergeTextures()
{
Debug.Profiler.ProfileResourceFunction!();
delete _textures;
_textures = new .();
@@ -414,6 +452,8 @@ namespace GlitchyEngine.Renderer
*/
private void EnumerateShaderTextures<T>(T shader) where T : Shader
{
Debug.Profiler.ProfileResourceFunction!();
//for(var (name, index, texture) in shader.Resources)
for(var shaderEntry in ref shader.Textures)
{
@@ -80,11 +80,15 @@ namespace GlitchyEngine.Renderer
protected override void UpdateProjection()
{
Debug.Profiler.ProfileFunction!();
_projection = Matrix.OrthographicProjectionOffCenter(_left, _right, _top, _bottom, _nearPlane, _farPlane);
}
protected override void UpdateTransform()
{
Debug.Profiler.ProfileFunction!();
_transform = Matrix.Translation(_position) * Matrix.RotationZ(_rotation.Z) * Matrix.RotationY(_rotation.Y) * Matrix.RotationX(_rotation.X);
_view = _transform.Invert();
}
@@ -78,6 +78,8 @@ namespace GlitchyEngine.Renderer
protected override void UpdateProjection()
{
Debug.Profiler.ProfileFunction!();
if(_projectionType == .Limited || _projectionType == .LimitedReversed)
Log.EngineLogger.AssertDebug(_nearPlane < _farPlane, "The near plane must be smaller than the far plane.");
@@ -98,6 +100,8 @@ namespace GlitchyEngine.Renderer
protected override void UpdateTransform()
{
Debug.Profiler.ProfileFunction!();
_transform = Matrix.Translation(_position) * Matrix.RotationZ(_rotation.Z) * Matrix.RotationY(_rotation.Y) * Matrix.RotationX(_rotation.X);
_view = _transform.Invert();
}
@@ -32,6 +32,8 @@ namespace GlitchyEngine.Renderer
[Inline]
public static void Init()
{
Debug.Profiler.ProfileFunction!();
_rendererAPI.Init();
}
@@ -63,6 +63,8 @@ namespace GlitchyEngine.Renderer
public this(RenderTarget2DDescription description)
{
Debug.Profiler.ProfileResourceFunction!();
_description = description;
ApplyChanges();
+20 -1
View File
@@ -29,6 +29,8 @@ namespace GlitchyEngine.Renderer
public static void Init(GraphicsContext context, EffectLibrary effectLibrary)
{
Debug.Profiler.ProfileFunction!();
_context = context..AddRef();
/*
_sceneConstants = new Buffer<SceneConstants>(.(0, .Constant, .Dynamic, .Write));
@@ -46,11 +48,15 @@ namespace GlitchyEngine.Renderer
public static void Deinit()
{
Debug.Profiler.ProfileFunction!();
Renderer2D.Deinit();
}
static void InitLineRenderer(EffectLibrary effectLibrary)
{
Debug.Profiler.ProfileFunction!();
LineEffect = effectLibrary.Load("content\\Shaders\\lineShader.hlsl");
LineGeometry = new GeometryBinding();
@@ -75,6 +81,8 @@ namespace GlitchyEngine.Renderer
public static void BeginScene(EcsWorld world, Entity cameraEntity)
{
Debug.Profiler.ProfileRendererFunction!();
var camera = world.GetComponent<CameraComponent>(cameraEntity);
var transform = world.GetComponent<TransformComponent>(cameraEntity);
@@ -87,15 +95,22 @@ namespace GlitchyEngine.Renderer
public static void BeginScene(Camera camera)
{
Debug.Profiler.ProfileRendererFunction!();
_sceneConstants.ViewProjection = camera.ViewProjection;
//_sceneConstants.Data.ViewProjection = camera.ViewProjection;
//_sceneConstants.Update();
}
public static void EndScene(){}
public static void EndScene()
{
Debug.Profiler.ProfileRendererFunction!();
}
public static void Submit(GeometryBinding geometry, Effect effect, Matrix transform = .Identity)
{
Debug.Profiler.ProfileRendererFunction!();
//effect.PixelShader?.Buffers.TryReplaceBuffer("SceneConstants", _sceneConstants);
//effect.VertexShader?.Buffers.TryReplaceBuffer("SceneConstants", _sceneConstants);
@@ -116,6 +131,8 @@ namespace GlitchyEngine.Renderer
public static void Submit(GeometryBinding geometry, Material material, Matrix transform = .Identity)
{
Debug.Profiler.ProfileRendererFunction!();
material.SetVariable("ViewProjection", _sceneConstants.ViewProjection);
material.SetVariable("Transform", transform);
@@ -175,6 +192,8 @@ namespace GlitchyEngine.Renderer
*/
public static void DrawLine(Vector4 start, Vector4 end, Color color, Matrix transform)
{
Debug.Profiler.ProfileRendererFunction!();
LineVertices.SetData(Vector4[2](start, end), 0, .WriteDiscard);
LineEffect.Variables["ViewProjection"].SetData(_sceneConstants.ViewProjection * transform);
LineEffect.Variables["Color"].SetData(color);
+32
View File
@@ -135,12 +135,16 @@ namespace GlitchyEngine.Renderer
private static void InitEffect()
{
Debug.Profiler.ProfileFunction!();
s_batchEffect = new Effect("content\\Shaders\\spritebatch.hlsl");
s_circleBatchEffect = new Effect("content\\Shaders\\circlebatch.hlsl");
}
private static void InitGeometry()
{
Debug.Profiler.ProfileFunction!();
s_quadGeometry = new GeometryBinding();
s_quadGeometry.SetPrimitiveTopology(.TriangleList);
@@ -171,6 +175,8 @@ namespace GlitchyEngine.Renderer
private static void InitInstancingGeometry()
{
Debug.Profiler.ProfileFunction!();
{
s_instanceBuffer = new VertexBuffer(typeof(BatchVertex), 1024, .Dynamic, .Write);
s_instanceBuffer.SetData(0);
@@ -242,6 +248,8 @@ namespace GlitchyEngine.Renderer
private static void InitWhitetexture()
{
Debug.Profiler.ProfileFunction!();
// Create a texture with a single white pixel
Texture2DDesc tex2Ddesc = .{
Format = .R8G8B8A8_UNorm,
@@ -266,6 +274,8 @@ namespace GlitchyEngine.Renderer
public static void Init()
{
Debug.Profiler.ProfileFunction!();
InitEffect();
InitGeometry();
InitInstancingGeometry();
@@ -280,6 +290,7 @@ namespace GlitchyEngine.Renderer
public static void Deinit()
{
Debug.Profiler.ProfileFunction!();
#if DEBUG
Log.EngineLogger.AssertDebug(s_initialized, "Renderer2D was not initialized.");
#endif
@@ -313,6 +324,7 @@ namespace GlitchyEngine.Renderer
public static void BeginScene(OrthographicCamera camera, DrawOrder drawOrder = .SortByTexture, Effect effect = null, Effect circleEffect = null)
{
Debug.Profiler.ProfileRendererFunction!();
#if DEBUG
Log.EngineLogger.AssertDebug(s_initialized, "Renderer2D was not initialized.");
Log.EngineLogger.AssertDebug(!s_sceneRunning, "You have to call EndScene before you can make another call to BeginScene.");
@@ -352,6 +364,7 @@ namespace GlitchyEngine.Renderer
public static void EndScene()
{
Debug.Profiler.ProfileRendererFunction!();
#if DEBUG
Log.EngineLogger.AssertDebug(s_sceneRunning, "Missing call of BeginScene.");
#endif
@@ -364,6 +377,7 @@ namespace GlitchyEngine.Renderer
public static void Flush()
{
Debug.Profiler.ProfileFunction!();
#if DEBUG
Log.EngineLogger.AssertDebug(s_sceneRunning, "Missing call of BeginScene.");
#endif
@@ -388,6 +402,8 @@ namespace GlitchyEngine.Renderer
private static void FlushInstances()
{
Debug.Profiler.ProfileRendererFunction!();
if(s_setInstances == 0)
return;
@@ -403,6 +419,8 @@ namespace GlitchyEngine.Renderer
private static void FlushCircleInstances()
{
Debug.Profiler.ProfileRendererFunction!();
if(s_setInstances == 0)
return;
@@ -446,6 +464,8 @@ namespace GlitchyEngine.Renderer
private static void SortInstances()
{
Debug.Profiler.ProfileRendererFunction!();
switch(s_drawOrder)
{
case .SortByTexture:
@@ -465,6 +485,8 @@ namespace GlitchyEngine.Renderer
private static void DrawDeferred()
{
Debug.Profiler.ProfileRendererFunction!();
if(s_instanceQueue.IsEmpty && s_circleInstanceQueue.IsEmpty)
return;
@@ -476,6 +498,8 @@ namespace GlitchyEngine.Renderer
private static void DrawDeferredQuads()
{
Debug.Profiler.ProfileRendererFunction!();
if(s_instanceQueue.IsEmpty)
return;
@@ -512,6 +536,8 @@ namespace GlitchyEngine.Renderer
private static void DrawDeferredCircles()
{
Debug.Profiler.ProfileRendererFunction!();
if(s_circleInstanceQueue.IsEmpty)
return;
@@ -583,6 +609,8 @@ namespace GlitchyEngine.Renderer
public static void DrawQuad(Vector3 position, Vector2 size, float rotation, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1))
{
Debug.Profiler.ProfileRendererFunction!();
#if DEBUG
Log.EngineLogger.AssertDebug(s_sceneRunning, "Missing call of BeginScene.");
#endif
@@ -599,6 +627,8 @@ namespace GlitchyEngine.Renderer
public static void DrawQuad(Matrix transform, Texture2D texture, ColorRGBA color = .White, Vector4 uvTransform = .(0, 0, 1, 1))
{
Debug.Profiler.ProfileRendererFunction!();
#if DEBUG
Log.EngineLogger.AssertDebug(s_sceneRunning, "Missing call of BeginScene.");
#endif
@@ -636,6 +666,8 @@ namespace GlitchyEngine.Renderer
public static void DrawCircle(Vector3 position, Vector2 size, Texture2D texture, ColorRGBA color = .White, float innerRadius = 1.0f, Vector4 uvTransform = .(0, 0, 1, 1))
{
#if DEBUG
Debug.Profiler.ProfileRendererFunction!();
Log.EngineLogger.AssertDebug(s_sceneRunning, "Missing call of BeginScene.");
#endif
@@ -23,6 +23,8 @@ namespace GlitchyEngine.Renderer
public void Clear(RenderTarget2D renderTarget, ClearOptions options, ColorRGBA color, float depth, uint8 stencil)
{
Debug.Profiler.ProfileRendererFunction!();
var actualRt = (renderTarget ?? GraphicsContext.Get().SwapChain.BackBuffer);
if(options.HasFlag(.Color))
@@ -164,6 +164,8 @@ namespace GlitchyEngine.Renderer
public static void Init()
{
Debug.Profiler.ProfileFunction!();
_samplers = new .();
// Init point samplers
@@ -230,6 +232,8 @@ namespace GlitchyEngine.Renderer
public static void Uninit()
{
Debug.Profiler.ProfileFunction!();
PointClamp.ReleaseRef();
PointWrap.ReleaseRef();
LinearClamp.ReleaseRef();
@@ -249,6 +253,8 @@ namespace GlitchyEngine.Renderer
*/
public static SamplerState GetSampler(SamplerStateDescription desc)
{
Debug.Profiler.ProfileResourceFunction!();
Log.EngineLogger.AssertDebug(_samplers != null, "SamplerStateManager was not initialized.");
if(_samplers.TryGetValue(desc, let sampler))
@@ -299,6 +305,8 @@ namespace GlitchyEngine.Renderer
public this(SamplerStateDescription desc)
{
Debug.Profiler.ProfileResourceFunction!();
_desc = desc;
PlatformCreateSamplerState();
@@ -306,6 +314,8 @@ namespace GlitchyEngine.Renderer
public ~this()
{
Debug.Profiler.ProfileResourceFunction!();
SamplerStateManager.[Friend]Remove(this);
}
+5 -1
View File
@@ -32,6 +32,8 @@ namespace GlitchyEngine.Renderer
[AllowAppend]
public this(String source, String entryPoint, ShaderDefine[] macros = null)
{
Debug.Profiler.ProfileResourceFunction!();
// Todo: append as soon as it's fixed.
//let buffers = new BufferCollection();
_buffers = new BufferCollection();
@@ -42,11 +44,13 @@ namespace GlitchyEngine.Renderer
public ~this()
{
Debug.Profiler.ProfileResourceFunction!();
}
public static mixin FromFile<T>(String fileName, String entryPoint, ShaderDefine[] macros = null) where T : Shader
{
Debug.Profiler.ProfileResourceFunction!();
String fileContent = new String();
File.ReadAllText(fileName, fileContent, true);
+49 -3
View File
@@ -115,6 +115,8 @@ namespace GlitchyEngine.Renderer.Text
public this(String fontPath, uint32 fontSize, bool hasColor = true, char32 firstChar = '\0', uint32 charCount = 128, int32 faceIndex = 0)
{
Debug.Profiler.ProfileResourceFunction!();
// Make sure the fontrenderer is initialized (Font only cares about freetype)
FontRenderer.Init();
@@ -125,11 +127,19 @@ namespace GlitchyEngine.Renderer.Text
_faceIndex = faceIndex;
_hasColor = hasColor;
var res = FreeType.New_Face(FontRenderer.s_Library, fontPath, faceIndex, &_face);
Log.EngineLogger.Assert(res.Success, scope $"New_Face failed({(int)res}): {res}");
{
Debug.Profiler.ProfileResourceScope!("Freetype.New_Face");
res = FreeType.Set_Pixel_Sizes(_face, 0, _fontSize);
FT_Error res = FreeType.New_Face(FontRenderer.s_Library, fontPath, faceIndex, &_face);
Log.EngineLogger.Assert(res.Success, scope $"New_Face failed({(int)res}): {res}");
}
{
Debug.Profiler.ProfileResourceScope!("Freetype.Set_Pixel_Sizes");
FT_Error res = FreeType.Set_Pixel_Sizes(_face, 0, _fontSize);
Log.EngineLogger.Assert(res.Success, scope $"Set_Pixel_Sizes failed({(int)res}): {res}");
}
double unitsPerEm = F26Dot6ToDouble(_face.units_per_EM);
_geometryScaler = _fontSize / unitsPerEm;
@@ -147,6 +157,8 @@ namespace GlitchyEngine.Renderer.Text
// HarfBuzz
{
Debug.Profiler.ProfileResourceScope!("hb_ft_font_create_referenced");
_harfBuzzFont = hb_ft_font_create_referenced(_face);
hb_font_set_scale(_harfBuzzFont, (.)fontSize * 64, (.)fontSize * 64);
}
@@ -156,6 +168,8 @@ namespace GlitchyEngine.Renderer.Text
public void LoadGlyphs(char32 firstChar, uint32 charCount)
{
Debug.Profiler.ProfileResourceFunction!();
ExtendRange(firstChar, firstChar + charCount);
UpdateAtlas();
@@ -163,6 +177,8 @@ namespace GlitchyEngine.Renderer.Text
public void LoadGlyphs(uint32 firstGlyph, uint32 charCount)
{
Debug.Profiler.ProfileResourceFunction!();
ExtendRange(firstGlyph, firstGlyph + charCount);
UpdateAtlas();
@@ -237,6 +253,8 @@ namespace GlitchyEngine.Renderer.Text
void ExtendRange(char32 firstChar, char32 rangeEnd)
{
Debug.Profiler.ProfileResourceFunction!();
// TODO: refactor
for(char32 char = firstChar; char < rangeEnd; char++)
@@ -266,6 +284,8 @@ namespace GlitchyEngine.Renderer.Text
void ExtendRange(uint32 firstGlyph, uint32 rangeEnd)
{
Debug.Profiler.ProfileResourceFunction!();
// TODO: refactor
for(uint32 glyphId = firstGlyph; glyphId < rangeEnd; glyphId++)
@@ -317,6 +337,8 @@ namespace GlitchyEngine.Renderer.Text
Int3 PrepareAtlas()
{
Debug.Profiler.ProfileResourceFunction!();
const uint32 maxRes = 16384; // D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION
const uint32 maxArray = 2048; // D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION
@@ -398,11 +420,15 @@ namespace GlitchyEngine.Renderer.Text
void DrawAtlas()
{
Debug.Profiler.ProfileResourceFunction!();
Int3 oldAtlasSize = _atlasSize;
_atlasSize = PrepareAtlas();
if(_atlasSize != oldAtlasSize)
{
Debug.Profiler.ProfileResourceScope!("Recreate Atlas");
var oldAtlas = _atlas;
Texture2DDesc desc;
@@ -444,20 +470,31 @@ namespace GlitchyEngine.Renderer.Text
bool Calculate(ref GlyphDescriptor desc)
{
Debug.Profiler.ProfileResourceFunction!();
// prepare shape
double advance = 0;
Shape shape;
{
Debug.Profiler.ProfileResourceScope!("msdfgen.LoadGlyph");
if(!msdfgen.LoadGlyph(out shape, ref _face, desc.GlyphIndex, out advance) || !shape.Validate())
{
return false;
}
}
desc.Advance = (float)(advance * _geometryScaler);
//shape.OrientContours();
{
Debug.Profiler.ProfileResourceScope!("msdfgen.ResolveShapeGeometry");
msdfgen.ResolveShapeGeometry(shape);
}
shape.Normalize();
@@ -616,12 +653,19 @@ namespace GlitchyEngine.Renderer.Text
void GenerateMSDF(GlyphDescriptor desc)
{
Debug.Profiler.ProfileResourceFunction!();
// prepare shape
double advance = 0;
Shape shape;
{
Debug.Profiler.ProfileResourceScope!("msdfgen.LoadGlyph");
msdfgen.LoadGlyph(out shape, ref _face, desc.GlyphIndex, out advance);
}
msdfgen.ResolveShapeGeometry(shape);
@@ -646,6 +690,8 @@ namespace GlitchyEngine.Renderer.Text
using(Bitmap<ColorRGB, const 1> bitmap = .((.)bufferX, (.)bufferY))
{
Debug.Profiler.ProfileResourceScope!("GenerateMSDF");
MSDFGeneratorConfig config = .();
msdfgen.GenerateMSDF(*(Bitmap<float, const 3>*)&bitmap, shape, projection, _range, config);
@@ -20,6 +20,8 @@ namespace GlitchyEngine.Renderer.Text
internal static void Init()
{
Debug.Profiler.ProfileFunction!();
if(s_isInitialized)
return;
@@ -32,6 +34,8 @@ namespace GlitchyEngine.Renderer.Text
internal static void Deinit()
{
Debug.Profiler.ProfileFunction!();
_msdfEffect.ReleaseRef();
DeinitFreetype();
@@ -41,6 +45,8 @@ namespace GlitchyEngine.Renderer.Text
private static void InitFreetype()
{
Debug.Profiler.ProfileFunction!();
if(s_Library == null)
{
var res = FreeType.Init_FreeType(&s_Library);
@@ -50,6 +56,8 @@ namespace GlitchyEngine.Renderer.Text
private static void DeinitFreetype()
{
Debug.Profiler.ProfileFunction!();
FreeType.Done_FreeType(s_Library);
}
@@ -117,6 +125,8 @@ namespace GlitchyEngine.Renderer.Text
public static PreparedText PrepareText(Font font, String text, float fontSize, Color fontColor = .White, Color bitmapColor = .White, float lineSpaceScale = 1.0f, TextDirection direction = .LeftToRight)
{
Debug.Profiler.ProfileRendererFunction!();
if(text.IsWhiteSpace)
return .Empty;
@@ -152,6 +162,8 @@ namespace GlitchyEngine.Renderer.Text
void FlushShapeBuffer()
{
Debug.Profiler.ProfileRendererFunction!();
float fontScale = (float)fontSize / currentFont._fontSize;
hb_buffer_clear_contents(buf);
@@ -294,6 +306,8 @@ namespace GlitchyEngine.Renderer.Text
public static void DrawText(PreparedText text, float x, float y)
{
Debug.Profiler.ProfileRendererFunction!();
text.AddRef();
defer text.ReleaseRef();
@@ -396,6 +410,8 @@ namespace GlitchyEngine.Renderer.Text
*/
public static void DrawText(Font font, String text, float x, float y, float fontSize, Color fontColor = .White, Color bitmapColor = .White, float lineGapOffset = 0)
{
Debug.Profiler.ProfileRendererFunction!();
if(text.IsWhiteSpace)
return;