First working effects with new pipeline

This commit is contained in:
Simon Lübeß
2024-08-22 00:34:20 +02:00
parent 7b7a3dc645
commit 66e62f42ec
20 changed files with 652 additions and 43 deletions
+2 -1
View File
@@ -38,8 +38,9 @@ namespace GlitchyEngine.Renderer
[Inline]
internal uint8* firstByte => _constantBuffer.rawData.CArray() + _offset;
public this(ConstantBuffer constantBuffer, ShaderVariableType type, uint32 columns, uint32 rows, uint32 offset, uint32 sizeInBytes, uint32 elements, bool isUsed)
public this(StringView name, ConstantBuffer constantBuffer, ShaderVariableType type, uint32 columns, uint32 rows, uint32 offset, uint32 sizeInBytes, uint32 elements, bool isUsed)
{
_name = new String(name);
_constantBuffer = constantBuffer..AddRef();
_type = type;
_columns = columns;
+17 -2
View File
@@ -74,13 +74,28 @@ namespace GlitchyEngine.Renderer
public BufferVariableCollection Variables => _variables;
/// Gets a span to the rawData held on the CPU.
public Span<uint8> RawData => rawData;
protected this() {}
public this(StringView name, int64 size)
{
_name = new String(name);
rawData = new uint8[size];
ConstructBuffer();
}
protected internal void AddVariable(BufferVariable ownVariable)
{
_variables.Add(ownVariable);
}
public void AddVariable(StringView name, uint64 offset, uint64 sizeInBytes, bool isUsed, ShaderVariableType type, uint8 rows, uint8 columns, uint64 arraySize)
{
_variables.Add(new BufferVariable(name, this, type, columns, rows, (uint32)offset, (uint32)sizeInBytes, (uint32)arraySize, isUsed));
}
/**
* Construct the buffer description.
*/
@@ -96,9 +111,9 @@ namespace GlitchyEngine.Renderer
/**
* Uploads the date to the GPU.
*/
public void Update()
public Result<void> Update()
{
PlatformSetData(rawData.CArray(), (uint32)rawData.Count, 0, .WriteDiscard);
return PlatformSetData(rawData.CArray(), (uint32)rawData.Count, 0, .WriteDiscard);
}
}
+11 -3
View File
@@ -65,7 +65,7 @@ public class Effect : Asset
}
}
Dictionary<String, TextureEntry> _textures ~ delete _;
Dictionary<String, TextureEntry> _textures ~ DeleteDictionaryAndKeys!(_);
public Dictionary<String, TextureEntry> Textures => _textures;
@@ -99,7 +99,8 @@ public class Effect : Asset
MergeResources();
}
[Obsolete("", false)]
public this(Stream data, StringView assetIdentifier, IContentManager contentManager)
{
Debug.Profiler.ProfileResourceFunction!();
@@ -115,6 +116,13 @@ public class Effect : Asset
MergeResources();
}
public this()
{
_bufferCollection = new BufferCollection();
_variables = new BufferVariableCollection(false);
_textures = new Dictionary<String, TextureEntry>();
}
public ~this()
{
Debug.Profiler.ProfileResourceFunction!();
@@ -668,7 +676,7 @@ public class Effect : Asset
}
// save entry
_textures[shaderEntry.Name] = entry;
_textures[new String(shaderEntry.Name)] = entry;
}
}
}
@@ -8,5 +8,7 @@ namespace GlitchyEngine.Renderer
[AllowAppend]
public this(StringView code, StringView? fileName, String entryPoint, IContentManager contentManager, ShaderDefine[] macros = null)
: base(code, fileName, entryPoint, contentManager, macros) { }
public this() : base() { }
}
}
+53 -15
View File
@@ -20,16 +20,29 @@ namespace GlitchyEngine.Renderer
}
}
public abstract class Shader : RefCounter
public enum ShaderType
{
Unknown,
Vertex,
Pixel
}
// TODO: We may not even need the distinction between shader types anymore (maybe just as an enum)
public abstract class
Shader : RefCounter
{
protected internal BufferCollection _buffers ~ _.ReleaseRef();//:append _;
protected ShaderTextureCollection _textures ~ delete _;
protected ShaderType _shaderType;
public BufferCollection Buffers => _buffers;
public ShaderTextureCollection Textures => _textures;
public ShaderType ShaderType => _shaderType;
[AllowAppend]
public this(StringView code, StringView? fileName, String entryPoint, IContentManager contentManager, ShaderDefine[] macros = null)
{
@@ -43,24 +56,49 @@ namespace GlitchyEngine.Renderer
CompileFromSource(code, fileName, entryPoint, contentManager);
}
public this()
{
_buffers = new BufferCollection();
_textures = new ShaderTextureCollection();
}
public static Result<Shader> CreateFromBlob(Span<uint8> shaderBlob, ShaderType shaderType)
{
Shader shader = null;
defer
{
if (@return case .Err)
{
shader?.ReleaseRef();
}
}
switch (shaderType)
{
case .Vertex:
shader = new VertexShader();
case .Pixel:
shader = new PixelShader();
default:
Log.EngineLogger.Error($"Can't create shader of type {shaderType}");
return .Err;
}
shader._shaderType = shaderType;
Try!(shader.InternalCreateFromBlob(shaderBlob));
return shader;
}
public ~this()
{
Debug.Profiler.ProfileResourceFunction!();
}
/*public static mixin FromFile<T>(String fileName, String entryPoint, IContentManager contentManager, ShaderDefine[] macros = null) where T : Shader
{
Debug.Profiler.ProfileResourceFunction!();
String fileContent = new String();
File.ReadAllText(fileName, fileContent, true);
T shader = new T(fileContent, (StringView)fileName, contentManager, entryPoint, macros);
delete fileContent;
shader
}*/
public abstract void CompileFromSource(StringView code, StringView? fileName, String entryPoint, IContentManager contentManager, ShaderDefine[] macros = null);
protected abstract Result<void> InternalCreateFromBlob(Span<uint8> blob);
}
}
@@ -38,6 +38,8 @@ namespace GlitchyEngine.Renderer
}
// TODO: finish implementation (like BufferCollection)
public ResourceEntry* this[int idx] => _idxToBuf[idx];
public ResourceEntry* this[String name] => _strToBuf[name];
public void Add(String name, uint32 index, TextureViewBinding texture, TextureDimension dimension)
{
@@ -2,6 +2,7 @@ using System;
namespace GlitchyEngine.Renderer
{
// TODO: I hate this. It is a reference counting struct?!
/// Represents a reference to a texture that can be used as shader input resource.
public struct TextureViewBinding : IRefCounted, IDisposable
{
@@ -11,6 +12,8 @@ namespace GlitchyEngine.Renderer
public extern void AddRef();
public extern void Release();
public static extern TextureViewBinding CreateDefault();
public void Dispose() => Release();
}
}
@@ -8,5 +8,7 @@ namespace GlitchyEngine.Renderer
[AllowAppend]
public this(StringView code, StringView? fileName, String entryPoint, IContentManager contentManager = null, ShaderDefine[] macros = null)
: base(code, fileName, entryPoint, contentManager, macros) { }
public this() : base() { }
}
}