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

+2
View File
@@ -346,3 +346,5 @@ ASALocalRun/
# BeatPulse healthcheck temp database
healthchecksdb
.DS_Store
**/generated/**
-3
View File
@@ -140,9 +140,6 @@ if(WIN32)
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>)
endif()
add_custom_command(TARGET Engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>)
install(
TARGETS
AssetViewer
+132
View File
@@ -64,6 +64,130 @@ class ListSyntheticProvider:
def has_children(self):
return True
def Tree_SummaryProvider(valobj, internal_dict):
size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
return f"Tree(size={size})"
class TreeSyntheticProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
self.update()
def num_children(self):
return self.size
def get_child_index(self, name):
try:
return int(name.lstrip('[').rstrip(']'))
except:
return -1
def get_child_at_index(self, index):
if index < 0 or index >= self.size:
return None
# Collect all nodes via in-order traversal, then return the one at `index`
nodes = []
self._collect(self.root, nodes)
if index >= len(nodes):
return None
return nodes[index].GetChildMemberWithName('data')
def _collect(self, node, out):
if not node.IsValid():
return
self._collect(node.GetChildMemberWithName('leftChild'), out)
out.append(node)
self._collect(node.GetChildMemberWithName('rightChild'), out)
def update(self):
self.root = self.valobj.GetChildMemberWithName('root')
self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
def has_children(self):
return True
def Set_SummaryProvider(valobj, internal_dict):
size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
return f"Set(size={size})"
class SetSyntheticProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
self.update()
def num_children(self):
return self.size
def get_child_index(self, name):
try:
return int(name.lstrip('[').rstrip(']'))
except:
return -1
def get_child_at_index(self, index):
if index < 0 or index >= self.size:
return None
nodes = []
self._collect(self.root, nodes)
if index >= len(nodes):
return None
return nodes[index].GetChildMemberWithName('data')
def _collect(self, node, out):
if not node.IsValid():
return
self._collect(node.GetChildMemberWithName('leftChild'), out)
out.append(node)
self._collect(node.GetChildMemberWithName('rightChild'), out)
def update(self):
self.root = self.valobj.GetChildMemberWithName('root')
self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
def has_children(self):
return True
def Map_SummaryProvider(valobj, internal_dict):
size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
return f"Map(size={size})"
class MapSyntheticProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
self.update()
def num_children(self):
return self.size
def get_child_index(self, name):
try:
return int(name.lstrip('[').rstrip(']'))
except:
return -1
def get_child_at_index(self, index):
if index < 0 or index >= self.size:
return None
nodes = []
self._collect(self.root, nodes)
if index >= len(nodes):
return None
return nodes[index].GetChildMemberWithName('data')
def _collect(self, node, out):
if not node.IsValid():
return
self._collect(node.GetChildMemberWithName('leftChild'), out)
out.append(node)
self._collect(node.GetChildMemberWithName('rightChild'), out)
def update(self):
self.root = self.valobj.GetChildMemberWithName('root')
self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0)
def has_children(self):
return True
def Vector_SummaryProvider(valobj, internal_dict):
# Get the template parameters to determine vector length
type_name = valobj.GetTypeName()
@@ -93,6 +217,14 @@ def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('type summary add -F Seele_lldb.List_SummaryProvider -x "^Seele::List<.*>$"')
debugger.HandleCommand('type synthetic add -l Seele_lldb.ListSyntheticProvider -x "^Seele::List<.*>$"')
# Register Set formatter
debugger.HandleCommand('type summary add -F Seele_lldb.Set_SummaryProvider -x "^Seele::Set<.*>$"')
debugger.HandleCommand('type synthetic add -l Seele_lldb.SetSyntheticProvider -x "^Seele::Set<.*>$"')
# Register Map formatter
debugger.HandleCommand('type summary add -F Seele_lldb.Map_SummaryProvider -x "^Seele::Map<.*>$"')
debugger.HandleCommand('type synthetic add -l Seele_lldb.MapSyntheticProvider -x "^Seele::Map<.*>$"')
# Register Vector formatter
debugger.HandleCommand('type summary add -F Seele_lldb.Vector_SummaryProvider -x "^glm::(detail::)?t?vec[234]?<.*>$"')
+1
View File
@@ -0,0 +1 @@
fonts/
-65
View File
@@ -1,65 +0,0 @@
import Common;
struct VertexInput
{
uint vertexId : SV_VertexID;
uint instanceId : SV_InstanceID;
};
struct VertexOutput
{
float4 position : SV_Position;
float2 texCoords : TEXCOORD;
uint glyphIndex : GLYPHINDEX;
};
struct GlyphInstanceData
{
float x;
float y;
float z;
float width;
float height;
uint glyphIndex;
};
struct TextData
{
StructuredBuffer<GlyphInstanceData> glyphs;
SamplerState glyphSampler;
Texture2D<float> glyphTextures[];
};
ParameterBlock<TextData> pText;
[shader("vertex")]
VertexOutput vertexMain(VertexInput input)
{
float xpos = pText.glyphs[input.instanceId].x;
float ypos = pText.glyphs[input.instanceId].y;
float w = pText.glyphs[input.instanceId].width;
float h = pText.glyphs[input.instanceId].height;
const float4 coordinates[4] = {
float4(xpos, ypos, 0, 0),
float4(xpos, ypos + h, 0, 1),
float4(xpos + w, ypos, 1, 0),
float4(xpos + w, ypos + h, 1, 1),
};
float4 vertex = coordinates[input.vertexId];
VertexOutput output;
output.texCoords = vertex.zw;
output.position = mul(pViewParams.projectionMatrix, float4(vertex.xy, pText.glyphs[input.instanceId].z-1, 1));
output.glyphIndex = pText.glyphs[input.instanceId].glyphIndex;
return output;
}
[shader("fragment")]
float4 fragmentMain(
float4 position : SV_Position,
float2 texCoords : TEXCOORD,
uint glyphIndex : GLYPHINDEX
) : SV_Target
{
return float4(0,0,0,pText.glyphTextures[glyphIndex].Sample(pText.glyphSampler, texCoords));
}
+20 -3
View File
@@ -44,7 +44,17 @@ VertexOutput vertexMain(uint vertexId : SV_VertexID, uint instanceId: SV_Instanc
float4(xMax, yMax, 1, 1)
};
VertexOutput output;
output.position = mul(pViewParams.projectionMatrix, float4(coordinates[vertexId].xy, style.z-1, 1));
// The UI is a 2D overlay in *screen* pixel space (top-left origin, y down).
// The 3D scene camera's projectionMatrix is meaningless for these coordinates,
// so build a 2D ortho screen->NDC projection from the viewport size instead:
// ndcX = (x / W) * 2 - 1
// ndcY = 1 - (y / H) * 2 (flip y: screen is top-down, NDC is bottom-up)
// The UI must NOT be transformed by pViewParams.projectionMatrix (the 3D camera).
float2 ndc = float2(
coordinates[vertexId].x * pViewParams.invScreenDimensions.x * 2.0 - 1.0,
1.0 - coordinates[vertexId].y * pViewParams.invScreenDimensions.y * 2.0
);
output.position = float4(ndc, style.z, 1.0);
output.texCoords = coordinates[vertexId].zw;
output.style = style;
return output;
@@ -59,5 +69,12 @@ float4 fragmentMain(
if(style.textureIndex == -1) {
return float4(style.color, style.opacity);
}
return pParams.textures[style.textureIndex].Sample(pParams.sampler, texCoords.xy);
}
// Glyph quads: the texture is R8_UNORM (coverage in the R channel, A baked to 1.0).
// Reading it as a Texture2D gives (R=coverage, G=0, B=0, A=1) — so the alpha we want
// is in .r, NOT .a (using .a would make every pixel opaque -> the "black cutout").
// Output the pure text color + coverage as alpha; the pipeline's SRC_ALPHA blend then
// applies the coverage exactly once (do NOT premultiply here or it'd be squared).
float4 tex = pParams.textures[style.textureIndex].Sample(pParams.sampler, texCoords.xy);
float coverage = tex.r;
return float4(style.color, coverage * style.opacity);
}
+1
View File
@@ -0,0 +1 @@
shaders/
+1
View File
@@ -0,0 +1 @@
textures/
+29 -5
View File
@@ -45,11 +45,15 @@ UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array<Rend
uint32 num_glyphs;
hb_glyph_info_t* glyphs = hb_buffer_get_glyph_infos(buf, &num_glyphs);
hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buf, &num_glyphs);
Vector2 min = Vector2(std::numeric_limits<float>::max());
Vector2 max = Vector2(std::numeric_limits<float>::lowest());
int32 xppem, yppem;
hb_font_get_scale(hb_font, &xppem, &yppem);
Vector2 cursor = Vector2(0);
// Baseline (in pixels, relative to the text block's top-left) = the font's ascender.
// FreeType gives it in 1/64-pixel units after FT_Set_Pixel_Sizes; convert to pixels.
// Screen space is y-down; the baseline sits `ascender` px *below* the block's top edge.
// (FT metrics ascender is positive-up, so the baseline screen y = +ascender in y-down.)
float ascenderPx = (float)ft_face->size->metrics.ascender / 64.0f;
Vector2 cursor = Vector2(0, ascenderPx);
for (uint32 i = 0; i < num_glyphs; ++i) {
hb_codepoint_t glyphid = glyphs[i].codepoint;
float xOffset = (float)positions[i].x_offset * fontSize / xppem;
@@ -58,17 +62,37 @@ UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array<Rend
float yAdvance = (float)positions[i].y_advance * fontSize / yppem;
Vector2 position = cursor + Vector2(xOffset, yOffset);
Vector2 dimensions = fontSizes[fontSize].glyphs[glyphid].size;
// FreeType bitmap_top = distance from the baseline to the TOP of the bitmap
// (positive up). In y-down screen space the bitmap's top edge is therefore at
// (baselineY - bitmap_top). bearing.x (bitmap_left) shifts the bitmap right of the
// pen. This is what was missing: without it every glyph's top sat on the cursor y
// (text top), giving top-aligned instead of baseline-aligned text.
float bearingX = (float)fontSizes[fontSize].glyphs[glyphid].bearing.x;
float bitmapTop = (float)fontSizes[fontSize].glyphs[glyphid].bearing.y;
position.x += bearingX;
position.y += -bitmapTop;
render.add(RenderGlyph{
.texture = fontSizes[fontSize].glyphs[glyphid].texture,
.position = position,
.dimensions = dimensions,
});
cursor += Vector2(xAdvance, yAdvance);
min = Vector2(std::min(min.x, position.x), std::min(min.y, position.y));
max = Vector2(std::max(max.x, position.x + dimensions.x), std::max(min.y, position.y + dimensions.y));
// Track the right-most x extent (for auto width). Height is NOT derived from the
// bitmap extents: it must be the full line height (ascender - descender) or
// auto-sized elements would clip descenders. See below.
max.x = std::max(max.x, position.x + dimensions.x);
}
hb_buffer_destroy(buf);
return UVector2(max - min);
// Width = right-most x extent (glyphs start at x>=0, so max.x is the full width).
// Height = line height from the font metrics: ascender (above baseline) plus the
// descender depth (FT descender is negative-up => its magnitude is below baseline).
// This is the correct auto-size: it fits the whole em, including descenders.
float descenderPx = (float)ft_face->size->metrics.descender / 64.0f; // <= 0 (down is negative-up)
float lineHeightPx = ascenderPx - descenderPx;
if (max.x <= 0.0f) { // empty string
return UVector2(0, 0);
}
return UVector2((uint32)std::ceil(max.x), (uint32)std::ceil(lineHeightPx));
}
void FontAsset::loadGlyphs(uint32 fontSize) {
+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";