Commit dd6afb64 authored by Lotrado's avatar Lotrado
Browse files

Added gsl::narrow calls where MSVC warned about numeric conversions that could...

Added gsl::narrow calls where MSVC warned about numeric conversions that could potentially lose information.
parent 59ae37db
......@@ -74,7 +74,7 @@ namespace mirrage {
auto new_idx = nk_combo(ctx,
animations_strs.data(),
animations_strs.size(),
gsl::narrow<int>(animations_strs.size()),
int(curr_idx),
14,
nk_vec2(100.f, 200));
......
......@@ -354,7 +354,7 @@ namespace mirrage {
"Cornell Box"}};
_set_preset(nk_combo(ctx,
preset_options.data(),
preset_options.size(),
gsl::narrow<int>(preset_options.size()),
_selected_preset,
14,
nk_vec2(100.f, 200)));
......
......@@ -76,7 +76,7 @@ namespace mirrage::graphic {
binding = gsl::narrow<int>(vertex_bindings.size());
vertex_bindings.emplace_back(binding,
sizeof(T),
gsl::narrow<uint32_t>(sizeof(T)),
per_instance_data ? vk::VertexInputRate::eInstance
: vk::VertexInputRate::eVertex);
......@@ -384,91 +384,91 @@ namespace mirrage::graphic {
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32Sfloat, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32Sfloat, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<std::int32_t>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32Sint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32Sint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<std::uint32_t>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32Uint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32Uint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::vec2>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32Sfloat, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32Sfloat, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::ivec2>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32Sint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32Sint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::uvec2>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32Uint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32Uint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::vec3>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32Sfloat, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32Sfloat, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::ivec3>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32Sint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32Sint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::uvec3>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32Uint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32Uint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::vec4>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32A32Sfloat, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32A32Sfloat, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::ivec4>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32A32Sint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32A32Sint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<glm::uvec4>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32A32Uint, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR32G32B32A32Uint, gsl::narrow<uint32_t>(offset));
}
template <>
inline void Pipeline_description::add_vertex_attributes<std::uint8_t (&)[4]>(int binding,
int location,
std::size_t offset)
{
vertex_attributes.emplace_back(location, binding, vk::Format::eR8G8B8A8Unorm, offset);
vertex_attributes.emplace_back(location, binding, vk::Format::eR8G8B8A8Unorm, gsl::narrow<uint32_t>(offset));
}
} // namespace mirrage::graphic
......
......@@ -632,7 +632,7 @@ namespace mirrage::graphic {
<< ". Collapsed with previous queue!";
}
queue_mapping.emplace(tag, std::make_tuple(family, std::get<1>(entry).size() - 1));
queue_mapping.emplace(tag, std::make_tuple(family, gsl::narrow<uint32_t>(std::get<1>(entry).size() - 1)));
}
auto used_queues = std::vector<vk::DeviceQueueCreateInfo>{};
......
......@@ -81,7 +81,7 @@ namespace mirrage::graphic {
auto ret = vkAllocateDescriptorSets(_device, &c_alloc_info, &desc_set);
if(ret == VK_SUCCESS) {
return DescriptorSet(this, pool_idx, desc_set, bindings);
return DescriptorSet(this, gsl::narrow<Descriptor_pool_chunk_index>(pool_idx), desc_set, bindings);
} else {
LOG(plog::warning) << "Allocated a new descriptorSetPool (shouldn't happen too often!).";
*free_iter = 0;
......@@ -188,7 +188,7 @@ namespace mirrage::graphic {
desc_writes.reserve(images.size());
for(auto& desc_image : desc_images) {
desc_writes.emplace_back(set,
desc_writes.size(),
gsl::narrow<uint32_t>(desc_writes.size()),
0,
1,
vk::DescriptorType::eCombinedImageSampler,
......
......@@ -392,8 +392,8 @@ namespace mirrage::graphic {
vk::DependencyFlags flags) -> Render_pass_builder&
{
auto src_id = src.process(VK_SUBPASS_EXTERNAL, [](auto& s) { return s._index; });
auto dst_id = dst.process(VK_SUBPASS_EXTERNAL, [](auto& s) { return s._index; });
auto src_id = src.process(VK_SUBPASS_EXTERNAL, [](auto& s) { return gsl::narrow<uint32_t>(s._index); });
auto dst_id = dst.process(VK_SUBPASS_EXTERNAL, [](auto& s) { return gsl::narrow<uint32_t>(s._index); });
_dependencies.emplace_back(
src_id, dst_id, srcStageMask, dstStageMask, srcAccessMask, dstAccessMask, flags);
......
......@@ -153,7 +153,7 @@ namespace mirrage::gui {
"debug_console",
nk_rect(50, 0, float(width), float(_show_suggestions ? height + 14 * 5 : height)),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_DYNAMIC)) {
nk_layout_row_dynamic(ctx, log_height + 15, 1);
nk_layout_row_dynamic(ctx, gsl::narrow<float>(log_height + 15), 1);
auto max_y_scroll = std::uint32_t(
util::max(log_height, msg_height * debug_console_appender()._messages.size())
......
......@@ -339,7 +339,7 @@ namespace mirrage::input {
if(SDL_IsGameController(joystick_id)) {
SDL_GameController* controller = SDL_GameControllerOpen(joystick_id);
if(controller) {
_gamepads.emplace_back(std::make_unique<Gamepad>(_gamepads.size() + 1, controller, *_mapper));
_gamepads.emplace_back(std::make_unique<Gamepad>(gsl::narrow<Input_source>(_gamepads.size() + 1), controller, *_mapper));
_mailbox.send<Source_added>(Input_source(_gamepads.size()));
} else {
std::cerr << "Could not open gamecontroller " << joystick_id << ": " << SDL_GetError()
......
......@@ -102,14 +102,14 @@ namespace mirrage::renderer {
#endif
constexpr auto rows = std::array<float, 5>{{0.4f, 0.15f, 0.15f, 0.15f, 0.15f}};
nk_layout_row(ctx, NK_DYNAMIC, 25, rows.size(), rows.data());
nk_layout_row(ctx, NK_DYNAMIC, 25, gsl::narrow<int>(rows.size()), rows.data());
nk_label(ctx, "RenderPass", NK_TEXT_CENTERED);
nk_label(ctx, "Curr (ms)", NK_TEXT_CENTERED);
nk_label(ctx, "Min (ms)", NK_TEXT_CENTERED);
nk_label(ctx, "Avg (ms)", NK_TEXT_CENTERED);
nk_label(ctx, "Max (ms)", NK_TEXT_CENTERED);
nk_layout_row(ctx, NK_DYNAMIC, 10, rows.size(), rows.data());
nk_layout_row(ctx, NK_DYNAMIC, 10, gsl::narrow<int>(rows.size()), rows.data());
auto print_entry = [&](auto&& printer,
......
......@@ -149,7 +149,7 @@ namespace mirrage::renderer {
nullptr,
&buffer_info};
device().vk_device()->updateDescriptorSets(desc_writes.size(), desc_writes.data(), 0, nullptr);
device().vk_device()->updateDescriptorSets(gsl::narrow<uint32_t>(desc_writes.size()), desc_writes.data(), 0, nullptr);
}
void Deferred_renderer::update(util::Time dt)
......
......@@ -70,7 +70,7 @@ namespace mirrage::renderer {
desc_images.data(),
nullptr};
device.vk_device()->updateDescriptorSets(desc_writes.size(), desc_writes.data(), 0, nullptr);
device.vk_device()->updateDescriptorSets(gsl::narrow<uint32_t>(desc_writes.size()), desc_writes.data(), 0, nullptr);
}
void Material::bind(graphic::Render_pass& pass) const
......
......@@ -134,7 +134,7 @@ namespace mirrage::renderer {
&mat_data_info};
renderer.device().vk_device()->updateDescriptorSets(
desc_writes.size(), desc_writes.data(), 0, nullptr);
gsl::narrow<uint32_t>(desc_writes.size()), desc_writes.data(), 0, nullptr);
}
void Deferred_lighting_subpass::configure_pipeline(Deferred_renderer& renderer,
......@@ -198,7 +198,7 @@ namespace mirrage::renderer {
dpc.light_data.g = dir.x / dir_len;
dpc.light_data.b = dir.y / dir_len;
dpc.light_data.a = dir.z / dir_len;
dpc.light_data2.r = _gbuffer.shadowmaps ? light_data.shadowmap_id() : -1;
dpc.light_data2.r = gsl::narrow<float>(_gbuffer.shadowmaps ? light_data.shadowmap_id() : -1);
render_pass.push_constant("dpc"_strid, dpc);
......@@ -239,8 +239,8 @@ namespace mirrage::renderer {
dpc.light_data.g = pos.x;
dpc.light_data.b = pos.y;
dpc.light_data.a = pos.z;
dpc.light_data2.g = _gbuffer.colorA.width();
dpc.light_data2.b = _gbuffer.colorA.height();
dpc.light_data2.g = gsl::narrow<float>(_gbuffer.colorA.width());
dpc.light_data2.b = gsl::narrow<float>(_gbuffer.colorA.height());
render_pass.push_constant("dpc"_strid, dpc);
frame.main_command_buffer.drawIndexed(_point_light_mesh.index_count(), 1, 0, 0, 0);
......
......@@ -173,8 +173,8 @@ namespace mirrage::renderer {
_mipmap_gen_renderpass.bind_descriptor_sets(0, descriptor_sets);
auto pcs = Push_constants{};
pcs.arguments.r = i;
pcs.arguments.g = _renderer.gbuffer().mip_levels - 1;
pcs.arguments.r = gsl::narrow<float>(i);
pcs.arguments.g = gsl::narrow<float>(_renderer.gbuffer().mip_levels - 1);
_mipmap_gen_renderpass.push_constant("pcs"_strid, pcs);
......
......@@ -251,7 +251,7 @@ namespace mirrage::renderer {
*renderer.gbuffer().shadowmaps, 2, 0, 1, vk::DescriptorType::eSampler, &depth_sampler};
renderer.device().vk_device()->updateDescriptorSets(
desc_writes.size(), desc_writes.data(), 0, nullptr);
gsl::narrow<uint32_t>(desc_writes.size()), desc_writes.data(), 0, nullptr);
}
void Shadowmapping_pass::update(util::Time) {}
......
......@@ -205,9 +205,9 @@ namespace mirrage::renderer {
std::array<vk::DescriptorSet, 2>{frame.global_uniform_set, *_ssao_descriptor_set};
Push_constants pcs;
pcs.options.x = util::max(1, _renderer.gbuffer().mip_levels - ao_mip_level - 1);
pcs.options.x = gsl::narrow<float>(util::max(1, _renderer.gbuffer().mip_levels - ao_mip_level - 1));
float height = _ao_result_buffer.height();
float height = gsl::narrow<float>(_ao_result_buffer.height());
float v_fov = _renderer.global_uniforms().proj_planes.w;
pcs.options.y = height / (-2.f * glm::tan(v_fov * 0.5f));
......
......@@ -302,7 +302,7 @@ namespace mirrage::renderer {
auto data = reinterpret_cast<std::uint32_t*>(data_addr);
for(auto i : util::range(_last_result_data.size())) {
_last_result_data[i] = data[i];
_last_result_data[i] = gsl::narrow<float>(data[i]);
}
for(auto i : util::range(1u, 2u)) {
......@@ -380,7 +380,7 @@ namespace mirrage::renderer {
auto _ = _renderer.profiler().push("Foveal rescale");
auto foveal_mip_level =
compute_foveal_mip_level(_src.height(), _renderer.global_uniforms().proj_planes.w);
compute_foveal_mip_level(gsl::narrow<float>(_src.height()), _renderer.global_uniforms().proj_planes.w);
_last_max_histogram_size = _src.height(foveal_mip_level) * _src.width(foveal_mip_level);
if(foveal_mip_level > 0) {
graphic::generate_mipmaps(command_buffer,
......@@ -432,7 +432,7 @@ namespace mirrage::renderer {
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eCompute,
*_compute_pipeline_layout,
0,
desc_sets.size(),
gsl::narrow<uint32_t>(desc_sets.size()),
desc_sets.data(),
0,
nullptr);
......@@ -503,7 +503,7 @@ namespace mirrage::renderer {
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eCompute,
*_compute_pipeline_layout,
0,
desc_sets.size(),
gsl::narrow<uint32_t>(desc_sets.size()),
desc_sets.data(),
0,
nullptr);
......
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