Skip to content

Commit

Permalink
Merge pull request #57 from lamarrr/bring-up-core-systems
Browse files Browse the repository at this point in the history
Core-Systems Bring-Up 2
  • Loading branch information
lamarrr authored Dec 7, 2024
2 parents 3446b84 + 40ec0c4 commit efc963c
Show file tree
Hide file tree
Showing 64 changed files with 3,118 additions and 2,054 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: false
LineEnding: LF
LineEnding: CRLF
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ else()
-Wno-nullability-extension)
else()
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W3 /Zc:preprocessor)
add_compile_options(/W3 /Zc:preprocessor /permissive)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
endif()
Expand Down
6 changes: 3 additions & 3 deletions ashura/editor/editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main()

sw[0].on();

scalar.frame(250, 100);
scalar.frame(250, 100);

slider.range(0, 100).interp(0).axis(Axis::Y);

Expand Down Expand Up @@ -76,7 +76,7 @@ scalar.frame(250, 100);
.axis(Axis::X)
.cross_align(0)
.main_align(MainAlign::SpaceBetween)
.frame(1920, 1080);
.frame(1'920, 1'080);

engine->run(flex);
}
}
18 changes: 9 additions & 9 deletions ashura/engine/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ static inline void flush_batch(Canvas & c)
.params_ssbo = ctx.ngons.descriptor,
.textures = ctx.gpu.texture_views,
.index_counts =
ctx.canvas.ngon_index_counts.span().slice(batch.objects)};
ctx.canvas.ngon_index_counts.view().slice(batch.objects)};
ctx.passes.ngon->encode(ctx.gpu, ctx.enc, params);
});
return;
Expand Down Expand Up @@ -638,12 +638,12 @@ Canvas & Canvas::text(ShapeInfo const & info, TextBlock const & block,
f32 const block_width = max(layout.extent.x, style.align_width);
Vec2 const block_extent{block_width, layout.extent.y};

constexpr u8 PASS_BACKGROUND = 0;
constexpr u8 PASS_GLYPH_SHADOWS = 1;
constexpr u8 PASS_GLYPHS = 2;
constexpr u8 PASS_UNDERLINE = 3;
constexpr u8 PASS_STRIKETHROUGH = 4;
constexpr u8 NUM_PASSES = 5;
static constexpr u8 PASS_BACKGROUND = 0;
static constexpr u8 PASS_GLYPH_SHADOWS = 1;
static constexpr u8 PASS_GLYPHS = 2;
static constexpr u8 PASS_UNDERLINE = 3;
static constexpr u8 PASS_STRIKETHROUGH = 4;
static constexpr u8 NUM_PASSES = 5;

for (u8 pass = 0; pass < NUM_PASSES; pass++)
{
Expand All @@ -667,7 +667,7 @@ Canvas & Canvas::text(ShapeInfo const & info, TextBlock const & block,
f32 cursor = space_align(block_width, ln.metrics.width, alignment) -
ln.metrics.width * 0.5F;
for (TextRun const & run :
layout.runs.span().slice(ln.first_run, ln.num_runs))
layout.runs.view().slice(ln.first_run, ln.num_runs))
{
FontStyle const & font_style = block.fonts[run.style];
TextStyle const & run_style = style.runs[run.style];
Expand Down Expand Up @@ -823,7 +823,7 @@ Canvas & Canvas::triangles(ShapeInfo const & info, Span<Vec2 const> points,
ngon_vertices.extend(points).unwrap();
ngon_indices.extend(idx).unwrap();

for (u32 & v : ngon_indices.span().slice(first_index))
for (u32 & v : ngon_indices.view().slice(first_index))
{
v += first_vertex;
}
Expand Down
714 changes: 357 additions & 357 deletions ashura/engine/color.h

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions ashura/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void Engine::init(AllocatorImpl allocator, void * app,

data_u32.resize_uninit(data.size() >> 2).unwrap();

mem::copy(data.span(), data_u32.span().as_u8());
mem::copy(data.view(), data_u32.view().as_u8());

logger->trace("Loaded shader ", shader_id, " from file");

Expand Down Expand Up @@ -442,7 +442,7 @@ void Engine::recreate_swapchain_()

for (gpu::ColorSpace cp : preferred_color_spaces)
{
Span sel = find_if(formats.span(), [&](gpu::SurfaceFormat a) {
Span sel = find_if(formats.view(), [&](gpu::SurfaceFormat a) {
return a.color_space == cp;
});
if (!sel.is_empty())
Expand All @@ -460,7 +460,7 @@ void Engine::recreate_swapchain_()

for (gpu::PresentMode pm : preferred_present_modes)
{
if (!find(present_modes.span(), pm).is_empty())
if (!find(present_modes.view(), pm).is_empty())
{
found_present_mode = true;
present_mode = pm;
Expand Down
2 changes: 1 addition & 1 deletion ashura/engine/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ash
{

// App Unit (AU)
constexpr i32 AU_UNIT = 128 * 64;
inline constexpr i32 AU_UNIT = 128 * 64;

static_assert((AU_UNIT % 64) == 0,
"App Unit needs to be in 26.6 Fractional Unit");
Expand Down
3 changes: 1 addition & 2 deletions ashura/engine/font_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ Result<Dyn<Font *>, FontErr> Font::decode(Span<u8 const> encoded, u32 face,
if (ft_postscript_name != nullptr)
{
postscript_name_size = strlen(ft_postscript_name);
if (!postscript_name.extend(
Span{ft_postscript_name, postscript_name_size}))
if (!postscript_name.extend(Span{ft_postscript_name, postscript_name_size}))
{
return Err{FontErr::OutOfMemory};
}
Expand Down
20 changes: 10 additions & 10 deletions ashura/engine/font_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct FontImpl : Font

virtual Result<> rasterize(u32 font_height, AllocatorImpl allocator) override
{
constexpr u32 MIN_ATLAS_EXTENT = 512;
static constexpr u32 MIN_ATLAS_EXTENT = 512;
static_assert(MIN_ATLAS_EXTENT > 0, "Font atlas extent must be non-zero");
static_assert(MIN_ATLAS_EXTENT > 128,
"Font atlas extent must be at least 128px");
Expand All @@ -147,7 +147,7 @@ struct FontImpl : Font

CpuFontAtlas atlas;

if (!atlas.glyphs.resize_defaulted(glyphs.size32()))
if (!atlas.glyphs.resize(glyphs.size32()))
{
return Err{};
}
Expand Down Expand Up @@ -234,14 +234,14 @@ struct FontImpl : Font
rect_pack::pack_rects(pack_context, rects.data() + num_packed,
num_rasterized_glyphs - num_packed);
auto [just_packed, unpacked] =
partition(rects.span().slice(num_packed),
partition(rects.view().slice(num_packed),
[](rect_pack::rect const & r) { return r.was_packed; });
for (u32 i = num_packed; i < (num_packed + just_packed.span); i++)
CHECK(!just_packed.is_empty());
for (auto & rect : rects.view().slice(num_packed, just_packed.size32()))
{
rects[i].layer = num_layers;
rect.layer = num_layers;
}
CHECK(just_packed.span != 0);
num_packed += (u32) just_packed.span;
num_packed += just_packed.size32();
num_layers++;
}

Expand All @@ -264,7 +264,7 @@ struct FontImpl : Font
u64 const atlas_layer_size = atlas_area;
u64 const atlas_size = atlas_layer_size * num_layers;

if (!atlas.channels.resize_defaulted(atlas_size))
if (!atlas.channels.resize(atlas_size))
{
return Err{};
}
Expand Down Expand Up @@ -349,7 +349,7 @@ struct FontImpl : Font

Vec<gpu::ImageView> views;

views.resize_defaulted(atlas.num_layers).unwrap();
views.resize(atlas.num_layers).unwrap();

for (u32 i = 0; i < atlas.num_layers; i++)
{
Expand Down Expand Up @@ -427,7 +427,7 @@ struct FontImpl : Font
Vec<u32> textures;
Vec<AtlasGlyph> glyphs;

textures.resize_defaulted(atlas.num_layers).unwrap();
textures.resize(atlas.num_layers).unwrap();
glyphs.extend(atlas.glyphs).unwrap();

for (u32 i = 0; i < atlas.num_layers; i++)
Expand Down
2 changes: 1 addition & 1 deletion ashura/engine/gpu_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ static void uninit_objects(gpu::Device * d, Span<gpu::Object const> objects)
d->uninit_descriptor_set_layout(obj.descriptor_set_layout);
break;
default:
UNREACHABLE();
CHECK_UNREACHABLE();
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions ashura/engine/gpu_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
namespace ash
{

constexpr u32 TEXTURE_WHITE = 0;
constexpr u32 TEXTURE_BLACK = 1;
constexpr u32 TEXTURE_TRANSPARENT = 2;
constexpr u32 TEXTURE_RED = 3;
constexpr u32 TEXTURE_GREEN = 4;
constexpr u32 TEXTURE_BLUE = 5;
constexpr u32 NUM_DEFAULT_TEXTURES = TEXTURE_BLUE + 1;

constexpr u32 SAMPLER_LINEAR = 0;
constexpr u32 SAMPLER_NEAREST = 1;
constexpr u32 SAMPLER_LINEAR_CLAMPED = 2;
constexpr u32 SAMPLER_NEAREST_CLAMPED = 3;
constexpr u32 NUM_DEFAULT_SAMPLERS = SAMPLER_NEAREST_CLAMPED + 1;
inline constexpr u32 TEXTURE_WHITE = 0;
inline constexpr u32 TEXTURE_BLACK = 1;
inline constexpr u32 TEXTURE_TRANSPARENT = 2;
inline constexpr u32 TEXTURE_RED = 3;
inline constexpr u32 TEXTURE_GREEN = 4;
inline constexpr u32 TEXTURE_BLUE = 5;
inline constexpr u32 NUM_DEFAULT_TEXTURES = TEXTURE_BLUE + 1;

inline constexpr u32 SAMPLER_LINEAR = 0;
inline constexpr u32 SAMPLER_NEAREST = 1;
inline constexpr u32 SAMPLER_LINEAR_CLAMPED = 2;
inline constexpr u32 SAMPLER_NEAREST_CLAMPED = 3;
inline constexpr u32 NUM_DEFAULT_SAMPLERS = SAMPLER_NEAREST_CLAMPED + 1;

struct FramebufferAttachment
{
Expand Down
12 changes: 5 additions & 7 deletions ashura/engine/image_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern "C"
#include "jpeglib.h"
#include "png.h"
#include "webp/decode.h"
#include "webp/types.h"
}

namespace ash
Expand Down Expand Up @@ -202,13 +201,12 @@ ImageDecodeError decode_jpg(Span<u8 const> bytes, DecodedImage & image)

ImageDecodeError decode_image(Span<u8 const> bytes, DecodedImage & image)
{
constexpr u8 JPG_MAGIC[] = {0xFF, 0xD8, 0xFF};

constexpr u8 PNG_MAGIC[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};

static constexpr u8 JPG_MAGIC[] = {0xFF, 0xD8, 0xFF};
static constexpr u8 PNG_MAGIC[] = {0x89, 0x50, 0x4E, 0x47,
0x0D, 0x0A, 0x1A, 0x0A};
// RIFF-[file size: 4 bytes]-WEBP
constexpr u8 WEBP_MAGIC1[] = {'R', 'I', 'F', 'F'};
constexpr u8 WEBP_MAGIC2[] = {'W', 'E', 'B', 'P'};
static constexpr u8 WEBP_MAGIC1[] = {'R', 'I', 'F', 'F'};
static constexpr u8 WEBP_MAGIC2[] = {'W', 'E', 'B', 'P'};

if (range_eq(bytes.slice(0, size(JPG_MAGIC)), JPG_MAGIC))
{
Expand Down
78 changes: 39 additions & 39 deletions ashura/engine/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ enum class KeyCode : u16
EndCall = 290
};

constexpr u16 NUM_KEYS = 512;
inline constexpr u16 NUM_KEYS = 512;

enum class MouseButtons : u8
{
Expand Down Expand Up @@ -743,44 +743,44 @@ enum class Cursor
};

/// @brief default charset is ASCII
constexpr char const MIME_TEXT_PLAIN[] = "text/plain";
constexpr char const MIME_TEXT_UTF8[] = "text/plain;charset=UTF-8";
constexpr char const MIME_TEXT_CSS[] = "text/css";
constexpr char const MIME_TEXT_CSV[] = "text/csv";
constexpr char const MIME_TEXT_HTML[] = "text/html";
constexpr char const MIME_TEXT_JS[] = "text/javascript";
constexpr char const MIME_TEXT_MARKDOWN[] = "text/markdown";

constexpr char const MIME_IMAGE_AVIF[] = "image/avif";
constexpr char const MIME_IMAGE_BMP[] = "image/bmp";
constexpr char const MIME_IMAGE_HEIF[] = "image/heif";
constexpr char const MIME_IMAGE_JPEG[] = "image/jpeg";
constexpr char const MIME_IMAGE_PNG[] = "image/png";
constexpr char const MIME_IMAGE_SVG[] = "image/svg+xml";
constexpr char const MIME_IMAGE_WEBP[] = "image/webp";

constexpr char const MIME_VIDEO_AV1[] = "video/AV1";
constexpr char const MIME_VIDEO_H264[] = "video/H264";
constexpr char const MIME_VIDEO_H265[] = "video/H265";
constexpr char const MIME_VIDEO_H266[] = "video/H266";
constexpr char const MIME_VIDEO_MATROSKA[] = "video/matroska";
constexpr char const MIME_VIDEO_MP4[] = "video/mp4";
constexpr char const MIME_VIDEO_RAW[] = "video/raw";
constexpr char const MIME_VIDEO_VP8[] = "video/VP8";
constexpr char const MIME_VIDEO_VP9[] = "video/VP9";

constexpr char const MIME_MODEL_GLTF_BINARY[] = "model/gltf+binary";
constexpr char const MIME_MODEL_GLTF_JSON[] = "model/gltf+json";
constexpr char const MIME_MODEL_MESH[] = "model/mesh";
constexpr char const MIME_MODEL_MTL[] = "model/mtl";
constexpr char const MIME_MODEL_OBJ[] = "model/obj";
constexpr char const MIME_MODEL_STL[] = "model/stl";

constexpr char const MIME_FONT_OTF[] = "font/otf";
constexpr char const MIME_FONT_SFNT[] = "font/sfnt";
constexpr char const MIME_FONT_TTF[] = "font/ttf";
constexpr char const MIME_FONT_WOFF[] = "font/woff";
constexpr char const MIME_FONT_WOFF2[] = "font/woff2";
inline constexpr char const MIME_TEXT_PLAIN[] = "text/plain";
inline constexpr char const MIME_TEXT_UTF8[] = "text/plain;charset=UTF-8";
inline constexpr char const MIME_TEXT_CSS[] = "text/css";
inline constexpr char const MIME_TEXT_CSV[] = "text/csv";
inline constexpr char const MIME_TEXT_HTML[] = "text/html";
inline constexpr char const MIME_TEXT_JS[] = "text/javascript";
inline constexpr char const MIME_TEXT_MARKDOWN[] = "text/markdown";

inline constexpr char const MIME_IMAGE_AVIF[] = "image/avif";
inline constexpr char const MIME_IMAGE_BMP[] = "image/bmp";
inline constexpr char const MIME_IMAGE_HEIF[] = "image/heif";
inline constexpr char const MIME_IMAGE_JPEG[] = "image/jpeg";
inline constexpr char const MIME_IMAGE_PNG[] = "image/png";
inline constexpr char const MIME_IMAGE_SVG[] = "image/svg+xml";
inline constexpr char const MIME_IMAGE_WEBP[] = "image/webp";

inline constexpr char const MIME_VIDEO_AV1[] = "video/AV1";
inline constexpr char const MIME_VIDEO_H264[] = "video/H264";
inline constexpr char const MIME_VIDEO_H265[] = "video/H265";
inline constexpr char const MIME_VIDEO_H266[] = "video/H266";
inline constexpr char const MIME_VIDEO_MATROSKA[] = "video/matroska";
inline constexpr char const MIME_VIDEO_MP4[] = "video/mp4";
inline constexpr char const MIME_VIDEO_RAW[] = "video/raw";
inline constexpr char const MIME_VIDEO_VP8[] = "video/VP8";
inline constexpr char const MIME_VIDEO_VP9[] = "video/VP9";

inline constexpr char const MIME_MODEL_GLTF_BINARY[] = "model/gltf+binary";
inline constexpr char const MIME_MODEL_GLTF_JSON[] = "model/gltf+json";
inline constexpr char const MIME_MODEL_MESH[] = "model/mesh";
inline constexpr char const MIME_MODEL_MTL[] = "model/mtl";
inline constexpr char const MIME_MODEL_OBJ[] = "model/obj";
inline constexpr char const MIME_MODEL_STL[] = "model/stl";

inline constexpr char const MIME_FONT_OTF[] = "font/otf";
inline constexpr char const MIME_FONT_SFNT[] = "font/sfnt";
inline constexpr char const MIME_FONT_TTF[] = "font/ttf";
inline constexpr char const MIME_FONT_WOFF[] = "font/woff";
inline constexpr char const MIME_FONT_WOFF2[] = "font/woff2";

struct ClipBoard
{
Expand Down
3 changes: 1 addition & 2 deletions ashura/engine/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "ashura/engine/gpu_context.h"
#include "ashura/engine/passes.h"
#include "ashura/std/dyn.h"
#include "ashura/std/math.h"

namespace ash
{
Expand Down Expand Up @@ -158,7 +157,7 @@ struct Renderer
p->acquire(ctx, passes, assets);
}

resources.resize_defaulted(ctx.buffering).unwrap();
resources.resize(ctx.buffering).unwrap();
}

void release(GpuContext & ctx, AssetMap & assets)
Expand Down
2 changes: 1 addition & 1 deletion ashura/engine/shader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ ShaderCompileError
language = EShLanguage::EShLangVertex;
break;
default:
UNREACHABLE();
CHECK_UNREACHABLE();
}

char const * buff_p = (char *) buff.data();
Expand Down
2 changes: 1 addition & 1 deletion ashura/engine/shader.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// SPDX-License-Identifier: MIT
#pragma once

#include "ashura/std/vec.h"
#include "ashura/std/log.h"
#include "ashura/std/types.h"
#include "ashura/std/vec.h"

namespace ash
{
Expand Down
Loading

0 comments on commit efc963c

Please sign in to comment.