Commit 1c09700c authored by Florian Oetke's avatar Florian Oetke
Browse files

fixed some conversion/ signed-unsigned warnings

parent b10a8d6d
......@@ -5,8 +5,6 @@
#include "global_uniforms.glsl"
#include "normal_encoding.glsl"
layout(early_fragment_tests) in;
layout(location = 0) in vec3 world_pos;
layout(location = 1) in vec3 view_pos;
layout(location = 2) in vec3 normal;
......@@ -30,6 +28,9 @@ layout(push_constant) uniform Per_model_uniforms {
void main() {
vec4 albedo = texture(albedo_sampler, tex_coords);
if(albedo.a < 0.1)
discard;
depth_out = vec4(-view_pos.z / global_uniforms.proj_planes.y, 0,0,1);
albedo_mat_id = vec4(albedo.rgb, 1.0);
mat_data = vec4(encode_normal(normalize(normal)), 0.0, 0.0);
......
......@@ -31,6 +31,7 @@ endif()
add_definitions(-DHPC_HISTOGRAM_DEBUG_VIEW)
add_definitions(-DGSL_TERMINATE_ON_CONTRACT_VIOLATION)
if(MIRRAGE_BUILD_DEMO)
......
......@@ -96,8 +96,8 @@ namespace mirrage::systems {
{
auto frames = std::vector<Frame_data>();
frames.reserve(seq.frames());
for(auto i : util::range(seq.frames())) {
frames.reserve(std::size_t(seq.frames()));
for(auto i : util::range(std::size_t(seq.frames()))) {
auto& frame = frames.emplace_back();
frame.length = seq._frame_lengths.at(i) / second;
......@@ -178,10 +178,10 @@ namespace mirrage::systems {
_current_position = static_cast<float>(std::fmod(_current_position, _playing->frames()));
}
auto reached_end = _current_position >= _end_position && !_loop;
auto reached_end = int(_current_position) >= _end_position && !_loop;
if(reached_end) {
_current_position = _end_position;
_current_position = float(_end_position);
}
_playing->apply([&](const auto& entity_uid,
......@@ -232,7 +232,7 @@ namespace mirrage::systems {
_update_lookup_table();
_playback_speed = speed;
_current_position = begin;
_current_position = float(begin);
_end_position = end >= 0 ? end : _playing->frames();
_loop = false;
}
......
......@@ -46,7 +46,7 @@ namespace mirrage::systems {
auto frame_length(int frame) const noexcept { return _frame_lengths[frame % _frame_lengths.size()]; }
auto frames() const noexcept { return _frame_lengths.size(); }
auto frames() const noexcept { return std::int32_t(_frame_lengths.size()); }
// F = void(Str_id, vector<vec3>, vector<quat>, vector<Rgba>)
template <typename F>
......
......@@ -214,7 +214,7 @@ namespace mirrage {
if(preset_id <= 0)
return;
const Preset& p = presets[preset_id - 1];
const Preset& p = presets[std::size_t(preset_id - 1)];
_camera.get<Transform_comp>().process(
[&](auto& transform) { transform.position = p.camera_position; });
......@@ -235,7 +235,7 @@ namespace mirrage {
_update_sun_position();
}
void Test_screen::_on_enter(util::maybe<Screen&> prev)
void Test_screen::_on_enter(util::maybe<Screen&>)
{
_meta_system.shrink_to_fit();
......@@ -243,7 +243,7 @@ namespace mirrage {
_mailbox.enable();
}
void Test_screen::_on_leave(util::maybe<Screen&> next)
void Test_screen::_on_leave(util::maybe<Screen&>)
{
_mailbox.disable();
_engine.input().capture_mouse(false);
......@@ -372,13 +372,13 @@ namespace mirrage {
nk_layout_row_dynamic(ctx, 14, 1);
auto elevation = nk_propertyf(ctx, "Elevation", 0.f, _sun_elevation, 1.f, 0.05f, 0.001f);
if(elevation != _sun_elevation) {
if(std::abs(elevation - _sun_elevation) > 0.000001f) {
_sun_elevation = elevation;
_set_preset(0);
}
auto azimuth = nk_propertyf(ctx, "Azimuth", -2.f, _sun_azimuth, 2.f, 0.05f, 0.001f);
if(azimuth != _sun_azimuth) {
if(std::abs(azimuth - _sun_azimuth) > 0.000001f) {
_sun_azimuth = azimuth;
_set_preset(0);
}
......@@ -394,7 +394,7 @@ namespace mirrage {
auto new_temp = nk_propertyf(
ctx, "Color", 500.f, _sun_color_temperature, 20000.f, 500.f, 50.f);
if(new_temp != _sun_color_temperature) {
if(std::abs(new_temp - _sun_color_temperature) > 0.000001f) {
light.temperature(_sun_color_temperature = new_temp);
_set_preset(0);
}
......@@ -503,14 +503,18 @@ namespace mirrage {
}
namespace {
auto to_fixed_str(double num, int digits)
template <typename T>
auto to_fixed_str(T num, int digits)
{
auto ss = std::stringstream{};
ss << std::fixed << std::setprecision(digits) << num;
return ss.str();
}
auto pad_left(const std::string& str, int padding) { return std::string(padding, ' ') + str; }
auto pad_left(const std::string& str, int padding)
{
return std::string(std::size_t(padding), ' ') + str;
}
template <std::size_t N, typename Container, typename Comp>
auto top_n(const Container& container, Comp&& less)
......@@ -642,9 +646,8 @@ namespace mirrage {
nk_label(ctx, "Luminance", NK_TEXT_CENTERED);
auto log_lum_range = std::log(_meta_system.renderer().gbuffer().max_luminance)
- std::log(_meta_system.renderer().gbuffer().min_luminance);
auto log_lum =
static_cast<double>(_last_selected_histogram) / (histogram.size() - 1) * log_lum_range
+ std::log(_meta_system.renderer().gbuffer().min_luminance);
auto log_lum = float(_last_selected_histogram) / float(histogram.size() - 1) * log_lum_range
+ std::log(_meta_system.renderer().gbuffer().min_luminance);
auto lum = std::exp(log_lum);
nk_label(ctx, to_fixed_str(lum, 5).c_str(), NK_TEXT_CENTERED);
......
......@@ -11,6 +11,7 @@
#include <mirrage/utils/log.hpp>
#include <concurrentqueue.h>
#include <gsl/gsl>
#include <cstdint>
#include <string>
......@@ -21,37 +22,32 @@ namespace mirrage::ecs {
class Entity_manager;
using Entity_id = int32_t;
using Entity_id = uint32_t;
class Entity_handle {
public:
using packed_t = uint32_t;
static constexpr uint8_t free_rev = 0b10000; // marks revisions as free,
// is cut off when assigned to Entity_handle::revision
constexpr Entity_handle() : _id(0), _revision(0) {}
constexpr Entity_handle(Entity_id id, uint8_t revision) : _id(id), _revision(revision) {}
constexpr Entity_handle() : _data(0) {}
constexpr Entity_handle(Entity_id id, uint8_t revision) : _data(id << 4 | (revision & 0xfu)) {}
constexpr explicit operator bool() const noexcept { return _id != 0; }
constexpr explicit operator bool() const noexcept { return _data != 0; }
constexpr Entity_id id() const noexcept { return _id; }
constexpr void id(Entity_id id) noexcept { _id = id; }
constexpr Entity_id id() const noexcept { return _data >> 4; }
constexpr void id(Entity_id id) noexcept { _data = id << 4 | revision(); }
constexpr uint8_t revision() const noexcept { return _revision; }
constexpr void revision(uint8_t revision) noexcept { _revision = revision; }
void increment_revision() noexcept { _revision++; }
constexpr uint8_t revision() const noexcept { return _data & 0xf; }
constexpr void revision(uint8_t revision) noexcept { _data = id() << 4 | (revision & 0xfu); }
void increment_revision() noexcept { _data = (_data & (~0xfu)) | ((_data + 1) & 0xfu); }
constexpr packed_t pack() const noexcept
{
return static_cast<packed_t>(_id) << 4 | static_cast<packed_t>(_revision);
}
static constexpr Entity_handle unpack(packed_t d) noexcept
{
return Entity_handle{static_cast<int32_t>(d >> 4), static_cast<uint8_t>(d & 0b1111)};
}
constexpr packed_t pack() const noexcept { return _data; }
static constexpr Entity_handle unpack(packed_t d) noexcept { return Entity_handle{d}; }
private:
int32_t _id : 28;
uint8_t _revision : 4;
uint32_t _data;
constexpr Entity_handle(uint32_t data) : _data(data) {}
};
constexpr inline bool operator==(const Entity_handle& lhs, const Entity_handle& rhs) noexcept
......
......@@ -36,7 +36,7 @@ namespace mirrage::ecs {
return;
if(static_cast<Entity_id>(_table.size()) < owner) {
auto capacity = static_cast<std::size_t>(std::max(owner, 64));
auto capacity = std::max<std::size_t>(owner, 64u);
_table.resize(capacity * 2, -1);
}
......
......@@ -38,33 +38,33 @@ namespace mirrage::graphic {
DescriptorSet(Descriptor_pool*,
Descriptor_pool_chunk_index,
vk::DescriptorSet,
std::uint32_t reserved_bindings);
std::int32_t reserved_bindings);
Descriptor_pool* _pool = nullptr;
Descriptor_pool_chunk_index _chunk;
vk::DescriptorSet _set;
std::uint32_t _reserved_bindings;
std::int32_t _reserved_bindings;
};
class Descriptor_pool {
public:
// Allocates a descriptor from the pool
// \param bindings: The estimated number of bindings required by the layout
auto create_descriptor(vk::DescriptorSetLayout, std::uint32_t bindings) -> DescriptorSet;
auto create_descriptor(vk::DescriptorSetLayout, std::int32_t bindings) -> DescriptorSet;
private:
friend class Device;
friend class DescriptorSet;
vk::Device _device;
std::uint32_t _chunk_size;
std::int32_t _chunk_size;
std::vector<vk::DescriptorPoolSize> _pool_sizes;
std::vector<vk::UniqueDescriptorPool> _chunks;
std::vector<std::uint32_t> _chunks_free_count;
std::vector<std::int32_t> _chunks_free_count;
mutable std::mutex _mutex;
Descriptor_pool(vk::Device device,
std::uint32_t chunk_size,
std::int32_t chunk_size,
std::initializer_list<vk::DescriptorType> types);
Descriptor_pool(const Descriptor_pool&) = delete;
......@@ -75,14 +75,14 @@ namespace mirrage::graphic {
auto _create_descriptor_pool() -> vk::DescriptorPool;
void _free_descriptor_set(vk::DescriptorSet& set,
Descriptor_pool_chunk_index chunk,
std::uint32_t reserved_bindings);
std::int32_t reserved_bindings);
};
class Image_descriptor_set_layout {
public:
Image_descriptor_set_layout(graphic::Device& device,
vk::Sampler sampler,
std::uint32_t image_number,
std::int32_t image_number,
vk::ShaderStageFlags = vk::ShaderStageFlagBits::eFragment);
auto layout() const noexcept { return *_layout; }
......@@ -95,7 +95,7 @@ namespace mirrage::graphic {
private:
graphic::Device& _device;
vk::Sampler _sampler;
std::uint32_t _image_number;
std::int32_t _image_number;
vk::UniqueDescriptorSetLayout _layout;
};
......
......@@ -61,7 +61,7 @@ namespace mirrage::graphic {
bool resetable = true,
bool short_lived = false) -> Command_buffer_pool;
auto create_descriptor_pool(std::uint32_t chunk_size, std::initializer_list<vk::DescriptorType> types)
auto create_descriptor_pool(std::int32_t chunk_size, std::initializer_list<vk::DescriptorType> types)
-> Descriptor_pool;
auto create_descriptor_set_layout(gsl::span<const vk::DescriptorSetLayoutBinding> bindings)
......@@ -80,13 +80,13 @@ namespace mirrage::graphic {
auto create_image_view(vk::Image,
vk::Format,
std::uint32_t base_mipmap,
std::int32_t base_mipmap,
std::uint32_t mipmap_levels,
vk::ImageAspectFlags = vk::ImageAspectFlagBits::eColor,
vk::ImageViewType = vk::ImageViewType::e2D,
vk::ComponentMapping = {}) -> vk::UniqueImageView;
auto create_sampler(std::uint32_t max_mip_levels,
auto create_sampler(std::int32_t max_mip_levels,
vk::SamplerAddressMode = vk::SamplerAddressMode::eRepeat,
vk::BorderColor = vk::BorderColor::eIntOpaqueBlack,
vk::Filter = vk::Filter::eLinear,
......
......@@ -81,8 +81,8 @@ namespace mirrage::graphic {
bool dedicated_alloc_supported);
~Device_memory_allocator();
auto alloc(std::size_t size,
std::size_t alignment,
auto alloc(std::uint32_t size,
std::uint32_t alignment,
std::uint32_t type_mask,
bool host_visible,
Memory_lifetime lifetime = Memory_lifetime::normal) -> util::maybe<Device_memory>;
......
......@@ -39,10 +39,15 @@ namespace mirrage::graphic {
gsl::span<const std::uint32_t> indices)
: Mesh(device,
owner_qfamily,
vertices.size_bytes(),
indices.size_bytes(),
[&](char* dest) { (void) std::memcmp(dest, vertices.data(), vertices.size_bytes()); },
[&](char* dest) { (void) std::memcmp(dest, indices.data(), indices.size_bytes()); })
gsl::narrow<std::uint32_t>(vertices.size_bytes()),
gsl::narrow<std::uint32_t>(indices.size_bytes()),
[&](char* dest) {
(void) std::memcmp(
dest, vertices.data(), gsl::narrow<std::size_t>(vertices.size_bytes()));
},
[&](char* dest) {
(void) std::memcmp(dest, indices.data(), gsl::narrow<std::size_t>(indices.size_bytes()));
})
{
}
......@@ -63,6 +68,6 @@ namespace mirrage::graphic {
private:
Static_buffer _buffer;
vk::DeviceSize _index_offset;
std::size_t _indices = 0;
std::uint32_t _indices = 0;
};
} // namespace mirrage::graphic
......@@ -41,7 +41,10 @@ namespace mirrage::graphic {
// read-only interface
auto& name() const noexcept { return _name; }
auto time_ms() const noexcept { return _time_ms_index < 0 ? 0 : _time_ms[_time_ms_index]; }
auto time_ms() const noexcept
{
return _time_ms_index < 0 ? 0 : _time_ms.at(std::size_t(_time_ms_index));
}
auto time_avg_ms() const noexcept { return _time_avg_ms; }
auto time_min_ms() const noexcept { return _time_min_ms; }
auto time_max_ms() const noexcept { return _time_max_ms; }
......@@ -111,7 +114,7 @@ namespace mirrage::graphic {
};
public:
explicit Profiler(Device&, std::size_t max_elements = 32);
explicit Profiler(Device&, std::uint32_t max_elements = 32);
void enable() noexcept { _active_requested = true; }
void disable() noexcept { _active_requested = false; }
......
......@@ -73,7 +73,7 @@ namespace mirrage::graphic {
void vertex(int binding, bool per_instance_data, Member&&... members)
{
if(binding < 0)
binding = vertex_bindings.size();
binding = gsl::narrow<int>(vertex_bindings.size());
vertex_bindings.emplace_back(binding,
sizeof(T),
......
......@@ -17,12 +17,12 @@ namespace mirrage::graphic {
class Streamed_buffer {
public:
Streamed_buffer(Device&, std::size_t capacity, vk::BufferUsageFlags usage);
Streamed_buffer(Device&, std::int32_t capacity, vk::BufferUsageFlags usage);
void update(vk::DeviceSize dest_offset, gsl::span<const char> data);
void update(std::int32_t dest_offset, gsl::span<const char> data);
template <class T>
void update_objs(vk::DeviceSize dest_offset, gsl::span<T> obj)
void update_objs(std::int32_t dest_offset, gsl::span<T> obj)
{
static_assert(std::is_standard_layout<T>::value, "");
update(dest_offset,
......@@ -46,9 +46,9 @@ namespace mirrage::graphic {
char* data;
};
std::size_t _capacity;
std::int32_t _capacity;
std::vector<Buffer_entry> _buffers;
std::size_t _current_buffer_idx = 0;
std::int32_t _current_buffer_idx = 0;
util::maybe<Backed_buffer&> _read_buffer;
};
} // namespace mirrage::graphic
......@@ -17,16 +17,11 @@ namespace mirrage::graphic {
class Device;
namespace detail {
auto clamp_mip_levels(std::uint32_t width, std::uint32_t height, std::uint32_t mipmaps)
-> std::uint32_t;
auto clamp_mip_levels(std::int32_t width, std::int32_t height, std::int32_t mipmaps) -> std::int32_t;
class Base_texture {
public:
Base_texture(Base_texture&& rhs) noexcept
: _image(std::move(rhs._image)), _image_view(std::move(rhs._image_view))
{
}
Base_texture(Base_texture&& rhs) noexcept;
Base_texture& operator=(Base_texture&& rhs) noexcept
{
_image = std::move(rhs._image);
......@@ -42,21 +37,15 @@ namespace mirrage::graphic {
auto depth() const noexcept { return _image.depth(); }
auto layers() const noexcept { return _image.layers(); }
auto width(std::uint32_t level) const noexcept
{
return this->width() / (std::uint32_t(1) << level);
}
auto height(std::uint32_t level) const noexcept
{
return this->height() / (std::uint32_t(1) << level);
}
auto width(std::int32_t level) const noexcept { return this->width() / (1 << level); }
auto height(std::int32_t level) const noexcept { return this->height() / (1 << level); }
protected:
// construct as render target
Base_texture(Device&,
Image_type type,
Image_dimensions,
std::uint32_t mip_levels,
std::int32_t mip_levels,
vk::Format,
vk::ImageUsageFlags,
vk::ImageAspectFlags,
......@@ -81,9 +70,9 @@ namespace mirrage::graphic {
vk::UniqueImageView _image_view;
};
extern auto format_from_channels(Device& device, std::uint32_t channels, bool srgb) -> vk::Format;
extern auto format_from_channels(Device& device, std::int32_t channels, bool srgb) -> vk::Format;
extern auto build_mip_views(Device& device,
std::uint32_t mip_levels,
std::int32_t mip_levels,
vk::Image image,
vk::Format format,
vk::ImageAspectFlags aspects) -> std::vector<vk::UniqueImageView>;
......@@ -108,7 +97,7 @@ namespace mirrage::graphic {
Texture(Device& device,
Image_dimensions_t<Type> dim,
bool generate_mipmaps,
std::uint32_t channels,
std::int32_t channels,
bool srgb,
gsl::span<const std::uint8_t> data,
std::uint32_t owner_qfamily)
......@@ -130,7 +119,7 @@ namespace mirrage::graphic {
public:
Render_target(Device& device,
Image_dimensions_t<Type> dim,
std::uint32_t mip_levels,
std::int32_t mip_levels,
vk::Format format,
vk::ImageUsageFlags usage,
vk::ImageAspectFlags aspects)
......@@ -154,11 +143,8 @@ namespace mirrage::graphic {
using Texture<Type>::height;
using Texture<Type>::view;
auto view(std::uint32_t level) const noexcept { return *_single_mip_level_views.at(level); }
auto mip_levels() const noexcept
{
return gsl::narrow<std::uint32_t>(_single_mip_level_views.size());
}
auto view(std::int32_t level) const noexcept { return *_single_mip_level_views.at(level); }
auto mip_levels() const noexcept { return gsl::narrow<std::int32_t>(_single_mip_level_views.size()); }
private:
std::vector<vk::UniqueImageView> _single_mip_level_views;
......
......@@ -45,7 +45,7 @@ namespace mirrage::graphic {
class Static_image {
public:
Static_image(Backed_image image,
std::uint32_t mip_count,
std::int32_t mip_count,
bool generate_mips,
Image_dimensions dimensions)
: _image(std::move(image))
......@@ -56,7 +56,7 @@ namespace mirrage::graphic {
{
}
Static_image(Backed_image image,
std::uint32_t mip_count,
std::int32_t mip_count,
bool generate_mips,
Image_dimensions dimensions,
async::shared_task<void> transfer_task)
......@@ -82,7 +82,7 @@ namespace mirrage::graphic {
private:
Backed_image _image;
std::uint32_t _mip_count;
std::int32_t _mip_count;
bool _generate_mips;
Image_dimensions _dimensions;
async::shared_task<void> _transfer_task;
......@@ -91,7 +91,7 @@ namespace mirrage::graphic {
class Dynamic_buffer {
public:
Dynamic_buffer(Backed_buffer buffer,
std::size_t capacity,
std::int32_t capacity,
vk::PipelineStageFlags earliest_usage,
vk::AccessFlags earliest_usage_access,
vk::PipelineStageFlags latest_usage,
......@@ -118,7 +118,7 @@ namespace mirrage::graphic {
update(cb, 0, gsl::span<const char>(reinterpret_cast<const char*>(obj.data()), obj.size_bytes()));
}
void update(const Command_buffer& cb, vk::DeviceSize dstOffset, gsl::span<const char> data);
void update(const Command_buffer& cb, std::int32_t dstOffset, gsl::span<const char> data);
/// F = void(void(tuple<vk::DiviceOffset, gsl::span<const char>))
template <class F>
......@@ -134,14 +134,14 @@ namespace mirrage::graphic {
private:
Backed_buffer _buffer;
std::size_t _capacity;
std::int32_t _capacity;
vk::PipelineStageFlags _earliest_usage;
vk::AccessFlags _earliest_usage_access;
vk::PipelineStageFlags _latest_usage;
vk::AccessFlags _latest_usage_access;
void _pre_update(const Command_buffer& cb);
void _do_update(const Command_buffer& cb, vk::DeviceSize dstOffset, gsl::span<const char> data);
void _do_update(const Command_buffer& cb, std::int32_t dstOffset, gsl::span<const char> data);
void _post_update(const Command_buffer& cb);
};
......@@ -183,8 +183,8 @@ namespace mirrage::graphic {
std::uint32_t owner,
const Image_dimensions&,
vk::Format,
std::uint32_t mip_levels,
std::uint32_t size,
std::int32_t mip_levels,
std::int32_t size,
std::function<void(char*)> write_data,
bool dedicated = false) -> Static_image;
......@@ -201,9 +201,9 @@ namespace mirrage::graphic {
std::initializer_list<gsl::span<const char>> data,
bool dedicated = false) -> Static_buffer
{
auto size = std::uint32_t(0);