Fixed some text shaders and changed some image parameters

- SHApplication has a font compiler exe call to test compiling a sample font
- SHVkImage now takes in a vector instead of a span for mip offsets (fuck it, copy the mip offset. The RAM can cry about it).
- Removed font data descriptor set layouts from graphics global data
- FONT_DATA set index is changed to 4 instead. This clashes with Render graph resource set index but it won't matter. 
- Added entity ID render graph resource to scene render graph
- SHFont format for images is now R8G8B8A8UNorm
This commit is contained in:
Brandon Mak 2022-11-16 16:57:08 +08:00
parent 292fdf4ee2
commit f991e7b227
21 changed files with 105 additions and 61 deletions

Binary file not shown.

View File

@ -23,16 +23,12 @@ layout(location = 0) in struct
layout(location = 3) flat in struct layout(location = 3) flat in struct
{ {
uint eid; uint eid;
vec3 textColor;
} In2; } In2;
// push constants
layout(std140, push_constant) uniform TestPushConstant
{
vec3 textColor;
} testPushConstant;
layout(set = 6, binding = 0) uniform sampler2D fontBitmap; layout(set = 4, binding = 0) uniform sampler2D fontBitmap;
layout(location = 0) out vec4 color; layout(location = 0) out vec4 color;
layout(location = 1) out uint outEntityID; layout(location = 1) out uint outEntityID;
@ -56,7 +52,7 @@ void main()
fragColor = vec4(0.0f, 1.0f, 1.0f, 1.0f); fragColor = vec4(0.0f, 1.0f, 1.0f, 1.0f);
} }
fragColor = mix(vec4(0.0f), vec4(testPushConstant.textColor, 1.0f), min (opacity, 1.0f)); fragColor = mix(vec4(0.0f), vec4(In2.textColor, 1.0f), min (opacity, 1.0f));
color = fragColor; color = fragColor;

Binary file not shown.

View File

@ -21,6 +21,7 @@ layout(location = 0) out struct
layout(location = 3) out struct layout(location = 3) out struct
{ {
uint eid; uint eid;
vec3 textColor;
} Out2; } Out2;
// Camera data // Camera data
@ -37,11 +38,12 @@ layout(std140, push_constant) uniform TestPushConstant
{ {
mat4 worldTransform; mat4 worldTransform;
uint eid; uint eid;
vec3 textColor;
} testPushConstant; } testPushConstant;
// Descriptor sets // Descriptor sets
layout(std430, set = 6, binding = 1) buffer GlyphTransforms layout(std430, set = 4, binding = 1) buffer GlyphTransforms
{ {
mat4 matrices[]; mat4 matrices[];
} glyphTransforms; } glyphTransforms;
@ -92,6 +94,8 @@ void main()
// Transform the vertices to font space // Transform the vertices to font space
vertexPos = toFontSpace * vertexPos; vertexPos = toFontSpace * vertexPos;
Out2.textColor = testPushConstant.textColor;
// transform the vertex position to font space // transform the vertex position to font space
gl_Position = PVMatrix * localModel * vec4(vertexPos, 1.0f); gl_Position = PVMatrix * localModel * vec4(vertexPos, 1.0f);
} }

Binary file not shown.

View File

@ -78,6 +78,7 @@ namespace Sandbox
SHSystemManager::CreateSystem<SHAudioSystem>(); SHSystemManager::CreateSystem<SHAudioSystem>();
SHSystemManager::CreateSystem<SHCameraSystem>(); SHSystemManager::CreateSystem<SHCameraSystem>();
std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf");
SHSystemManager::CreateSystem<SHGraphicsSystem>(); SHSystemManager::CreateSystem<SHGraphicsSystem>();
SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>()); SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
@ -148,8 +149,6 @@ namespace Sandbox
SHFrameRateController::UpdateFRC(); SHFrameRateController::UpdateFRC();
std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf");
// Link up SHDebugDraw // Link up SHDebugDraw
SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>()); SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>());
} }

View File

