Remote TextPass, merged with UIPass

This commit is contained in:
Dynamitos committed 2026-10-20 22:01:51 +02:00
1 parent 332c47fc9d
commit 17dc1e4d88
11 files changed
+191 -179

No files matched your search

+4 -76
View File
@@ -9,26 +9,7 @@
using namespace Seele;
UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics), system(system) {
glyphInstanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "GlyphInstanceBuffer"});
elementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "RenderStyleElements"});
textDescriptorLayout = graphics->createDescriptorLayout("pText");
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = GLYPHINSTANCE_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = GLYPHSAMPLER_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = TEXTURES_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 1024,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
textPipelineLayout = graphics->createPipelineLayout("TextPipeline");
textPipelineLayout->addDescriptorLayout(viewParamsLayout);
textPipelineLayout->addDescriptorLayout(textDescriptorLayout);
uiDescriptorLayout = graphics->createDescriptorLayout("pParams");
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
@@ -48,7 +29,6 @@ UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphic
uiPipelineLayout = graphics->createPipelineLayout("UIPipeline");
uiPipelineLayout->addDescriptorLayout(viewParamsLayout);
uiPipelineLayout->addDescriptorLayout(uiDescriptorLayout);
// todo:
}
UIPass::~UIPass() {}
@@ -60,7 +40,6 @@ void UIPass::beginFrame(const Component::Camera& cam, const Component::Transform
system->processInput();
system->beginFrame(UVector2(viewport->getWidth(), viewport->getHeight()));
renderElements = system->render();
glyphs.clear();
usedTextures.clear();
elements.clear();
for (auto& render : renderElements) {
@@ -82,20 +61,6 @@ void UIPass::beginFrame(const Component::Camera& cam, const Component::Transform
.textureIndex = textureIndex,
});
}
glyphInstanceBuffer->rotateBuffer(sizeof(GlyphInstanceData) * glyphs.size());
glyphInstanceBuffer->updateContents(0, sizeof(GlyphInstanceData) * glyphs.size(), glyphs.data());
glyphInstanceBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT);
textDescriptorLayout->reset();
textDescriptorSet = textDescriptorLayout->allocateDescriptorSet();
textDescriptorSet->updateBuffer(GLYPHINSTANCE_NAME, 0, glyphInstanceBuffer);
textDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler);
for (uint32 i = 0; i < usedTextures.size(); ++i) {
textDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]->getDefaultView());
}
textDescriptorSet->writeChanges();
elementBuffer->rotateBuffer(sizeof(RenderElementStyle) * elements.size());
elementBuffer->updateContents(0, sizeof(RenderElementStyle) * elements.size(), elements.data());
elementBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
@@ -103,7 +68,7 @@ void UIPass::beginFrame(const Component::Camera& cam, const Component::Transform
uiDescriptorLayout->reset();
uiDescriptorSet = uiDescriptorLayout->allocateDescriptorSet();
uiDescriptorSet->updateBuffer(ELEMENT_NAME, 0, elementBuffer);
uiDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler);
uiDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, uiSampler);
for (uint32 i = 0; i < usedTextures.size(); ++i) {
uiDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]->getDefaultView());
}
@@ -113,7 +78,7 @@ void UIPass::beginFrame(const Component::Camera& cam, const Component::Transform
void UIPass::render() {
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
Gfx::ORenderCommand command = graphics->createRenderCommand("TextPassCommand");
Gfx::ORenderCommand command = graphics->createRenderCommand("UIPassCommand");
command->setViewport(viewport);
command->bindPipeline(uiPipeline);
command->bindDescriptor({viewParamsSet, uiDescriptorSet});
@@ -175,52 +140,15 @@ void UIPass::createRenderPass() {
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
};
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport->getRenderArea(), "TextPass");
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport->getRenderArea(), "UIPass");
graphics->beginShaderCompilation(ShaderCompilationInfo{
.name = "TextVertex",
.modules = {"TextPass"},
.entryPoints = {{"vertexMain", "TextPass"}, {"fragmentMain", "TextPass"}},
.rootSignature = textPipelineLayout,
});
textPipelineLayout->create();
textVertexShader = graphics->createVertexShader({0});
textFragmentShader = graphics->createFragmentShader({1});
glyphSampler = graphics->createSampler({
uiSampler = graphics->createSampler({
.magFilter = Gfx::SE_FILTER_LINEAR,
.minFilter = Gfx::SE_FILTER_LINEAR,
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
});
textPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
.vertexShader = textVertexShader,
.fragmentShader = textFragmentShader,
.renderPass = renderPass,
.pipelineLayout = textPipelineLayout,
.rasterizationState =
{
.cullMode = Gfx::SE_CULL_MODE_NONE,
},
.colorBlend =
{
.attachmentCount = 1,
.blendAttachments = {{
.blendEnable = true,
.srcColorBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA,
.dstColorBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.srcAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.dstAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ZERO,
.alphaBlendOp = Gfx::SE_BLEND_OP_ADD,
.colorWriteMask = Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT |
Gfx::SE_COLOR_COMPONENT_A_BIT,
}},
},
});
graphics->beginShaderCompilation(ShaderCompilationInfo{
.name = "UIVertex",
.modules = {"UIPass"},
+1 -27
View File
@@ -1,7 +1,6 @@
#pragma once
#include "Graphics/Shader.h"
#include "RenderPass.h"
#include "Asset/FontAsset.h"
#include "UI/System.h"
namespace Seele {
@@ -28,20 +27,6 @@ class UIPass : public RenderPass {
void key(KeyCode code, InputAction action, KeyModifierFlags modifier, char text = 0) { system->key(code, action, (KeyModifier)modifier, text); }
private:
struct GlyphData {
Vector2 bearing;
Vector2 size;
uint32 advance;
};
struct GlyphInstanceData {
float x;
float y;
float z;
float width;
float height;
uint32 glyphIndex;
};
struct RenderElementStyle {
float x;
float y;
@@ -59,14 +44,6 @@ class UIPass : public RenderPass {
Gfx::RenderTargetAttachment depthAttachment;
Gfx::OTexture2D depthBuffer;
Gfx::ODescriptorLayout textDescriptorLayout;
Gfx::ODescriptorSet textDescriptorSet;
Gfx::OVertexShader textVertexShader;
Gfx::OFragmentShader textFragmentShader;
Gfx::OPipelineLayout textPipelineLayout;
Gfx::PGraphicsPipeline textPipeline;
Gfx::ODescriptorLayout uiDescriptorLayout;
Gfx::ODescriptorSet uiDescriptorSet;
@@ -79,13 +56,10 @@ class UIPass : public RenderPass {
UI::PSystem system;
Array<UI::UIRender> renderElements;
Array<GlyphInstanceData> glyphs;
Array<RenderElementStyle> elements;
Gfx::OShaderBuffer glyphInstanceBuffer;
constexpr static const char* GLYPHINSTANCE_NAME = "glyphData";
Gfx::OShaderBuffer elementBuffer;
constexpr static const char* ELEMENT_NAME = "elements";
Gfx::OSampler glyphSampler;
Gfx::OSampler uiSampler;
constexpr static const char* GLYPHSAMPLER_NAME = "glyphSampler";
Array<Gfx::PTexture2D> usedTextures;
constexpr static const char* TEXTURES_NAME = "textures";