Skip to content

Commit

Permalink
The graphics service has been refactored to operate on a separate thr…
Browse files Browse the repository at this point in the history
…ead, allowing for parallel processing between the CPU and GPU, significantly improving performance and responsiveness.

The Direct3D 11 (D3D11) driver now caches states between submission calls. This optimization reduces redundant state changes and improves overall rendering efficiency.

The serialization module has been improved to eliminate the need for explicitly marking classes with "Serializable". This streamlines the serialization process and reduces boilerplate code.

Added support for serializing Matrix4 objects.

The 2D rendering module has been temporarily removed to address underlying issues and facilitate planned enhancements.
  • Loading branch information
Wolftein committed Nov 20, 2024
1 parent f768ec8 commit 27790e6
Show file tree
Hide file tree
Showing 52 changed files with 941 additions and 1,628 deletions.
2 changes: 1 addition & 1 deletion Source/Private/Aurora.Content/Model/GLTF/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace Content
for (UInt32 ID = 0; Ref<const tinygltf::Material> GLTFMaterial : GLTFModel.materials)
{
const SPtr<Graphic::Material> Material = NewPtr<Graphic::Material>(Uri { GLTFMaterial.name });
Material->SetResidence(true);
Material->SetOwnership(true);

if (SInt32 Index = GLTFMaterial.pbrMetallicRoughness.baseColorTexture.index; Index >= 0)
{
Expand Down
57 changes: 26 additions & 31 deletions Source/Private/Aurora.Graphic/D3D11/D3D11Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,13 @@ namespace Graphic
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void D3D11Driver::CopyBuffer(Object Destination, UInt32 DstOffset, Object Source, UInt32 SrcOffset, UInt32 Size)
void D3D11Driver::CopyBuffer(Object DstBuffer, UInt32 DstOffset, Object SrcBuffer, UInt32 SrcOffset, UInt32 Size)
{
const D3D11_BOX Offset = CD3D11_BOX(SrcOffset, 0, 0, SrcOffset + Size, 1, 1);
const D3D11_COPY_FLAGS Flags = D3D11_COPY_NO_OVERWRITE;

mDeviceImmediate->CopySubresourceRegion1(
mBuffers[Destination].Object.Get(), 0, DstOffset, 0, 0, mBuffers[Source].Object.Get(), 0, & Offset, Flags);
mBuffers[DstBuffer].Object.Get(), 0, DstOffset, 0, 0, mBuffers[SrcBuffer].Object.Get(), 0, & Offset, Flags);
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Expand Down Expand Up @@ -758,7 +758,7 @@ namespace Graphic
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void D3D11Driver::CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt32 Width, UInt32 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data)
void D3D11Driver::CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt16 Width, UInt16 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data)
{
CD3D11_TEXTURE2D_DESC Description(As(Format), Width, Height, 1, Level);
Description.Usage = Data.empty() ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
Expand Down Expand Up @@ -802,36 +802,24 @@ namespace Graphic

void D3D11Driver::UpdateTexture(Object ID, UInt8 Level, Ref<const Recti> Offset, UInt32 Pitch, CPtr<const UInt8> Data)
{
const D3D11_BOX Rect {
static_cast<UINT>(Offset.GetLeft()),
static_cast<UINT>(Offset.GetTop()),
0,
static_cast<UINT>(Offset.GetRight()),
static_cast<UINT>(Offset.GetBottom()),
1
};
const D3D11_BOX Rect = CD3D11_BOX(
Offset.GetLeft(), Offset.GetTop(), 0, Offset.GetRight(), Offset.GetBottom(), 1);
mDeviceImmediate->UpdateSubresource(mTextures[ID].Object.Get(), Level, AddressOf(Rect), Data.data(), Pitch, 0);
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void D3D11Driver::CopyTexture(Object Destination, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object Source, UInt8 SrcLevel, Ref<const Recti> SrcOffset)
void D3D11Driver::CopyTexture(Object DstTexture, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object SrcTexture, UInt8 SrcLevel, Ref<const Recti> SrcOffset)
{
const D3D11_BOX Rect {
static_cast<UINT>(SrcOffset.GetLeft()),
static_cast<UINT>(SrcOffset.GetTop()),
0,
static_cast<UINT>(SrcOffset.GetRight()),
static_cast<UINT>(SrcOffset.GetBottom()),
1
};
const D3D11_BOX Rect = CD3D11_BOX(
SrcOffset.GetLeft(), SrcOffset.GetTop(), 0, SrcOffset.GetRight(), SrcOffset.GetBottom(), 1);

const Ptr<ID3D11Texture2D> DstTexture = mTextures[Destination].Object.Get();
const Ptr<ID3D11Texture2D> SrcTexture = mTextures[Source].Object.Get();
const Ptr<ID3D11Texture2D> DstResource = mTextures[DstTexture].Object.Get();
const Ptr<ID3D11Texture2D> SrcResource = mTextures[SrcTexture].Object.Get();

mDeviceImmediate->CopySubresourceRegion(
DstTexture, DstLevel, DstOffset.GetX(), DstOffset.GetY(), 0, SrcTexture, SrcLevel, AddressOf(Rect));
DstResource, DstLevel, DstOffset.GetX(), DstOffset.GetY(), 0, SrcResource, SrcLevel, AddressOf(Rect));
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Expand Down Expand Up @@ -937,14 +925,17 @@ namespace Graphic
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void D3D11Driver::Submit(CPtr<Submission> Submissions)
void D3D11Driver::Submit(CPtr<const Submission> Submissions)
{
constexpr Submission k_DefaultSubmission { .Scissor = { 0, 0, 0, 0 } };
static Submission s_PreviousFrameCache {
.Scissor = Rectf(0, 0, 0, 0)
};

// Apply all job(s).
for (UInt Batch = 0; Batch < Submissions.size(); ++Batch)
{
Ref<const Submission> NewestSubmission = Submissions[Batch];
Ref<const Submission> OldestSubmission = Batch > 0 ? Submissions[Batch - 1] : k_DefaultSubmission;
Ref<const Submission> OldestSubmission = Batch > 0 ? Submissions[Batch - 1] : s_PreviousFrameCache;

// Apply vertices
ApplyVertexResources(OldestSubmission, NewestSubmission);
Expand All @@ -964,11 +955,12 @@ namespace Graphic
// Apply the scissor rect
if (OldestSubmission.Scissor != NewestSubmission.Scissor)
{
const RECT Rect {
NewestSubmission.Scissor.GetLeft(), NewestSubmission.Scissor.GetTop(),
NewestSubmission.Scissor.GetRight(), NewestSubmission.Scissor.GetBottom()
};
mDeviceImmediate->RSSetScissorRects(1, & Rect);
const RECT Scissor = CD3D11_RECT(
NewestSubmission.Scissor.GetLeft(),
NewestSubmission.Scissor.GetTop(),
NewestSubmission.Scissor.GetRight(),
NewestSubmission.Scissor.GetBottom());
mDeviceImmediate->RSSetScissorRects(1, AddressOf(Scissor));
}

// Apply pipeline or stencil value
Expand Down Expand Up @@ -1054,6 +1046,9 @@ namespace Graphic
}
}
}

// Apply cache
s_PreviousFrameCache = Submissions.back();
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Expand Down
8 changes: 4 additions & 4 deletions Source/Private/Aurora.Graphic/D3D11/D3D11Driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Graphic
void CreateBuffer(Object ID, Usage Type, UInt32 Capacity, CPtr<const UInt8> Data) override;

// \see Driver::CopyBuffer
void CopyBuffer(Object Destination, UInt32 DstOffset, Object Source, UInt32 SrcOffset, UInt32 Size) override;
void CopyBuffer(Object DstBuffer, UInt32 DstOffset, Object SrcBuffer, UInt32 SrcOffset, UInt32 Size) override;

// \see Driver::UpdateBuffer
void UpdateBuffer(Object ID, Bool Discard, UInt32 Offset, CPtr<const UInt8> Data) override;
Expand All @@ -61,13 +61,13 @@ namespace Graphic
void DeletePipeline(Object ID) override;

// \see Driver::CreateTexture
void CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt32 Width, UInt32 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data) override;
void CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt16 Width, UInt16 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data) override;

