Skip to content

Commit c0cc9e2

Browse files
committed
image and font renderer refactors
1 parent b58e72d commit c0cc9e2

7 files changed

Lines changed: 32 additions & 40 deletions

File tree

WickedEngine/shaders/ShaderInterop.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ struct IndirectDispatchArgs
8888
// Common buffers:
8989
// These are usable by all shaders
9090
#define CBSLOT_IMAGE 0
91-
#define CBSLOT_FONT 0
9291
#define CBSLOT_RENDERER_FRAME 0
9392
#define CBSLOT_RENDERER_CAMERA 1
9493

@@ -116,7 +115,6 @@ struct IndirectDispatchArgs
116115
#define CBSLOT_RESERVED_PS5_1 1
117116

118117
#define CBSLOT_IMAGE 2
119-
#define CBSLOT_FONT 2
120118
#define CBSLOT_RENDERER_FRAME 2
121119
#define CBSLOT_RENDERER_CAMERA 3
122120

WickedEngine/shaders/ShaderInterop_Image.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ enum IMAGE_FLAGS
2626
FONT_FLAG_OUTPUT_COLOR_SPACE_LINEAR = 1u << 18u,
2727
};
2828

29-
struct FontVertex
30-
{
31-
float2 pos;
32-
float2 uv;
33-
};
3429
namespace SDF
3530
{
3631
static const uint padding = 5;
@@ -68,9 +63,10 @@ struct alignas(16) ImageConstants
6863
uint highlight_xy; // packed half2
6964
uint angular_softness_direction; // packed half2
7065

71-
uint2 softness_bolden_hdrscaling; // packed half3
7266
uint angular_softness_mad; // packed half2
7367
uint padding0;
68+
uint padding1;
69+
uint padding2;
7470

7571
uint2 gradient_color; // packed half4
7672
uint gradient_uv_start; // packed half2

WickedEngine/shaders/imageHF.hlsli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ float Wedge2D(float2 v, float2 w)
1010

1111
struct VertextoPixel
1212
{
13-
float4 pos : SV_POSITION;
14-
float4 screen : TEXCOORD0;
15-
float2 q : TEXCOORD1;
16-
float2 edge : TEXCOORD2;
13+
float4 pos : SV_Position;
14+
float4 screen : SCREENCOORD;
15+
float2 q : QUADCOORD;
16+
float2 edge : EDGECOORD;
1717

1818
float2 uv_screen()
1919
{

WickedEngine/shaders/imagePS.hlsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ float4 main(VertextoPixel input) : SV_TARGET
44
{
55
half4 color = unpack_half4(image.packed_color);
66

7+
const half hdr_scaling = unpack_half2(image.hdr_scaling_aspect).x;
8+
79
[branch]
810
if (image.IsFont())
911
{
1012
// Font renderer:
1113
Texture2D<half4> tex = bindless_textures_half4[descriptor_index(image.texture_base_index)];
1214
half value = tex.SampleLevel(sampler_linear_clamp, input.q, 0).r;
1315

14-
const half3 softness_bolden_hdrscaling = unpack_half3(image.softness_bolden_hdrscaling);
15-
const half softness = softness_bolden_hdrscaling.x;
16-
const half bolden = softness_bolden_hdrscaling.y;
17-
const half hdr_scaling = softness_bolden_hdrscaling.z;
16+
const half2 softness_bolden = unpack_half2(image.angular_softness_direction);
17+
const half softness = softness_bolden.x;
18+
const half bolden = softness_bolden.y;
1819

1920
[branch]
2021
if (image.flags & FONT_FLAG_SDF_RENDERING)
@@ -57,7 +58,6 @@ float4 main(VertextoPixel input) : SV_TARGET
5758
// Image renderer:
5859
SamplerState sam = bindless_samplers[descriptor_index(image.sampler_index)];
5960

60-
const half hdr_scaling = unpack_half2(image.hdr_scaling_aspect).x;
6161
const half canvas_aspect = unpack_half2(image.hdr_scaling_aspect).y;
6262
const half border_soften = unpack_half2(image.bordersoften_saturation).x;
6363
const half saturation = unpack_half2(image.bordersoften_saturation).y;

WickedEngine/shaders/imageVS.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ VertextoPixel main(uint vertexID : SV_VertexID, uint instanceID : SV_InstanceID)
1717
{
1818
// Font renderer:
1919
uint vID = instanceID * 4 + vertexID;
20-
FontVertex vertex = bindless_buffers[descriptor_index(image.buffer_index)].Load<FontVertex>(image.buffer_offset + vID * sizeof(FontVertex));
20+
const float4 vertex = bindless_buffers[descriptor_index(image.buffer_index)].Load<float4>(image.buffer_offset + vID * sizeof(float4));
2121

22-
Out.pos = mul(image.transform, float4(asfloat(vertex.pos), 0, 1));
23-
Out.q = vertex.uv;
22+
Out.pos = mul(image.transform, float4(vertex.xy, 0, 1));
23+
Out.q = vertex.zw;
2424
switch (vertexID)
2525
{
2626
default:

WickedEngine/wiFont.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace wi::font
111111
bool start_new_word = false;
112112
};
113113

114-
static thread_local wi::vector<FontVertex> vertexList;
114+
static thread_local wi::vector<XMFLOAT4> vertexList;
115115
ParseStatus ParseText(const wchar_t* text, size_t text_length, const Params& params)
116116
{
117117
ParseStatus status;
@@ -128,11 +128,11 @@ namespace wi::font
128128
if (status.last_word_begin > 0 && params.h_wrap >= 0 && status.cursor.position.x >= params.h_wrap - 1)
129129
{
130130
// Word ended and wrap detected, push down last word by one line:
131-
const float word_offset = vertexList[status.last_word_begin].pos.x;
131+
const float word_offset = vertexList[status.last_word_begin].x;
132132
for (size_t i = status.last_word_begin; i < status.quadCount * 4; ++i)
133133
{
134-
vertexList[i].pos.x -= word_offset;
135-
vertexList[i].pos.y += linebreak_size;
134+
vertexList[i].x -= word_offset;
135+
vertexList[i].y += linebreak_size;
136136
}
137137
status.cursor.position.x -= word_offset;
138138
status.cursor.position.y += linebreak_size;
@@ -202,11 +202,6 @@ namespace wi::font
202202
const float top = status.cursor.position.y + glyphOffsetY;
203203
const float bottom = top + glyphHeight;
204204

205-
vertexList[vertexID + 0].pos = float2(left, top);
206-
vertexList[vertexID + 1].pos = float2(right, top);
207-
vertexList[vertexID + 2].pos = float2(left, bottom);
208-
vertexList[vertexID + 3].pos = float2(right, bottom);
209-
210205
float tc_left = glyph.tc_left;
211206
float tc_right = glyph.tc_right;
212207
float tc_top = glyph.tc_top;
@@ -219,10 +214,11 @@ namespace wi::font
219214
{
220215
std::swap(tc_top, tc_bottom);
221216
}
222-
vertexList[vertexID + 0].uv = float2(tc_left, tc_top);
223-
vertexList[vertexID + 1].uv = float2(tc_right, tc_top);
224-
vertexList[vertexID + 2].uv = float2(tc_left, tc_bottom);
225-
vertexList[vertexID + 3].uv = float2(tc_right, tc_bottom);
217+
218+
vertexList[vertexID + 0] = float4(left, top, tc_left, tc_top);
219+
vertexList[vertexID + 1] = float4(right, top, tc_right, tc_top);
220+
vertexList[vertexID + 2] = float4(left, bottom, tc_left, tc_bottom);
221+
vertexList[vertexID + 3] = float4(right, bottom, tc_right, tc_bottom);
226222

227223
int advance, lsb;
228224
stbtt_GetCodepointHMetrics(&glyph.fontStyle->fontInfo, code, &advance, &lsb);
@@ -259,7 +255,7 @@ namespace wi::font
259255

260256
void CommitText(void* vertexList_GPU)
261257
{
262-
std::memcpy(vertexList_GPU, vertexList.data(), sizeof(FontVertex) * vertexList.size());
258+
std::memcpy(vertexList_GPU, vertexList.data(), sizeof(XMFLOAT4) * vertexList.size());
263259
}
264260

265261
}
@@ -560,7 +556,7 @@ namespace wi::font
560556
M = M * Projection;
561557

562558
GraphicsDevice* device = wi::graphics::GetDevice();
563-
GraphicsDevice::GPUAllocation mem = device->AllocateGPU(sizeof(FontVertex) * status.quadCount * 4, cmd);
559+
GraphicsDevice::GPUAllocation mem = device->AllocateGPU(sizeof(float4) * status.quadCount * 4, cmd);
564560
if (!mem.IsValid())
565561
return status.cursor;
566562
CommitText(mem.data);
@@ -612,8 +608,9 @@ namespace wi::font
612608
image.packed_color = pack_half4(color);
613609
bolden = params.shadow_bolden;
614610
softness = params.shadow_softness * 0.5f;
615-
image.softness_bolden_hdrscaling = pack_half3(softness, bolden, hdr_scaling);
616-
device->BindDynamicConstantBuffer(image, CBSLOT_FONT, cmd);
611+
image.hdr_scaling_aspect = pack_half2(hdr_scaling, 0);
612+
image.angular_softness_direction = pack_half2(softness, bolden);
613+
device->BindDynamicConstantBuffer(image, CBSLOT_IMAGE, cmd);
617614

618615
device->DrawInstanced(4, status.quadCount, 0, 0, cmd);
619616
}
@@ -627,8 +624,9 @@ namespace wi::font
627624
image.packed_color = pack_half4(color);
628625
bolden = params.bolden;
629626
softness = params.softness * 0.5f;
630-
image.softness_bolden_hdrscaling = pack_half3(softness, bolden, hdr_scaling);
631-
device->BindDynamicConstantBuffer(image, CBSLOT_FONT, cmd);
627+
image.hdr_scaling_aspect = pack_half2(hdr_scaling, 0);
628+
image.angular_softness_direction = pack_half2(softness, bolden);
629+
device->BindDynamicConstantBuffer(image, CBSLOT_IMAGE, cmd);
632630

633631
device->DrawInstanced(4, status.quadCount, 0, 0, cmd);
634632

WickedEngine/wiVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace wi::version
99
// minor features, major updates, breaking compatibility changes
1010
const int minor = 72;
1111
// minor bug fixes, alterations, refactors, updates
12-
const int revision = 112;
12+
const int revision = 113;
1313

1414
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
1515

0 commit comments

Comments
 (0)