@ -459,7 +459,7 @@ namespace SHADE
return SHVkInstance::GetResourceManager().Create<SHVkImage>(GetHandle(), &vmaAllocator, w, h, levels, format, usage, create); return SHVkInstance::GetResourceManager().Create<SHVkImage>(GetHandle(), &vmaAllocator, w, h, levels, format, usage, create);
} }
Handle<SHVkImage> SHVkLogicalDevice::CreateImage(SHImageCreateParams const& imageDetails, unsigned char* data, uint32_t dataSize, std::span<uint32_t> inMipOffsets, VmaMemoryUsage memUsage, VmaAllocationCreateFlags allocFlags) noexcept Handle<SHVkImage> SHVkLogicalDevice::CreateImage(SHImageCreateParams const& imageDetails, unsigned char* data, uint32_t dataSize, std::vector<uint32_t> const& inMipOffsets, VmaMemoryUsage memUsage, VmaAllocationCreateFlags allocFlags) noexcept
{ {
return SHVkInstance::GetResourceManager().Create<SHVkImage>(GetHandle(), &vmaAllocator, imageDetails, data, dataSize, inMipOffsets, memUsage, allocFlags); return SHVkInstance::GetResourceManager().Create<SHVkImage>(GetHandle(), &vmaAllocator, imageDetails, data, dataSize, inMipOffsets, memUsage, allocFlags);
} }

View File

@ -162,7 +162,7 @@ namespace SHADE
SHImageCreateParams const& imageDetails, SHImageCreateParams const& imageDetails,
unsigned char* data, unsigned char* data,
uint32_t dataSize, uint32_t dataSize,
std::span<uint32_t> inMipOffsets, std::vector<uint32_t> const& inMipOffsets,
VmaMemoryUsage memUsage, VmaMemoryUsage memUsage,
VmaAllocationCreateFlags allocFlags VmaAllocationCreateFlags allocFlags
) noexcept; ) noexcept;

View File

@ -123,7 +123,7 @@ namespace SHADE
SHImageCreateParams const& imageDetails, SHImageCreateParams const& imageDetails,
const unsigned char* data, const unsigned char* data,
uint32_t dataSize, uint32_t dataSize,
std::span<uint32_t> inMipOffsets, std::vector<uint32_t> const& inMipOffsets,
VmaMemoryUsage memUsage, VmaMemoryUsage memUsage,
VmaAllocationCreateFlags allocFlags VmaAllocationCreateFlags allocFlags
) noexcept ) noexcept

View File

@ -102,7 +102,7 @@ namespace SHADE
vk::Buffer stagingBuffer; vk::Buffer stagingBuffer;
//! Mipmap offsets for initializing the vk::BufferImageCopy during transfer to GPU resource //! Mipmap offsets for initializing the vk::BufferImageCopy during transfer to GPU resource
std::span<uint32_t> mipOffsets; std::vector<uint32_t> mipOffsets;
//! Handle to the device that creates these images //! Handle to the device that creates these images
Handle<SHVkLogicalDevice> device; Handle<SHVkLogicalDevice> device;
@ -125,7 +125,7 @@ namespace SHADE
SHImageCreateParams const& imageDetails, SHImageCreateParams const& imageDetails,
const unsigned char* data, const unsigned char* data,
uint32_t dataSize, uint32_t dataSize,
std::span<uint32_t> inMipOffsets, std::vector<uint32_t> const& inMipOffsets,
VmaMemoryUsage memUsage, VmaMemoryUsage memUsage,
VmaAllocationCreateFlags allocFlags VmaAllocationCreateFlags allocFlags
) noexcept; ) noexcept;

View File

@ -97,23 +97,6 @@ namespace SHADE
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, { materialDataBinding }); Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, { materialDataBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals");
SHVkDescriptorSetLayout::Binding fontBitmapBinding
{
.Type = vk::DescriptorType::eCombinedImageSampler,
.Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
.DescriptorCount = 1,
};
SHVkDescriptorSetLayout::Binding fontMatrixBinding
{
.Type = vk::DescriptorType::eStorageBuffer,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
.DescriptorCount = 1,
};
Handle<SHVkDescriptorSetLayout> fontDataLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, { fontBitmapBinding, fontMatrixBinding });
globalDescSetLayouts.push_back(staticGlobalLayout); globalDescSetLayouts.push_back(staticGlobalLayout);

View File

@ -66,7 +66,9 @@ namespace SHADE
/***************************************************************************/ /***************************************************************************/
/*! /*!
\brief \brief
DescriptorSet Index for render graph resources. DescriptorSet Index for render graph resources. Unlike the sets from
1 to 3 and 6, this set index does not have hard coded bindings and is
NOT part of the layouts included in the global data.
*/ */
/***************************************************************************/ /***************************************************************************/
static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; static constexpr uint32_t RENDERGRAPH_RESOURCE = 4;
@ -75,7 +77,7 @@ namespace SHADE
\brief \brief
DescriptorSet Index for render graph node compute resources. For data DescriptorSet Index for render graph node compute resources. For data
that we wish to pass to compute shaders in the render graph, this is that we wish to pass to compute shaders in the render graph, this is
the set to use. Unlike the sets from 1 to 3, this set index does not have the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have
hard coded bindings and is NOT part of the layouts included in the global hard coded bindings and is NOT part of the layouts included in the global
data. data.
*/ */
@ -89,7 +91,7 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
static constexpr uint32_t FONT_DATA = 6; static constexpr uint32_t FONT_DATA = 4;
}; };
struct DescriptorSetBindings struct DescriptorSetBindings

View File

@ -282,10 +282,12 @@ namespace SHADE
screenRenderGraph = resourceManager.Create<SHRenderGraph>(); screenRenderGraph = resourceManager.Create<SHRenderGraph>();
screenRenderGraph->Init("Scene Render Graph", device, swapchain, &resourceManager); screenRenderGraph->Init("Scene Render Graph", device, swapchain, &resourceManager);
screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Scene"); screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Scene");
screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Entity ID");
auto screenSpaceNode = screenRenderGraph->AddNode("Screen Space Pass", { "Scene" }, {}); auto screenSpaceNode = screenRenderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID"}, {});
auto uiSubpass = screenSpaceNode->AddSubpass("UI"); auto uiSubpass = screenSpaceNode->AddSubpass("UI");
uiSubpass->AddColorOutput("Scene"); uiSubpass->AddColorOutput("Scene");
uiSubpass->AddColorOutput("Entity ID");
{ {
// Dummy Node to transition scene render graph resource // Dummy Node to transition scene render graph resource
@ -360,8 +362,8 @@ namespace SHADE
textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>(); textRenderingSubSystem = resourceManager.Create<SHTextRenderingSubSystem>();
// initialize the text renderer // initialize the text renderer
//auto uiNode = screenRenderGraph->GetNode("Screen Space Pass"); auto uiNode = screenRenderGraph->GetNode("Screen Space Pass");
//textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS);
SHFreetypeInstance::Init(); SHFreetypeInstance::Init();
} }
@ -855,7 +857,7 @@ namespace SHADE
void SHGraphicsSystem::BuildFonts(void) noexcept void SHGraphicsSystem::BuildFonts(void) noexcept
{ {
fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, resourceManager); fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, textRenderingSubSystem->GetFontDataDescSetLayout(), resourceManager);
} }
#pragma endregion ADD_REMOVE #pragma endregion ADD_REMOVE

View File

@ -76,7 +76,7 @@ namespace SHADE
}; };
uint32_t mipOffset = 0; uint32_t mipOffset = 0;
rotationVectorsImage = logicalDevice->CreateImage(imageDetails, reinterpret_cast<unsigned char*>( rotationVectors.data()), static_cast<uint32_t>(sizeof(rotationVectors)), {&mipOffset, 1}, VMA_MEMORY_USAGE_AUTO, {}); rotationVectorsImage = logicalDevice->CreateImage(imageDetails, reinterpret_cast<unsigned char*>(rotationVectors.data()), static_cast<uint32_t>(sizeof(rotationVectors)), { mipOffset }, VMA_MEMORY_USAGE_AUTO, {});
vk::ImageMemoryBarrier transferBarrier{}; vk::ImageMemoryBarrier transferBarrier{};
rotationVectorsImage->PrepareImageTransitionInfo(vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal, transferBarrier); rotationVectorsImage->PrepareImageTransitionInfo(vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal, transferBarrier);

View File

@ -4,6 +4,7 @@
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
#include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/Images/SHVkSampler.h"
namespace SHADE namespace SHADE
{ {
@ -42,9 +43,9 @@ namespace SHADE
.depth = 1, .depth = 1,
.levels = 1, .levels = 1,
.arrayLayers = 1, .arrayLayers = 1,
//.imageFormat = vk::Format::eR8G8B8Snorm, .imageFormat = vk::Format::eR8G8B8A8Snorm,
//.imageFormat = vk::Format::eR32Sfloat, //.imageFormat = vk::Format::eR32Sfloat,
.imageFormat = vk::Format::eR32G32B32Sfloat, //.imageFormat = vk::Format::eR32G32B32Sfloat,
.usageFlags = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst, .usageFlags = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
.createFlags = {} .createFlags = {}
}; };
@ -53,7 +54,7 @@ namespace SHADE
uint32_t mipOffset = 0; uint32_t mipOffset = 0;
// Create the image // Create the image
bitmapDataImage = logicalDevice->CreateImage(imageParams, fontAsset.bitmapData.data(), bytesRequired, { &mipOffset, 1 }, VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO, {}); bitmapDataImage = logicalDevice->CreateImage(imageParams, fontAsset.bitmapData.data(), bytesRequired, { mipOffset }, VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO, {});
// Amount of data required to hold matrices for all glyphs // Amount of data required to hold matrices for all glyphs
uint32_t glyphDataSize = fontAsset.glyphTransformations.size() * sizeof (SHMatrix); uint32_t glyphDataSize = fontAsset.glyphTransformations.size() * sizeof (SHMatrix);
@ -65,9 +66,7 @@ namespace SHADE
// allocate GPU buffer for matrices // allocate GPU buffer for matrices
matrixDataBuffer = logicalDevice->CreateBuffer(glyphDataSize, fontAsset.glyphTransformations.data(), glyphDataSize, vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, {}); matrixDataBuffer = logicalDevice->CreateBuffer(glyphDataSize, fontAsset.glyphTransformations.data(), glyphDataSize, vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, {});
//// Prepare pre and post transfer barrier sampler = logicalDevice->CreateSampler(SHVkSamplerParams{});
//bitmapDataImage->PrepareImageTransitionInfo(vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal, preTransferBarrier);
//bitmapDataImage->PrepareImageTransitionInfo(vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal, postTransferBarrier);
} }
@ -97,7 +96,7 @@ namespace SHADE
matrixDataBuffer->TransferToDeviceResource(commandBuffer); matrixDataBuffer->TransferToDeviceResource(commandBuffer);
} }
void SHFont::DoPostTransfer(Handle<SHVkDescriptorPool> descPool) noexcept void SHFont::DoPostTransfer(Handle<SHVkDescriptorPool> descPool, Handle<SHVkDescriptorSetLayout> layout) noexcept
{ {
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* CREATE IMAGE VIEW */ /* CREATE IMAGE VIEW */
@ -106,7 +105,7 @@ namespace SHADE
SHImageViewDetails viewDetails SHImageViewDetails viewDetails
{ {
.viewType = vk::ImageViewType::e2D, .viewType = vk::ImageViewType::e2D,
.format = vk::Format::eR32G32B32Sfloat, .format = bitmapDataImage->GetImageFormat(),
.imageAspectFlags = vk::ImageAspectFlagBits::eColor, .imageAspectFlags = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0, .baseMipLevel = 0,
.mipLevelCount = 1, .mipLevelCount = 1,
@ -118,14 +117,11 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* DESCRIPTORS */ /* DESCRIPTORS */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
// Font data desc set layout
auto fontDataLayout = SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA];
// allocate desc set for the bitmap and matrix data // allocate desc set for the bitmap and matrix data
descSet = descPool->Allocate({ fontDataLayout }, { 1, 1 }); descSet = descPool->Allocate({ layout }, { 1 });
//auto viewLayoutSampler = std::make_tuple() auto viewLayoutSampler = std::make_tuple(bitmapDataImageView, sampler, vk::ImageLayout::eShaderReadOnlyOptimal);
descSet->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, {}); descSet->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, {&viewLayoutSampler, 1});
descSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, descSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA,
SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, { &matrixDataBuffer, 1 }, 0, fontAsset.glyphTransformations.size() * sizeof(SHMatrix)); SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, { &matrixDataBuffer, 1 }, 0, fontAsset.glyphTransformations.size() * sizeof(SHMatrix));

View File