// \see Driver::UpdateTexture
void UpdateTexture(Object ID, UInt8 Level, Ref<const Recti> Offset, UInt32 Pitch, CPtr<const UInt8> Data) override;

// \see Driver::CopyTexture
void CopyTexture(Object Destination, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object Source, UInt8 SrcLevel, Ref<const Recti> SrcOffset) override;
void CopyTexture(Object DstTexture, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object SrcTexture, UInt8 SrcLevel, Ref<const Recti> SrcOffset) override;

// \see Driver::ReadTexture
Data ReadTexture(Object ID, UInt8 Level, Ref<const Recti> Offset) override;
Expand All @@ -82,7 +82,7 @@ namespace Graphic
void Prepare(Object ID, Ref<const Rectf> Viewport, Clear Target, Color Tint, Real32 Depth, UInt8 Stencil) override;

// \see Driver::Submit
void Submit(CPtr<Submission> Submissions) override;
void Submit(CPtr<const Submission> Submissions) override;

// \see Driver::Commit
void Commit(Object ID, Bool Synchronised) override;
Expand Down
8 changes: 4 additions & 4 deletions Source/Private/Aurora.Graphic/GLES3/GLES3Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ namespace Graphic
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void GLES3Driver::CopyBuffer(Object Destination, UInt32 DstOffset, Object Source, UInt32 SrcOffset, UInt32 Size)
void GLES3Driver::CopyBuffer(Object DstBuffer, UInt32 DstOffset, Object SrcBuffer, UInt32 SrcOffset, UInt32 Size)
{

}
Expand Down Expand Up @@ -349,7 +349,7 @@ namespace Graphic
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void GLES3Driver::CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt32 Width, UInt32 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data)
void GLES3Driver::CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt16 Width, UInt16 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data)
{
}

