Commit 758b4d87 authored by Florian Oetke's avatar Florian Oetke Committed by Lotrado
Browse files

MSVC magic and stuff

parent f76222b4
......@@ -34,8 +34,10 @@ static auto mirrage_asset_reg = mirrage::asset::Embedded_asset(\"${target}\",
gsl::span<const gsl::byte>{reinterpret_cast<const gsl::byte*>(&*${ID}), ${ID}_size});
void ref_embedded_assets_${target}() {
volatile auto x = &mirrage_asset_reg;
volatile mirrage::asset::Embedded_asset* x = &mirrage_asset_reg;
#ifndef _MSC_VER
asm volatile(\"\" : \"+r\" (x));
#endif
}
")
......
This diff is collapsed.
......@@ -38,9 +38,14 @@ target_link_libraries(demo
if (WIN32)
target_link_libraries(demo
PRIVATE
mingw32
SDL2::SDL2main
)
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
target_link_libraries(demo
PRIVATE
mingw32
)
endif()
endif()
option(MIRRAGE_EXPORT_EXECUTABLE "Export executable" OFF)
......
......@@ -129,11 +129,8 @@ namespace {
"screen.print | Prints the currently open screens (=> update+draw next, D> only draw, S> "
"don't update+draw)",
[&]() {
LOG(plog::info) << "Open Screens: " << [](std::ostream & out) -> auto&
{
engine->screens().print_stack(out);
return out;
};
auto screen_list = engine->screens().print_stack();
LOG(plog::info) << "Open Screens: " << screen_list;
});
global_commands->add("screen.enter.test | Enters the test screen",
......
......@@ -71,9 +71,9 @@ namespace mirrage {
void do_queued_actions();
void clear();
template <class Stream>
auto print_stack(Stream& out) const -> auto&
auto print_stack() const -> std::string
{
auto out = std::stringstream();
for(auto& screen : util::range_reverse(_screen_stack)) {
out << screen->name();
switch(screen->_prev_screen_policy()) {
......@@ -84,7 +84,7 @@ namespace mirrage {
}
}
return out;
return out.str();
}
protected:
......
......@@ -48,6 +48,10 @@ namespace mirrage::graphic {
class Descriptor_pool {
public:
Descriptor_pool(vk::Device device,
std::int32_t chunk_size,
std::initializer_list<vk::DescriptorType> types);
// Allocates a descriptor from the pool
// \param bindings: The estimated number of bindings required by the layout
auto create_descriptor(vk::DescriptorSetLayout, std::int32_t bindings) -> DescriptorSet;
......@@ -63,10 +67,6 @@ namespace mirrage::graphic {
std::vector<std::int32_t> _chunks_free_count;
mutable std::mutex _mutex;
Descriptor_pool(vk::Device device,
std::int32_t chunk_size,
std::initializer_list<vk::DescriptorType> types);
Descriptor_pool(const Descriptor_pool&) = delete;
Descriptor_pool(Descriptor_pool&&) = delete;
Descriptor_pool& operator=(const Descriptor_pool&) = delete;
......
......@@ -80,6 +80,19 @@ namespace mirrage::graphic {
template <Image_type Type>
class Texture : public detail::Base_texture {
protected:
Texture(Device& device,
Image_type type,
Image_dimensions sim,
std::int32_t mip_levels,
vk::Format format,
vk::ImageUsageFlags usage,
vk::ImageAspectFlags aspect,
bool dedicated)
: Base_texture(device, type, sim, mip_levels, format, usage, aspect, dedicated)
{
}
public:
Texture(Device& device, Static_image image, vk::Format format)
: Base_texture(device, std::move(image), format)
......@@ -101,7 +114,7 @@ namespace mirrage::graphic {
bool srgb,
gsl::span<const std::uint8_t> data,
std::uint32_t owner_qfamily)
: Texture(device,
: Base_texture(device,
Type,
dim,
generate_mipmaps,
......@@ -110,9 +123,6 @@ namespace mirrage::graphic {
owner_qfamily)
{
}
protected:
using detail::Base_texture::Base_texture;
};
template <Image_type Type>
class Render_target : public Texture<Type> {
......
......@@ -117,11 +117,10 @@ namespace mirrage::renderer {
Render_pass_mask = Render_pass_mask{}) -> std::unique_ptr<Deferred_renderer>;
template <class... Passes>
auto create_renderer(util::maybe<ecs::Entity_manager&> ecs = util::nothing,
Render_pass_mask passes = Render_pass_mask{render_pass_id_of<Passes>()...})
auto create_renderer(util::maybe<ecs::Entity_manager&> ecs = util::nothing)
-> std::unique_ptr<Deferred_renderer>
{
return create_renderer(ecs, passes);
return create_renderer(ecs, Render_pass_mask{render_pass_id_of<Passes>()...});
}
auto all_passes_mask() const noexcept -> auto& { return _all_passes_mask; }
......
......@@ -13,6 +13,7 @@
#include <functional>
#include <variant>
#include <type_traits>
namespace mirrage {
......@@ -168,12 +169,12 @@ namespace mirrage::renderer {
template <class T>
auto render_pass_id_of()
{
if constexpr(std::is_base_of_v<Render_pass_factory, T>)
if constexpr(std::is_base_of<Render_pass_factory, T>::value)
return util::type_uid_of<T>();
else {
static_assert(std::is_base_of_v<Render_pass_factory, T::Factory>,
static_assert(std::is_base_of<Render_pass_factory, typename T::Factory>::value,
"T is not a renderpass, nor its factory.");
return util::type_uid_of<T::Factory>();
return util::type_uid_of<typename T::Factory>();
}
}
......
......@@ -38,7 +38,7 @@ namespace mirrage::renderer {
: _engine(&engine)
, _factory(&factory)
, _entity_manager(ecs)
, _descriptor_set_pool(device().create_descriptor_pool(128,
, _descriptor_set_pool(*device().vk_device(), 128,
{vk::DescriptorType::eUniformBuffer,
vk::DescriptorType::eUniformBufferDynamic,
vk::DescriptorType::eCombinedImageSampler,
......@@ -47,7 +47,7 @@ namespace mirrage::renderer {
vk::DescriptorType::eStorageTexelBuffer,
vk::DescriptorType::eStorageImage,
vk::DescriptorType::eSampledImage,
vk::DescriptorType::eSampler}))
vk::DescriptorType::eSampler})
, _gbuffer(gbuffer_required(passes) ? std::make_unique<GBuffer>(device(),
_descriptor_set_pool,
factory._window.width(),
......
......@@ -122,7 +122,7 @@ namespace mirrage::asset {
, _assets(assets)
, _sampler(sampler)
, _descriptor_set_layout(layout)
, _descriptor_set_pool(device.create_descriptor_pool(256, {vk::DescriptorType::eCombinedImageSampler}))
, _descriptor_set_pool(*device.vk_device(), 256, {vk::DescriptorType::eCombinedImageSampler})
{
}
......
......@@ -83,7 +83,7 @@ namespace mirrage::renderer {
auto pcs = vk::PushConstantRange{vk::ShaderStageFlagBits::eCompute, 0, sizeof(Push_constants)};
return renderer.device().vk_device()->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo{{}, dsl.size(), dsl.data(), 1, &pcs});
vk::PipelineLayoutCreateInfo{{}, gsl::narrow<std::uint32_t>(dsl.size()), dsl.data(), 1, &pcs});
}
auto build_compute_pipeline(graphic::Device& device,
asset::Asset_manager& assets,
......@@ -106,7 +106,7 @@ namespace mirrage::renderer {
reinterpret_cast<float&>(spec_data[3 * 32]) = std::log(histogram_max);
auto spec_info = vk::SpecializationInfo{
spec_entries.size(), spec_entries.data(), spec_data.size(), spec_data.data()};
gsl::narrow<std::uint32_t>(spec_entries.size()), spec_entries.data(), gsl::narrow<std::uint32_t>(spec_data.size()), spec_data.data()};
auto stage = vk::PipelineShaderStageCreateInfo{
{}, vk::ShaderStageFlagBits::eCompute, **module, "main", &spec_info};
......
......@@ -82,7 +82,7 @@ namespace mirrage::util {
{
add("set." + name + " <value> | Sets the value of the property", std::forward<FS>(setter));
add("get." + name + " | Gets the value of the property",
[name = name, getter = std::forward<FG>(getter)] {
[name = name, getter = std::forward<FG>(getter), this] {
LOG(plog::info) << "Value of " << name << ": " << util::to_string(getter());
});
}
......
......@@ -184,7 +184,10 @@ namespace mirrage::util {
value_type& operator*() noexcept { return *get(); }
value_type* operator->() noexcept { return get(); }
value_type* get() noexcept;
const value_type& operator*() const noexcept { return *get(); }
const value_type* operator->() const noexcept { return get(); }
const value_type* get() const noexcept;
value_type* get() noexcept;
auto operator++() -> pool_iterator&;
......
......@@ -162,6 +162,9 @@ namespace mirrage::util {
util::max(static_cast<std::size_t>(min_chunks), util::min(_chunks.size(), std::size_t(1))));
}
namespace detail {
}
MIRRAGE_POOL_HEADER
template <typename F, class... Args>
auto MIRRAGE_POOL::emplace(F&& relocation, Args&&... args) -> std::tuple<T&, IndexType>
......@@ -182,20 +185,20 @@ namespace mirrage::util {
auto i = _used_elements;
if constexpr(ValueTraits::sorted) {
auto sort_key = [&] {
using first_arg_type =
std::remove_cv_t<std::remove_reference_t<std::tuple_element_t<0, std::tuple<Args...>>>>;
auto sort_key = decltype(std::declval<T>().*(ValueTraits::sort_key)){};
if constexpr(sizeof...(args) == 1 && std::is_same_v<T, first_arg_type>) {
// copy/move construction
auto&& first_arg = std::get<0>(std::forward_as_tuple(args...));
return first_arg.*(ValueTraits::sort_key);
using first_arg_type =
std::remove_cv_t<std::remove_reference_t<std::tuple_element_t<0, std::tuple<Args...>>>>;
} else {
// normal constructor call
return std::get<ValueTraits::sort_key_constructor_idx>(std::tie(args...));
}
}();
if constexpr(sizeof...(args) == 1 && std::is_same_v<T, first_arg_type>) {
// copy/move construction
auto&& first_arg = std::get<0>(std::forward_as_tuple(args...));
sort_key = first_arg.*(ValueTraits::sort_key);
} else {
// normal constructor call
sort_key = std::get<ValueTraits::sort_key_constructor_idx>(std::tie(args...));
}
// find insert position
......@@ -209,28 +212,29 @@ namespace mirrage::util {
i = iter.physical_index();
// find first free slot
auto first_empty = [&] {
if constexpr(max_free_slots > 0) {
auto min = std::lower_bound(_freelist.begin(), _freelist.end(), i);
if(min != _freelist.end()) {
auto min_v = *min;
_freelist.erase(min);
return min_v;
}
auto first_empty = util::maybe<IndexType>{};
if constexpr(max_free_slots > 0) {
auto min = std::lower_bound(_freelist.begin(), _freelist.end(), i);
if(min != _freelist.end()) {
auto min_v = *min;
_freelist.erase(min);
first_empty = min_v;
}
}
if(first_empty.is_nothing()) {
// create new slot if required
addr(_used_elements);
_used_elements++;
first_empty = _used_elements - 1;
}
return _used_elements - 1;
}();
MIRRAGE_INVARIANT(first_empty >= i, "first_empty (" << first_empty << ") < i (" << i << ")");
MIRRAGE_INVARIANT(first_empty.get_or_throw() >= i,
"first_empty (" << first_empty.get_or_throw() << ") < i (" << i << ")");
if(first_empty > i) {
if(first_empty.get_or_throw() > i) {
// shift to make room for new element
_move_elements(i, i + 1, relocation, first_empty - i, true);
_move_elements(i, i + 1, relocation, first_empty.get_or_throw() - i, true);
iter->~T();
}
......@@ -453,6 +457,13 @@ namespace mirrage::util {
return std::launder(_element_iter);
}
template <class Pool>
auto pool_iterator<Pool>::get() const noexcept -> const value_type*
{
MIRRAGE_INVARIANT(_element_iter, "access to invalid pool_iterator");
return std::launder(_element_iter);
}
template <class Pool>
auto pool_iterator<Pool>::operator++() -> pool_iterator&
{
......
......@@ -28,17 +28,17 @@ namespace mirrage::util {
namespace details {
struct Type_uid_gen_base {
protected:
static auto next_uid() noexcept
static type_uid_t next_uid() noexcept
{
static auto idc = type_uid_t(1);
static type_uid_t idc = type_uid_t(1);
return idc++;
}
};
template <typename T>
struct Type_uid_gen : Type_uid_gen_base {
static auto uid() noexcept
static type_uid_t uid() noexcept
{
static auto i = next_uid();
static type_uid_t i = next_uid();
return i;
}
};
......@@ -47,7 +47,7 @@ namespace mirrage::util {
template <class T>
auto type_uid_of()
{
return details::Type_uid_gen<std::decay_t<std::remove_pointer_t<std::decay_t<T>>>>::uid();
return details::Type_uid_gen<T>::uid();
}
template <>
inline constexpr auto type_uid_of<void>()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment