Remove d3d12 renderer and replace with vulkan

This commit is contained in:
2026-03-09 10:16:38 -04:00
parent e35b849d49
commit b074d2113f
9 changed files with 1986 additions and 1563 deletions

View File

@@ -29,7 +29,7 @@
#include "audio/audio_coreaudio.cpp"
#else
#include "platform/platform_win32.cpp"
#include "renderer/renderer_dx12.cpp"
#include "renderer/renderer_vulkan.cpp"
#include "midi/midi_win32.cpp"
#include "audio/audio_asio.cpp"
#endif

View File

@@ -2,15 +2,19 @@
#include "base/base_core.h"
struct Renderer;
#ifdef __cplusplus
extern "C" {
#endif
typedef struct Renderer Renderer;
struct Clay_RenderCommandArray;
struct RendererDesc {
void *window_handle = nullptr;
S32 width = 1280;
S32 height = 720;
S32 frame_count = 2;
};
typedef struct RendererDesc {
void *window_handle;
S32 width;
S32 height;
S32 frame_count;
} RendererDesc;
Renderer *renderer_create(RendererDesc *desc);
@@ -31,8 +35,11 @@ void renderer_set_clear_color(Renderer *renderer, F32 r, F32 g, F32 b);
// Text measurement callback compatible with UI_MeasureTextFn
// Measures text of given length (NOT necessarily null-terminated) at font_size pixels.
// user_data should be the Renderer pointer.
struct Vec2F32;
Vec2F32 renderer_measure_text(const char *text, S32 length, F32 font_size, void *user_data);
// Upload an RGBA8 icon atlas texture for icon rendering (4 bytes per pixel)
void renderer_create_icon_atlas(Renderer *renderer, const U8 *data, S32 w, S32 h);
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

61
src/renderer/ui.f.glsl Normal file
View File

@@ -0,0 +1,61 @@
#version 450
layout(set = 0, binding = 0) uniform sampler2D tex;
layout(location = 0) in vec2 frag_uv;
layout(location = 1) in vec4 frag_col;
layout(location = 2) in vec2 frag_rect_min;
layout(location = 3) in vec2 frag_rect_max;
layout(location = 4) in vec4 frag_corner_radii;
layout(location = 5) in float frag_border_thickness;
layout(location = 6) in float frag_softness;
layout(location = 7) in float frag_mode;
layout(location = 8) in vec2 frag_pixel_pos;
layout(location = 0) out vec4 out_color;
float rounded_rect_sdf(vec2 sample_pos, vec2 rect_center, vec2 rect_half_size, float radius) {
vec2 d = abs(sample_pos - rect_center) - rect_half_size + vec2(radius, radius);
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - radius;
}
void main() {
vec4 col = frag_col;
if (frag_mode > 1.5) {
// RGBA textured mode: sample all channels, multiply by vertex color
vec4 tex_sample = texture(tex, frag_uv);
col *= tex_sample;
} else if (frag_mode > 0.5) {
// Alpha-only textured mode: sample R channel as alpha (font atlas)
float alpha = texture(tex, frag_uv).r;
col.a *= alpha;
} else {
// SDF rounded rect mode
vec2 pixel_pos = frag_pixel_pos;
vec2 rect_center = (frag_rect_min + frag_rect_max) * 0.5;
vec2 rect_half_size = (frag_rect_max - frag_rect_min) * 0.5;
// corner_radii = (TL, TR, BR, BL) - select radius by quadrant
float radius = (pixel_pos.x < rect_center.x)
? ((pixel_pos.y < rect_center.y) ? frag_corner_radii.x : frag_corner_radii.w)
: ((pixel_pos.y < rect_center.y) ? frag_corner_radii.y : frag_corner_radii.z);
float softness = max(frag_softness, 0.5);
float dist = rounded_rect_sdf(pixel_pos, rect_center, rect_half_size, radius);
if (frag_border_thickness > 0) {
float inner_dist = dist + frag_border_thickness;
float outer_alpha = 1.0 - smoothstep(-softness, softness, dist);
float inner_alpha = smoothstep(-softness, softness, inner_dist);
col.a *= outer_alpha * inner_alpha;
} else {
col.a *= 1.0 - smoothstep(-softness, softness, dist);
}
}
// Dither to reduce gradient banding (interleaved gradient noise)
float dither = fract(52.9829189 * fract(dot(frag_pixel_pos, vec2(0.06711056, 0.00583715)))) - 0.5;
col.rgb += dither / 255.0;
if (col.a < 0.002) discard;
out_color = col;
}

43
src/renderer/ui.v.glsl Normal file
View File

@@ -0,0 +1,43 @@
#version 450
layout(push_constant) uniform PushConstants {
vec2 viewport_size;
vec2 _padding;
} pc;
layout(location = 0) in vec2 in_pos;
layout(location = 1) in vec2 in_uv;
layout(location = 2) in vec4 in_col;
layout(location = 3) in vec2 in_rect_min;
layout(location = 4) in vec2 in_rect_max;
layout(location = 5) in vec4 in_corner_radii;
layout(location = 6) in float in_border_thickness;
layout(location = 7) in float in_softness;
layout(location = 8) in float in_mode;
layout(location = 0) out vec2 frag_uv;
layout(location = 1) out vec4 frag_col;
layout(location = 2) out vec2 frag_rect_min;
layout(location = 3) out vec2 frag_rect_max;
layout(location = 4) out vec4 frag_corner_radii;
layout(location = 5) out float frag_border_thickness;
layout(location = 6) out float frag_softness;
layout(location = 7) out float frag_mode;
layout(location = 8) out vec2 frag_pixel_pos;
void main() {
vec2 ndc;
ndc.x = (in_pos.x / pc.viewport_size.x) * 2.0 - 1.0;
ndc.y = (in_pos.y / pc.viewport_size.y) * 2.0 - 1.0; // Vulkan Y is top-down already
gl_Position = vec4(ndc, 0.0, 1.0);
frag_uv = in_uv;
frag_col = in_col;
frag_rect_min = in_rect_min;
frag_rect_max = in_rect_max;
frag_corner_radii = in_corner_radii;
frag_border_thickness = in_border_thickness;
frag_softness = in_softness;
frag_mode = in_mode;
frag_pixel_pos = in_pos;
}