Expand All @@ -363,7 +363,7 @@ namespace Graphic
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void GLES3Driver::CopyTexture(Object Destination, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object Source, UInt8 SrcLevel, Ref<const Recti> SrcOffset)
void GLES3Driver::CopyTexture(Object DstTexture, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object SrcTexture, UInt8 SrcLevel, Ref<const Recti> SrcOffset)
{
}

Expand Down Expand Up @@ -400,7 +400,7 @@ namespace Graphic
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

void GLES3Driver::Submit(CPtr<Submission> Submissions)
void GLES3Driver::Submit(CPtr<const Submission> Submissions)
{
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Private/Aurora.Graphic/GLES3/GLES3Driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Graphic
void CreateBuffer(Object ID, Usage Type, UInt32 Capacity, CPtr<const UInt8> Data) override;

// \see Driver::CopyBuffer
void CopyBuffer(Object Destination, UInt32 DstOffset, Object Source, UInt32 SrcOffset, UInt32 Size) override;
void CopyBuffer(Object DstBuffer, UInt32 DstOffset, Object SrcBuffer, UInt32 SrcOffset, UInt32 Size) override;

// \see Driver::UpdateBuffer
void UpdateBuffer(Object ID, Bool Discard, UInt32 Offset, CPtr<const UInt8> Data) override;
Expand All @@ -61,13 +61,13 @@ namespace Graphic
void DeletePipeline(Object ID) override;

// \see Driver::CreateTexture
void CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt32 Width, UInt32 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data) override;
void CreateTexture(Object ID, TextureFormat Format, TextureLayout Layout, UInt16 Width, UInt16 Height, UInt8 Level, UInt8 Samples, CPtr<const UInt8> Data) override;

// \see Driver::UpdateTexture
void UpdateTexture(Object ID, UInt8 Level, Ref<const Recti> Offset, UInt32 Pitch, CPtr<const UInt8> Data) override;

// \see Driver::CopyTexture
void CopyTexture(Object Destination, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object Source, UInt8 SrcLevel, Ref<const Recti> SrcOffset) override;
void CopyTexture(Object DstTexture, UInt8 DstLevel, Ref<const Vector2i> DstOffset, Object SrcTexture, UInt8 SrcLevel, Ref<const Recti> SrcOffset) override;

// \see Driver::ReadTexture
Data ReadTexture(Object ID, UInt8 Level, Ref<const Recti> Offset) override;
Expand All @@ -82,7 +82,7 @@ namespace Graphic
void Prepare(Object ID, Ref<const Rectf> Viewport, Clear Target, Color Tint, Real32 Depth, UInt8 Stencil) override;

// \see Driver::Submit
void Submit(CPtr<Submission> Submissions) override;
void Submit(CPtr<const Submission> Submissions) override;

// \see Driver::Commit
void Commit(Object ID, Bool Synchronised) override;
Expand Down
10 changes: 7 additions & 3 deletions Source/Public/Aurora.Base/Base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
// [ HEADER ]
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

#include "IO/Serializable.hpp"
#include "Container/Handle.hpp"
#include "Container/Pool.hpp"
#include "Container/Stack.hpp"

#include "IO/Reader.hpp"
#include "IO/Stream.hpp"
#include "IO/Writer.hpp"
#include "IO/TOML/Parser.hpp"

#include "Logger/Log.hpp"

#include "Memory/Data.hpp"
#include "Memory/Pool.hpp"
#include "Memory/Stack.hpp"

#include "Subsystem/Subsystem.hpp"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// [ HEADER ]
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

#include "Aurora.Base/Type.hpp"
#include "Aurora.Base/Trait.hpp"

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// [ CODE ]
Expand Down Expand Up @@ -78,6 +78,12 @@ inline namespace Core
return IsFull() ? nullptr : AddressOf(mPool[mSize++]);
}

// -=(Undocumented)=-
void Free()
{
--mSize;
}

// -=(Undocumented)=-
Ref<Type> operator[](UInt Handle)
{
Expand All @@ -93,13 +99,13 @@ inline namespace Core
private:

// -=(Undocumented)=-
void Destroy()
{
for (Ref<Type> Object : GetData())
{
Object.~Type();
}
}
void Destroy()
{
for (Ref<Type> Object : GetData())
{
Object.~Type();
}
}

private:

Expand Down
Loading

0 comments on commit 27790e6

Please sign in to comment.