Skip to content

Commit

Permalink
Merge branch 'bring-up' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Nov 30, 2024
2 parents 876a118 + 30f5ca4 commit b5ee31c
Show file tree
Hide file tree
Showing 21 changed files with 399 additions and 202 deletions.
68 changes: 39 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ set(SDL_STATIC

include(FetchContent)

set(ASH_VULKAN_VERSION "1.3.296.0")

FetchContent_Declare(
VulkanHeaders
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
GIT_TAG vulkan-sdk-1.3.296.0)
GIT_TAG vulkan-sdk-${ASH_VULKAN_VERSION})

FetchContent_Declare(
VulkanGLSL
GIT_REPOSITORY https://github.com/KhronosGroup/glslang.git
GIT_TAG vulkan-sdk-1.3.296.0)
GIT_TAG vulkan-sdk-${ASH_VULKAN_VERSION})

FetchContent_Declare(
SpirvReflect
GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Reflect.git
GIT_TAG vulkan-sdk-1.3.296.0)
GIT_TAG vulkan-sdk-${ASH_VULKAN_VERSION})

FetchContent_Declare(
VulkanUtilityLibraries
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
GIT_TAG vulkan-sdk-1.3.296.0)
GIT_TAG vulkan-sdk-${ASH_VULKAN_VERSION})

FetchContent_Declare(
VulkanLoader
Expand Down Expand Up @@ -96,6 +98,12 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/curl/curl.git
GIT_TAG curl-8_8_0)

FetchContent_Declare(
xxHash
GIT_REPOSITORY https://github.com/Cyan4973/xxHash.git
GIT_TAG dd11140
CONFIGURE_COMMAND "" BUILD_COMMAND "")

FetchContent_Declare(
fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
Expand All @@ -107,7 +115,6 @@ find_package(GTest REQUIRED)
find_package(libjpeg-turbo CONFIG REQUIRED)
find_package(PNG REQUIRED)
find_package(FFMPEG REQUIRED)
find_package(xxHash CONFIG REQUIRED)
find_package(benchmark CONFIG REQUIRED)
find_package(Threads REQUIRED)

Expand All @@ -123,12 +130,14 @@ FetchContent_MakeAvailable(SpirvReflect)
FetchContent_MakeAvailable(SDL3)
FetchContent_MakeAvailable(WebP)
FetchContent_MakeAvailable(CURL)
FetchContent_MakeAvailable(xxHash)
FetchContent_MakeAvailable(fast_float)

file(GLOB SheenBidi_SOURCES ${sheenbidi_SOURCE_DIR}/Source/*.c)

set(xxHash_INCLUDE_DIR ${xxhash_SOURCE_DIR})
set(fast_float_INCLUDE_DIR ${fast_float_SOURCE_DIR}/include)

file(GLOB SheenBidi_SOURCES ${sheenbidi_SOURCE_DIR}/Source/*.c)

add_library(SheenBidi ${SheenBidi_SOURCES})
target_include_directories(
SheenBidi
Expand Down Expand Up @@ -162,8 +171,9 @@ add_library(
ashura/std/panic.cc)
target_include_directories(
ashura_std
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(ashura_std PUBLIC xxHash::xxhash Threads::Threads)
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${xxHash_INCLUDE_DIR})
target_link_libraries(ashura_std PUBLIC Threads::Threads)

add_executable(
ashura_std_tests
Expand All @@ -186,8 +196,8 @@ target_link_libraries(ashura_std_bench benchmark::benchmark
add_library(ashura_gpu ashura/gpu/gpu.cc ashura/gpu/vma_def.cc
ashura/gpu/vulkan.cc)
target_link_libraries(
ashura_gpu ashura_std Vulkan-Headers Vulkan::UtilityHeaders Vulkan::Loader
GPUOpen::VulkanMemoryAllocator)
ashura_gpu PUBLIC ashura_std Vulkan-Headers Vulkan::UtilityHeaders
Vulkan::Loader GPUOpen::VulkanMemoryAllocator)
target_include_directories(ashura_gpu PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

add_library(
Expand All @@ -211,27 +221,27 @@ add_library(
ashura/engine/passes.cc)
target_link_libraries(
ashura_engine
ashura_std
ashura_gpu
glslang::glslang
spirv-reflect-static
SDL3::SDL3-static
harfbuzz
CURL::libcurl
freetype
simdjson::simdjson
webp
webpdecoder
$<IF:$<TARGET_EXISTS:libjpeg-turbo::turbojpeg>,libjpeg-turbo::turbojpeg,libjpeg-turbo::turbojpeg-static>
PNG::PNG
${FFMPEG_LIBRARIES}
SheenBidi::SheenBidi)
PUBLIC ashura_std ashura_gpu
PRIVATE
glslang::glslang
spirv-reflect-static
SDL3::SDL3-static
harfbuzz
CURL::libcurl
freetype
simdjson::simdjson
webp
webpdecoder
$<IF:$<TARGET_EXISTS:libjpeg-turbo::turbojpeg>,libjpeg-turbo::turbojpeg,libjpeg-turbo::turbojpeg-static>
PNG::PNG
${FFMPEG_LIBRARIES}
SheenBidi::SheenBidi)

target_include_directories(
ashura_engine
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${JPEG_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}
${FFMPEG_LIBRARY_DIRS}
PRIVATE ${fast_float_INCLUDE_DIR})
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${JPEG_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS} ${FFMPEG_LIBRARY_DIRS}
${fast_float_INCLUDE_DIR})

add_executable(
ashura_engine_tests
Expand Down
4 changes: 2 additions & 2 deletions ashura/engine/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ struct Canvas
// no need to free it
lambda.inner.allocator = noop_allocator;

return add_pass(Pass{
.name = name, .task = transmute(std::move(lambda), fn(lambda.get()))});
return add_pass(
Pass{.name = name, .task = transmute(std::move(lambda), fn(*lambda))});
}
};

Expand Down
26 changes: 14 additions & 12 deletions ashura/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,23 @@ void Engine::init(AllocatorImpl allocator, void * app,

window_system->listen(
SystemEventTypes::All,
fn(engine, [](Engine * engine, SystemEvent const & event) {
if (event.type == SystemEventTypes::ThemeChanged)
{
engine->view_ctx.theme = event.theme;
}
}));
fn(
engine, +[](Engine * engine, SystemEvent const & event) {
if (event.type == SystemEventTypes::ThemeChanged)
{
engine->view_ctx.theme = event.theme;
}
}));

window_system->listen(
window, WindowEventTypes::All,
fn(engine, [](Engine * engine, WindowEvent const & event) {
if (event.type == WindowEventTypes::CloseRequested)
{
engine->should_shutdown = true;
}
}));
fn(
engine, +[](Engine * engine, WindowEvent const & event) {
if (event.type == WindowEventTypes::CloseRequested)
{
engine->should_shutdown = true;
}
}));

engine->device->begin_frame(nullptr).unwrap();

Expand Down
21 changes: 11 additions & 10 deletions ashura/engine/gpu_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,26 @@ struct Framebuffer
gpu::Extent extent = {};
};

// [ ] use: enum to bits, and float to bits, not casted
struct SamplerHasher
{
constexpr Hash operator()(gpu::SamplerInfo const & info) const
constexpr hash64 operator()(gpu::SamplerInfo const & info) const
{
return hash_combine_n(
(Hash) info.mag_filter, (Hash) info.min_filter,
(Hash) info.mip_map_mode, (Hash) info.address_mode_u,
(Hash) info.address_mode_v, (Hash) info.address_mode_w,
(Hash) info.mip_lod_bias, (Hash) info.anisotropy_enable,
(Hash) info.max_anisotropy, (Hash) info.compare_enable,
(Hash) info.compare_op, (Hash) info.min_lod, (Hash) info.max_lod,
(Hash) info.border_color, (Hash) info.unnormalized_coordinates);
(hash64) info.mag_filter, (hash64) info.min_filter,
(hash64) info.mip_map_mode, (hash64) info.address_mode_u,
(hash64) info.address_mode_v, (hash64) info.address_mode_w,
(hash64) info.mip_lod_bias, (hash64) info.anisotropy_enable,
(hash64) info.max_anisotropy, (hash64) info.compare_enable,
(hash64) info.compare_op, (hash64) info.min_lod, (hash64) info.max_lod,
(hash64) info.border_color, (hash64) info.unnormalized_coordinates);
}
};

struct SamplerEq
{
constexpr Hash operator()(gpu::SamplerInfo const & a,
gpu::SamplerInfo const & b) const
constexpr hash64 operator()(gpu::SamplerInfo const & a,
gpu::SamplerInfo const & b) const
{
return a.mag_filter == b.mag_filter && a.mip_map_mode == b.mip_map_mode &&
a.address_mode_u == b.address_mode_u &&
Expand Down
6 changes: 3 additions & 3 deletions ashura/engine/tests/text_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ TEST(TextCompositor, Main)
ASSERT_TRUE(range_eq(str, text));
};

cmp.command(U""_str, layout, 0, 0, TextCommand::InputText, fn(&insert), noop,
cmp.command(U""_str, layout, 0, 0, TextCommand::InputText, fn(insert), noop,
text, clip, 1, {});

ASSERT_TRUE(inserted);
ASSERT_EQ(cmp.inner.current_record, 1);
ASSERT_EQ(cmp.inner.latest_record, 1);
ASSERT_EQ(cmp.inner.buffer_pos, text.size32());

cmp.command(text, layout, 0, 0, TextCommand::SelectLine, fn(&insert), noop,
{}, clip, 1, {});
cmp.command(text, layout, 0, 0, TextCommand::SelectLine, fn(insert), noop, {},
clip, 1, {});

ASSERT_EQ(cmp.inner.current_record, 1);
ASSERT_EQ(cmp.inner.latest_record, 1);
Expand Down
2 changes: 1 addition & 1 deletion ashura/engine/view_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ struct ViewSystem
};

ViewState s = view.tick(ctx, view.inner.region, view.inner.zoom,
process_events(view), fn(&builder));
process_events(view), fn(builder));

tab_indices.set(idx, (s.tab == I32_MIN) ? tab_index : s.tab);
viewports.set(idx, viewport);
Expand Down
34 changes: 18 additions & 16 deletions ashura/engine/views.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ struct TextInput : View

inner.compositor.command(
inner.content.inner.text, inner.content.inner.layout, region.extent.x,
inner.content.inner.alignment, cmd, fn(&insert), fn(&erase),
inner.content.inner.alignment, cmd, fn(insert), fn(erase),
text_input_utf32, *ctx.clipboard, state.lines_per_page,
(ctx.mouse.position - region.center) * zoom);

Expand Down Expand Up @@ -2085,7 +2085,7 @@ struct ScalarDragBox : View
char scratch[128];
c8 text[128];
Buffer buffer = ash::buffer(span(text).as_char());
fmt::Context ctx = fmt::buffer(&buffer, scratch);
fmt::Context ctx = fmt::buffer(buffer, scratch);
styling.fmt(ctx, state.value.current);
inner.input.inner.content.set_text(span(text).slice(0, buffer.size()));
}
Expand Down Expand Up @@ -2197,11 +2197,12 @@ struct ScalarBox : FlexView
FontStyle{.font = engine->default_font,
.font_height = DEFAULT_THEME.body_font_height,
.line_height = 1})
.on_pressed(fn(this,
[](ScalarBox * b) {
b->inner.drag.state.value.step_value(-1);
b->cb.update(b->inner.drag.state.value.current);
}))
.on_pressed(fn(
this,
+[](ScalarBox * b) {
b->inner.drag.state.value.step_value(-1);
b->cb.update(b->inner.drag.state.value.current);
}))
.padding(5, 5);

inner.inc.text(U"+"_str)
Expand All @@ -2215,11 +2216,12 @@ struct ScalarBox : FlexView
FontStyle{.font = engine->default_font,
.font_height = DEFAULT_THEME.body_font_height,
.line_height = 1})
.on_pressed(fn(this,
[](ScalarBox * b) {
b->inner.drag.state.value.step_value(1);
b->cb.update(b->inner.drag.state.value.current);
}))
.on_pressed(fn(
this,
+[](ScalarBox * b) {
b->inner.drag.state.value.step_value(1);
b->cb.update(b->inner.drag.state.value.current);
}))
.padding(5, 5);

// [ ] color, stroke color, etc. the rectangles at small sizes seem to have
Expand All @@ -2231,7 +2233,7 @@ struct ScalarBox : FlexView
//

inner.drag.cb.update =
fn(this, [](ScalarBox * b, ScalarInput in) { b->cb.update(in); });
fn(this, +[](ScalarBox * b, ScalarInput in) { b->cb.update(in); });

// [ ] set drag box style: create similar methods for it
// [ ] all views must have these methods
Expand Down Expand Up @@ -2972,8 +2974,8 @@ struct ComboBox : View
u32 const index = inner.scroll_view.inner.items.size32();
item.state.index = index;
item.style = Some<ComboBoxItem::Style const *>{&styling.item};
item.cb.selected =
fn(this, [](ComboBox * b, Option<u32> item) { b->set_selected(item); });
item.cb.selected = fn(
this, +[](ComboBox * b, Option<u32> item) { b->set_selected(item); });
item.state.selected = Some<Option<u32> const *>{&state.selected};
inner.scroll_view.inner.items.push(&item).unwrap();
return *this;
Expand All @@ -2983,7 +2985,7 @@ struct ComboBox : View
{
inner.header = Some<ComboBoxItem *>{&item};
item.state.index = 0;
item.cb.selected = fn(this, [](ComboBox * b, Option<u32>) { b->open(); });
item.cb.selected = fn(this, +[](ComboBox * b, Option<u32>) { b->open(); });
item.style = Some<ComboBoxItem::Style const *>{&styling.item};
item.state.selected = None;
return *this;
Expand Down
3 changes: 1 addition & 2 deletions ashura/engine/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ struct WindowImpl
SDL_WindowID id = 0;
SparseVec<Vec<WindowEventListener>> listeners = {};
gpu::Instance * instance = nullptr;
Fn<WindowRegion(Vec2U)> hit_test =
fn([](Vec2U) { return WindowRegion::Normal; });
Fn<WindowRegion(Vec2U)> hit_test = [](Vec2U) { return WindowRegion::Normal; };
};

struct SystemEventListener
Expand Down
6 changes: 3 additions & 3 deletions ashura/std/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,9 @@ struct TaskSchedule
template <TaskFrame F>
TaskInfo to_task_info(F & frame)
{
Fn init = fn(&frame, [](F * frame, void * mem) {
new (mem) F{static_cast<F &&>(*frame)};
});
Fn init = fn(
&frame,
+[](F * frame, void * mem) { new (mem) F{static_cast<F &&>(*frame)}; });

TaskInfo::Uninit uninit = [](void * f) {
F * frame = reinterpret_cast<F *>(f);
Expand Down
11 changes: 6 additions & 5 deletions ashura/std/dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct [[nodiscard]] Dyn

struct Inner
{
H handle = {};
H handle{};
AllocatorImpl allocator = {};
Uninit uninit = noop;
};
Expand Down Expand Up @@ -102,10 +102,11 @@ constexpr Result<Dyn<T *>, Void> dyn_inplace(AllocatorImpl allocator,

return Ok{
Dyn<T *>{object, allocator,
fn(object, [](T * object, AllocatorImpl allocator) {
object->~T();
allocator.ndealloc(object, 1);
})}
fn(
object, +[](T * object, AllocatorImpl allocator) {
object->~T();
allocator.ndealloc(object, 1);
})}
};
}

Expand Down
Loading

0 comments on commit b5ee31c

Please sign in to comment.