@ -9,12 +9,14 @@ namespace SHADE
class SHVkLogicalDevice; class SHVkLogicalDevice;
class SHVkDescriptorPool; class SHVkDescriptorPool;
class SHVkDescriptorSetGroup; class SHVkDescriptorSetGroup;
class SHVkDescriptorSetLayout;
class SHVkCommandBuffer; class SHVkCommandBuffer;
class SHVkCommandPool; class SHVkCommandPool;
class SHVkImage; class SHVkImage;
class SHVkImageView; class SHVkImageView;
class SHVkBuffer; class SHVkBuffer;
class SHVkQueue; class SHVkQueue;
class SHVkSampler;
class SHFont class SHFont
{ {
@ -37,6 +39,8 @@ namespace SHADE
//! Descriptor set required to store the bitmap AND matrix data for the UV and quad transformation //! Descriptor set required to store the bitmap AND matrix data for the UV and quad transformation
Handle<SHVkDescriptorSetGroup> descSet; Handle<SHVkDescriptorSetGroup> descSet;
Handle<SHVkSampler> sampler;
//! Used for getting the correct indices into the matrix data buffer //! Used for getting the correct indices into the matrix data buffer
std::unordered_map<msdfgen::unicode_t, uint32_t> unicodeIndexing; std::unordered_map<msdfgen::unicode_t, uint32_t> unicodeIndexing;
@ -52,7 +56,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
SHFont (Handle<SHVkLogicalDevice> inLogicalDeviceHdl, SHFontAsset const& asset) noexcept; SHFont (Handle<SHVkLogicalDevice> inLogicalDeviceHdl, SHFontAsset const& asset) noexcept;
void TransferToGPU (Handle<SHVkCommandBuffer> commandBuffer) noexcept; void TransferToGPU (Handle<SHVkCommandBuffer> commandBuffer) noexcept;
void DoPostTransfer (Handle<SHVkDescriptorPool> descPool) noexcept; void DoPostTransfer (Handle<SHVkDescriptorPool> descPool, Handle<SHVkDescriptorSetLayout> layout) noexcept;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/

View File

@ -50,11 +50,11 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
void SHFontLibrary::BuildFonts(Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkQueue> queue, Handle<SHVkCommandPool> cmdPool, Handle<SHVkDescriptorPool> descPool, SHResourceHub& resourceHub) noexcept void SHFontLibrary::BuildFonts(Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkQueue> queue, Handle<SHVkCommandPool> cmdPool, Handle<SHVkDescriptorPool> descPool, Handle<SHVkDescriptorSetLayout> layout, SHResourceHub& resourceHub) noexcept
{ {
// create fence to wait on after transfer // create fence to wait on after transfer
Handle<SHVkFence> finishCopyFence = resourceHub.Create<SHVkFence>(logicalDevice); Handle<SHVkFence> finishCopyFence = resourceHub.Create<SHVkFence>(logicalDevice);
finishCopyFence->Reset();
// allocate new command buffer // allocate new command buffer
Handle<SHVkCommandBuffer> transferCommandBuffer = cmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); Handle<SHVkCommandBuffer> transferCommandBuffer = cmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
@ -84,10 +84,10 @@ namespace SHADE
// Prepare image views and desc sets // Prepare image views and desc sets
for (auto& font : unpreparedFonts) for (auto& font : unpreparedFonts)
font->DoPostTransfer(descPool); font->DoPostTransfer(descPool, layout);
// Free the command buffer and fence // Free the command buffer and fence
resourceHub.Free(transferCommandBuffer); transferCommandBuffer.Free();
resourceHub.Free(finishCopyFence); resourceHub.Free(finishCopyFence);
// Once unprepared fonts are now ready for use, push them into container // Once unprepared fonts are now ready for use, push them into container

View File

@ -11,6 +11,7 @@ namespace SHADE
class SHVkCommandPool; class SHVkCommandPool;
class SHVkCommandBuffer; class SHVkCommandBuffer;
class SHVkQueue; class SHVkQueue;
class SHVkDescriptorSetLayout;
class SHFontLibrary class SHFontLibrary
{ {
@ -29,6 +30,6 @@ namespace SHADE
public: public:
Handle<SHFont> AddFont (Handle<SHVkLogicalDevice> logicalDevice, SHResourceHub& resourceHub, SHFontAsset const& asset) noexcept; Handle<SHFont> AddFont (Handle<SHVkLogicalDevice> logicalDevice, SHResourceHub& resourceHub, SHFontAsset const& asset) noexcept;
void BuildFonts (Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkQueue> queue, Handle<SHVkCommandPool> cmdPool, Handle<SHVkDescriptorPool> descPool, SHResourceHub& resourceHub) noexcept; void BuildFonts (Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkQueue> queue, Handle<SHVkCommandPool> cmdPool, Handle<SHVkDescriptorPool> descPool, Handle<SHVkDescriptorSetLayout> layout, SHResourceHub& resourceHub) noexcept;
}; };
} }

View File

@ -8,6 +8,8 @@
#include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
#include "Graphics/Pipeline/SHVkPipeline.h" #include "Graphics/Pipeline/SHVkPipeline.h"
#include "Graphics/SHVkUtil.h"
#include "Graphics/RenderGraph/SHSubpass.h"
namespace SHADE namespace SHADE
{ {
@ -114,8 +116,53 @@ namespace SHADE
// Set vertex state for new pipeline // Set vertex state for new pipeline
pipeline->GetPipelineState().SetVertexInputState(vertexInputState); pipeline->GetPipelineState().SetVertexInputState(vertexInputState);
SHColorBlendState colorBlendState{};
colorBlendState.logic_op_enable = VK_FALSE;
colorBlendState.logic_op = vk::LogicOp::eCopy;
auto const& subpassColorReferences = subpass->GetColorAttachmentReferences();
colorBlendState.attachments.reserve(subpassColorReferences.size());
for (auto& att : subpassColorReferences)
{
colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState
{
.blendEnable = SHVkUtil::IsBlendCompatible(subpass->GetFormatFromAttachmentReference(att.attachment)) ? true : false,
.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha,
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
.colorBlendOp = vk::BlendOp::eAdd,
.srcAlphaBlendFactor = vk::BlendFactor::eOne,
.dstAlphaBlendFactor = vk::BlendFactor::eZero,
.alphaBlendOp = vk::BlendOp::eAdd,
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
}
);
}
pipeline->GetPipelineState().SetColorBlenState(colorBlendState);
// Construct pipeline // Construct pipeline
pipeline->ConstructPipeline(); pipeline->ConstructPipeline();
SHVkDescriptorSetLayout::Binding fontBitmapBinding
{
.Type = vk::DescriptorType::eCombinedImageSampler,
.Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
.DescriptorCount = 1,
};
SHVkDescriptorSetLayout::Binding fontMatrixBinding
{
.Type = vk::DescriptorType::eStorageBuffer,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
.DescriptorCount = 1,
};
fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, { fontBitmapBinding, fontMatrixBinding });
} }
void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept
@ -164,4 +211,9 @@ namespace SHADE
} }
Handle<SHVkDescriptorSetLayout> SHTextRenderingSubSystem::GetFontDataDescSetLayout(void) const noexcept
{
return fontDataDescSetLayout;
}
} }

