Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,18 @@ namespace NovelRT::Ecs::Graphics
colourDataStruct.depth = 0;
colourDataStruct.stencil = 0;

cmdList->CmdTransitionSwapchainImageTo(image, NovelRT::Graphics::ImageLayout::Undefined,
NovelRT::Graphics::ImageLayout::DstTransfer);
using Access = NovelRT::Graphics::GraphicsMemoryAccessMode;
using Stage = NovelRT::Graphics::GraphicsPipelineVisibility;
using Layout = NovelRT::Graphics::ImageLayout;

cmdList->CmdTransitionTextureTo(image, Layout::Undefined, Layout::DstTransfer, Access::None,
Access::TransferWrite, Stage::Transfer, Stage::Transfer);

cmdList->CmdClearColourSwapchainImage(image, colourDataStruct);

cmdList->CmdTransitionSwapchainImageTo(image, NovelRT::Graphics::ImageLayout::DstTransfer,
NovelRT::Graphics::ImageLayout::Present);
cmdList->CmdTransitionTextureTo(image, Layout::DstTransfer, Layout::Present, Access::TransferWrite,
Access::ColorAttachmentRead | Access::ColorAttachmentWrite, Stage::Transfer,
Stage::ColorAttachmentOutput);
for (auto& root : roots)
{
EnumerateChildren(root, renderPasses, ordered);
Expand Down
46 changes: 30 additions & 16 deletions Ecs/Graphics/include/NovelRT/Ecs/Graphics/SpriteRendererSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

#include <NovelRT/Utilities/Memory.hpp>

#include <cmath>
#include <optional>
#include <span>
#include <unordered_map>
Expand Down Expand Up @@ -150,10 +149,6 @@ namespace NovelRT::Ecs::Graphics
void HandleNewSpriteTextures(Catalogue catalogue)
{
auto lastCompletedUpload = _uploadSemaphore->GetValue();
if (lastCompletedUpload > 0)
{
lastCompletedUpload -= 1;
}

_pendingStagingBuffers.erase(std::remove_if(_pendingStagingBuffers.begin(), _pendingStagingBuffers.end(),
[lastCompletedUpload](const auto& pending)
Expand Down Expand Up @@ -213,9 +208,18 @@ namespace NovelRT::Ecs::Graphics
.size = totalSize};

auto textureStagingBuffer = _memoryAllocator->CreateBuffer(bufferCreateInfo);
auto gfxContext = _graphicsDevice->CreateGraphicsContext();

// this was getting unreadable. - Matt J.
using Access = NovelRT::Graphics::GraphicsMemoryAccessMode;
using Stage = NovelRT::Graphics::GraphicsPipelineVisibility;
using Layout = NovelRT::Graphics::ImageLayout;

auto gfxContext = _graphicsDevice->CreateTransferContext();
auto uploadCmdList = gfxContext->CreateCmdList();

std::vector<BufferRegion> stagingBufferRegions{};
stagingBufferRegions.reserve(newTextures.size());

uploadCmdList->Begin();

for (auto [texture, texture2D] : newTextures)
Expand All @@ -230,12 +234,15 @@ namespace NovelRT::Ecs::Graphics

textureStagingBuffer->UnmapAndWrite(textureStagingBufferRegion);

uploadCmdList->CmdBeginTexturePipelineBarrierLegacyVersion(texture2D);
uploadCmdList->CmdTransitionTextureTo(texture2D, Layout::Undefined, Layout::DstTransfer,
Access::None, Access::TransferWrite, Stage::TopOfPipe,
Stage::Transfer);
uploadCmdList->CmdCopy(texture2D, textureStagingBufferRegion);
uploadCmdList->CmdEndTexturePipelineBarrierLegacyVersion(texture2D);
uploadCmdList->CmdTransitionTextureTo(texture2D, Layout::DstTransfer,
Layout::ShaderReadOnlyOptimal, Access::TransferWrite,
Access::None, Stage::Transfer, Stage::BottomOfPipe);

_pendingStagingBuffers.push_back({_submittedUploads, textureStagingBuffer,
textureStagingBufferRegion, gfxContext, uploadCmdList});
stagingBufferRegions.push_back(textureStagingBufferRegion);
_textureCache.emplace(
texture.databaseHandle,
TextureCacheItem{texture2DRegion,
Expand All @@ -244,20 +251,27 @@ namespace NovelRT::Ecs::Graphics

_pendingLoads.erase(texture.databaseHandle);
}
std::vector<std::pair<std::shared_ptr<NovelRT::Graphics::GraphicsSemaphore<TGraphicsBackend>>,
uint64_t>>
signalSemaphores{std::make_pair(_uploadSemaphore, ++_submittedUploads)};

uploadCmdList->End();

std::vector<std::shared_ptr<NovelRT::Graphics::GraphicsCmdList<TGraphicsBackend>>> list{
uploadCmdList};
_pendingStagingBuffers.reserve(_pendingStagingBuffers.size() + stagingBufferRegions.size());
const auto uploadIndex = ++_submittedUploads;
std::vector<std::pair<std::shared_ptr<NovelRT::Graphics::GraphicsSemaphore<TGraphicsBackend>>,
uint64_t>>
signalSemaphores{std::make_pair(_uploadSemaphore, uploadIndex)};
_graphicsDevice->QueueSubmit(list, signalSemaphores);

for (const auto& region : stagingBufferRegions)
{
_pendingStagingBuffers.push_back(
{uploadIndex, textureStagingBuffer, region, gfxContext, uploadCmdList});
}

Components::TrackedSemaphore<TGraphicsBackend> newUploadTracker{
.semaphore = new std::shared_ptr<NovelRT::Graphics::GraphicsSemaphore<TGraphicsBackend>>(
_uploadSemaphore),
.signalValue = _submittedUploads};
.signalValue = uploadIndex};

auto id = completionCatalogue.CreateEntity();

Expand Down Expand Up @@ -554,7 +568,7 @@ namespace NovelRT::Ecs::Graphics
_pipeline =
_graphicsDevice->CreatePipeline(signature, vertShaderProg, pixelShaderProg, _renderPass.RenderPass);

auto gfxContext = _graphicsDevice->CreateGraphicsContext();
auto gfxContext = _graphicsDevice->CreateTransferContext();
auto cmdList = gfxContext->CreateCmdList();
cmdList->Begin();
cmdList->CmdCopy(_vertexBufferRegion, stagingRegion);
Expand Down
2 changes: 1 addition & 1 deletion Ecs/UI/include/NovelRT/Ecs/UI/EcsUIBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace NovelRT::Ecs::UI
{
// By default, we will upload the font data when creating the default UI system.
// This is the user's responsibility if using a non-default UI system.
auto gfxContext = _gfxDevice->CreateGraphicsContext();
auto gfxContext = _gfxDevice->CreateTransferContext();
auto cmdList = gfxContext->CreateCmdList();
_uiProvider->UploadFontData(cmdList);

Expand Down
5 changes: 3 additions & 2 deletions Ecs/UI/include/NovelRT/Ecs/UI/UISystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ namespace NovelRT::Ecs::UI
Graphics::Components::TrackedSemaphore<TGraphicsBackend>>();

// create upload command list
auto uiContext = _gfxDevice->CreateGraphicsContext();
auto uploadCmdList = uiContext->CreateCmdList();
auto uploadContext = _gfxDevice->CreateTransferContext();
auto uploadCmdList = uploadContext->CreateCmdList();

// upload data to gpu
if (_uiProvider->UploadToGPU(uploadCmdList))
Expand Down Expand Up @@ -270,6 +270,7 @@ namespace NovelRT::Ecs::UI
trackedSemaphores.AddComponent(_drawSemaphoreEntity.value(), signalSemaComponent);

// create the draw cmdList
auto uiContext = _gfxDevice->CreateGraphicsContext();
auto drawCmdList =
uiContext->CreateCmdList(std::optional<NovelRT::Graphics::SecondaryCmdListInfo<TGraphicsBackend>>(
{_uiProvider->GetDedicatedRenderPass(), 0}));
Expand Down
21 changes: 15 additions & 6 deletions Graphics/Core/include/NovelRT/Graphics/GraphicsCmdList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ namespace NovelRT::Graphics

void CmdSetViewport(ViewportInfo viewportInfo);

void CmdBeginTexturePipelineBarrierLegacyVersion(const std::shared_ptr<GraphicsTexture<TBackend>>& texture);
void CmdEndTexturePipelineBarrierLegacyVersion(const std::shared_ptr<GraphicsTexture<TBackend>>& texture);

void CmdBindPipeline(const std::shared_ptr<GraphicsPipeline<TBackend>>& pipeline);

void CmdPushConstants(const std::shared_ptr<GraphicsPipelineSignature<TBackend>>& pipelineSignature,
Expand All @@ -135,9 +132,21 @@ namespace NovelRT::Graphics

void CmdExecuteCommands(const std::shared_ptr<GraphicsCmdList<TBackend>>& cmdList);

void CmdTransitionSwapchainImageTo(const std::shared_ptr<GraphicsSwapchainImage<TBackend>>& swapchainImage,
ImageLayout oldLayout,
ImageLayout newLayout);
void CmdTransitionTextureTo(const std::shared_ptr<GraphicsSwapchainImage<TBackend>>& swapchainImage,
ImageLayout oldLayout,
ImageLayout newLayout,
GraphicsMemoryAccessMode sourceAccess,
GraphicsMemoryAccessMode destinationAccess,
GraphicsPipelineVisibility sourceStage,
GraphicsPipelineVisibility destinationStage);

void CmdTransitionTextureTo(const std::shared_ptr<GraphicsTexture<TBackend>>& texture,
ImageLayout oldLayout,
ImageLayout newLayout,
GraphicsMemoryAccessMode sourceAccess,
GraphicsMemoryAccessMode destinationAccess,
GraphicsPipelineVisibility sourceStage,
GraphicsPipelineVisibility destinationStage);

void CmdClearColourSwapchainImage(const std::shared_ptr<GraphicsSwapchainImage<TBackend>>& swapchainImage,
ClearValue clearData);
Expand Down
1 change: 1 addition & 0 deletions Graphics/Core/include/NovelRT/Graphics/GraphicsDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace NovelRT::Graphics
NovelRT::Utilities::Span<uint8_t> byteData);

[[nodiscard]] std::shared_ptr<GraphicsContext<TBackend>> CreateGraphicsContext();
[[nodiscard]] std::shared_ptr<GraphicsContext<TBackend>> CreateTransferContext();

[[nodiscard]] std::shared_ptr<GraphicsSwapchainImage<TBackend>> BeginFrame();
void EndFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace NovelRT::Graphics
{
enum class GraphicsPipelineVisibility : uint32_t
{
// IMPLEMENTATION DETAIL:
// All of these values match the Vulkan implementation,
// or at least, they should. The vulkan module has
// static asserts due to some trickery we're doing to
// take advantage of this. - Matt J.

None = 0,
TopOfPipe = 1 << 0,
DrawIndirect = 1 << 1,
Expand All @@ -27,10 +33,8 @@ namespace NovelRT::Graphics
Transfer = 1 << 12,
BottomOfPipe = 1 << 13,
Host = 1 << 14,
AllGraphics = DrawIndirect | VertexInput | VertexShader | TesselationControlShader |
TesselationEvaluationShader | GeometryShader | FragmentShader | EarlyFragmentTests |
LateFragmentTests | ColorAttachmentOutput,
AllCommands = AllGraphics | TopOfPipe | Transfer | BottomOfPipe | Host,
AllGraphics = 1u << 15,
AllCommands = 1u << 16,
All = AllCommands
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ namespace NovelRT::Graphics
enum class ImageLayout : uint32_t
{
Undefined,
Optimal,
General,
Present,
SrcTransfer,
DstTransfer,
ShaderReadOnlyOptimal,
};

struct GraphicsAttachmentDescription
Expand Down
Loading
Loading