View File

@ -32,6 +32,9 @@ namespace SHADE
//! Pipeline layout for the pipeline //! Pipeline layout for the pipeline
Handle<SHVkPipelineLayout> pipelineLayout; Handle<SHVkPipelineLayout> pipelineLayout;
//! Descriptor set for font data access in shaders
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout;
private: private:
void RecomputePositions(SHTextRendererComponent& textComp) noexcept; void RecomputePositions(SHTextRendererComponent& textComp) noexcept;
@ -41,6 +44,8 @@ namespace SHADE
void Render (Handle<SHVkCommandBuffer> cmdBuffer) noexcept; void Render (Handle<SHVkCommandBuffer> cmdBuffer) noexcept;
void Exit(void) noexcept; void Exit(void) noexcept;
Handle<SHVkDescriptorSetLayout> GetFontDataDescSetLayout (void) const noexcept;
}; };
} }

View File

@ -319,7 +319,7 @@ namespace SHADE
else if constexpr (std::is_same_v<ResourceType, SHFont>) else if constexpr (std::is_same_v<ResourceType, SHFont>)
{ {
loadedAssetData.emplace_back(assetId); loadedAssetData.emplace_back(assetId);
textureChanged = true; fontChanged = true;
return gfxSystem->AddFont(assetData); return gfxSystem->AddFont(assetData);
} }