Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace gsl::span for std::span (c++20) #7531

Merged
merged 5 commits into from May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitmodules
Expand Up @@ -60,10 +60,6 @@
path = 3rdparty/FAudio
url = https://github.com/FNA-XNA/FAudio.git
ignore = dirty
[submodule "3rdparty/span"]
path = 3rdparty/span
url = https://github.com/tcbrindle/span
ignore = dirty
[submodule "3rdparty/curl"]
path = 3rdparty/curl/curl
url = https://github.com/curl/curl.git
Expand Down
6 changes: 0 additions & 6 deletions 3rdparty/CMakeLists.txt
Expand Up @@ -148,11 +148,6 @@ else()
endif()


# span
add_library(3rdparty_span INTERFACE)
target_include_directories(3rdparty_span INTERFACE span/include)


# stblib
add_library(3rdparty_stblib INTERFACE)
target_include_directories(3rdparty_stblib INTERFACE stblib/include)
Expand Down Expand Up @@ -370,7 +365,6 @@ add_library(3rdparty::hidapi ALIAS 3rdparty_hidapi)
add_library(3rdparty::libpng ALIAS ${LIBPNG_TARGET})
add_library(3rdparty::cereal ALIAS 3rdparty_cereal)
add_library(3rdparty::opengl ALIAS 3rdparty_opengl)
add_library(3rdparty::span ALIAS 3rdparty_span)
add_library(3rdparty::stblib ALIAS 3rdparty_stblib)
add_library(3rdparty::discordRPC ALIAS 3rdparty_discordRPC)
add_library(3rdparty::alsa ALIAS ${ALSA_TARGET})
Expand Down
1 change: 0 additions & 1 deletion 3rdparty/span
Submodule span deleted from 9d7559
2 changes: 0 additions & 2 deletions Utilities/span.h

This file was deleted.

2 changes: 1 addition & 1 deletion buildfiles/msvc/rpcs3_default.props
Expand Up @@ -3,7 +3,7 @@
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>.\;..\;..\3rdparty\asmjit\asmjit\src;..\3rdparty\yaml-cpp\include;..\3rdparty\ffmpeg\include;..\3rdparty\cereal\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);..\3rdparty\span\include;..\3rdparty\libpng\libpng;..\3rdparty\GL;..\3rdparty\stblib\include;..\3rdparty\OpenAL\include;..\3rdparty\pugixml\src;..\3rdparty\hidapi\hidapi;..\3rdparty\Optional;..\3rdparty\xxhash</IncludePath>
<IncludePath>.\;..\;..\3rdparty\asmjit\asmjit\src;..\3rdparty\yaml-cpp\include;..\3rdparty\ffmpeg\include;..\3rdparty\cereal\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);..\3rdparty\libpng\libpng;..\3rdparty\GL;..\3rdparty\stblib\include;..\3rdparty\OpenAL\include;..\3rdparty\pugixml\src;..\3rdparty\hidapi\hidapi;..\3rdparty\Optional;..\3rdparty\xxhash</IncludePath>
<OutDir>$(SolutionDir)lib\$(Configuration)-$(Platform)\</OutDir>
<LibraryPath>$(SolutionDir)lib\$(Configuration)-$(Platform)\;$(UniversalCRT_LibraryPath_x64);$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)tmp\$(ProjectName)-$(Configuration)-$(Platform)\</IntDir>
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Crypto/utils.cpp
Expand Up @@ -9,12 +9,12 @@
#include <stdio.h>
#include <time.h>
#include "Utilities/StrUtil.h"
#include "Utilities/span.h"
#include "Utilities/File.h"

#include <memory>
#include <string>
#include <string_view>
#include <span>

// Auxiliary functions (endian swap, xor).

Expand Down Expand Up @@ -132,7 +132,7 @@ char* extract_file_name(const char* file_path, char real_file_name[CRYPTO_MAX_PA
v.remove_prefix(pos + 1);
}

gsl::span r(real_file_name, CRYPTO_MAX_PATH);
std::span r(real_file_name, CRYPTO_MAX_PATH);
strcpy_trunc(r, v);
return real_file_name;
}
Expand Down
5 changes: 2 additions & 3 deletions rpcs3/Emu/CMakeLists.txt
Expand Up @@ -62,8 +62,7 @@ target_include_directories(rpcs3_emu PUBLIC "${CMAKE_SOURCE_DIR}")

target_link_libraries(rpcs3_emu
PUBLIC
3rdparty::pugixml
3rdparty::span)
3rdparty::pugixml)

if(MSVC)
set_source_files_properties("../../Utilities/JIT.cpp" PROPERTIES COMPILE_FLAGS /GR-)
Expand Down Expand Up @@ -505,7 +504,7 @@ target_link_libraries(rpcs3_emu
3rdparty::vulkan 3rdparty::glew
3rdparty::libusb 3rdparty::wolfssl
PRIVATE
3rdparty::span 3rdparty::xxhash
3rdparty::xxhash
)

if(APPLE)
Expand Down
5 changes: 3 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellGame.cpp
Expand Up @@ -15,10 +15,11 @@

#include "Loader/PSF.h"
#include "Utilities/StrUtil.h"
#include "Utilities/span.h"
#include "util/init_mutex.hpp"
#include "util/asm.hpp"

#include <span>

LOG_CHANNEL(cellGame);

template<>
Expand Down Expand Up @@ -1151,7 +1152,7 @@ error_code cellGameGetParamString(s32 id, vm::ptr<char> buf, u32 bufsize)
cellGame.warning("cellGameGetParamString(): id=%d was not found", id);
}

gsl::span dst(buf.get_ptr(), bufsize);
std::span dst(buf.get_ptr(), bufsize);
strcpy_trunc(dst, value);
return CELL_OK;
}
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/Modules/cellSaveData.cpp
Expand Up @@ -15,11 +15,11 @@

#include "Loader/PSF.h"
#include "Utilities/StrUtil.h"
#include "Utilities/span.h"
#include "Utilities/date_time.h"

#include <mutex>
#include <algorithm>
#include <span>

#include "util/asm.hpp"

Expand Down Expand Up @@ -1654,7 +1654,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
if (dotpos)
{
// Copy file name
gsl::span dst(name, dotpos + 1);
std::span dst(name, dotpos + 1);
strcpy_trunc(dst, file_path);

// Allow multiple '.' even though sysutil_check_name_string does not
Expand Down Expand Up @@ -1691,7 +1691,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
if (file_path.size() > dotpos + 1)
{
// Copy file extension
gsl::span dst(name, file_path.size() - dotpos);
std::span dst(name, file_path.size() - dotpos);
strcpy_trunc(dst, file_path.operator std::string_view().substr(dotpos + 1));

// Allow '_' at start even though sysutil_check_name_string does not
Expand Down
5 changes: 3 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellSysutil.cpp
Expand Up @@ -10,7 +10,8 @@

#include "Utilities/StrUtil.h"
#include "Utilities/lockless.h"
#include "Utilities/span.h"

#include <span>

LOG_CHANNEL(cellSysutil);

Expand Down Expand Up @@ -385,7 +386,7 @@ error_code cellSysutilGetSystemParamString(CellSysutilParamId id, vm::ptr<char>
cellSysutil.error("cellSysutilGetSystemParamString: Unknown ParamId 0x%x", id);
}

gsl::span dst(buf.get_ptr(), copy_size);
std::span dst(buf.get_ptr(), copy_size);
strcpy_trunc(dst, param_str);
return CELL_OK;
}
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_prx.cpp
Expand Up @@ -10,10 +10,10 @@
#include "Emu/Cell/ErrorCodes.h"
#include "Crypto/unedat.h"
#include "Utilities/StrUtil.h"
#include "Utilities/span.h"
#include "sys_fs.h"
#include "sys_process.h"
#include "sys_memory.h"
#include <span>

extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, const std::string&, s64);
extern void ppu_unload_prx(const lv2_prx& prx);
Expand Down Expand Up @@ -805,7 +805,7 @@ error_code _sys_prx_get_module_info(ppu_thread& ppu, u32 id, u64 flags, vm::ptr<
pOpt->info->all_segments_num = ::size32(prx->segs);
if (pOpt->info->filename)
{
gsl::span dst(pOpt->info->filename.get_ptr(), pOpt->info->filename_size);
std::span dst(pOpt->info->filename.get_ptr(), pOpt->info->filename_size);
strcpy_trunc(dst, prx->name);
}

Expand Down
26 changes: 13 additions & 13 deletions rpcs3/Emu/RSX/Common/BufferUtils.cpp
Expand Up @@ -51,13 +51,13 @@ namespace
// FIXME: GSL as_span break build if template parameter is non const with current revision.
// Replace with true as_span when fixed.
template <typename T>
gsl::span<T> as_span_workaround(gsl::span<std::byte> unformated_span)
std::span<T> as_span_workaround(std::span<std::byte> unformated_span)
{
return{ reinterpret_cast<T*>(unformated_span.data()), unformated_span.size_bytes() / sizeof(T) };
}

template <typename T>
gsl::span<T> as_const_span(gsl::span<const std::byte> unformated_span)
std::span<T> as_const_span(std::span<const std::byte> unformated_span)
{
return{ reinterpret_cast<T*>(unformated_span.data()), unformated_span.size_bytes() / sizeof(T) };
}
Expand Down Expand Up @@ -583,7 +583,7 @@ namespace
}
}

void write_vertex_array_data_to_buffer(gsl::span<std::byte> raw_dst_span, gsl::span<const std::byte> src_ptr, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride, u8 dst_stride, bool swap_endianness)
void write_vertex_array_data_to_buffer(std::span<std::byte> raw_dst_span, std::span<const std::byte> src_ptr, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride, u8 dst_stride, bool swap_endianness)
{
ensure((vector_element_count > 0));
const u32 src_read_stride = rsx::get_vertex_type_size_on_host(type, vector_element_count);
Expand Down Expand Up @@ -665,7 +665,7 @@ void write_vertex_array_data_to_buffer(gsl::span<std::byte> raw_dst_span, gsl::s
}
case rsx::vertex_base_type::cmp:
{
gsl::span<u16> dst_span = as_span_workaround<u16>(raw_dst_span);
std::span<u16> dst_span = as_span_workaround<u16>(raw_dst_span);
for (u32 i = 0; i < count; ++i)
{
u32 src_value;
Expand Down Expand Up @@ -782,7 +782,7 @@ namespace

template<typename T>
static
std::tuple<T, T, u32> upload_untouched(gsl::span<to_be_t<const T>> src, gsl::span<T> dst)
std::tuple<T, T, u32> upload_untouched(std::span<to_be_t<const T>> src, std::span<T> dst)
{
T min_index, max_index;
u32 written;
Expand Down Expand Up @@ -955,7 +955,7 @@ namespace

template<typename T>
static
std::tuple<T, T, u32> upload_untouched(gsl::span<to_be_t<const T>> src, gsl::span<T> dst, T restart_index, bool skip_restart)
std::tuple<T, T, u32> upload_untouched(std::span<to_be_t<const T>> src, std::span<T> dst, T restart_index, bool skip_restart)
{
T min_index = index_limit<T>();
T max_index = 0;
Expand Down Expand Up @@ -1015,7 +1015,7 @@ namespace
};

template<typename T>
std::tuple<T, T, u32> upload_untouched(gsl::span<to_be_t<const T>> src, gsl::span<T> dst, rsx::primitive_type draw_mode, bool is_primitive_restart_enabled, u32 primitive_restart_index)
std::tuple<T, T, u32> upload_untouched(std::span<to_be_t<const T>> src, std::span<T> dst, rsx::primitive_type draw_mode, bool is_primitive_restart_enabled, u32 primitive_restart_index)
{
if (!is_primitive_restart_enabled)
{
Expand All @@ -1039,7 +1039,7 @@ namespace
}

template<typename T>
std::tuple<T, T, u32> expand_indexed_triangle_fan(gsl::span<to_be_t<const T>> src, gsl::span<T> dst, bool is_primitive_restart_enabled, u32 primitive_restart_index)
std::tuple<T, T, u32> expand_indexed_triangle_fan(std::span<to_be_t<const T>> src, std::span<T> dst, bool is_primitive_restart_enabled, u32 primitive_restart_index)
{
const T invalid_index = index_limit<T>();

Expand Down Expand Up @@ -1091,7 +1091,7 @@ namespace
}

template<typename T>
std::tuple<T, T, u32> expand_indexed_quads(gsl::span<to_be_t<const T>> src, gsl::span<T> dst, bool is_primitive_restart_enabled, u32 primitive_restart_index)
std::tuple<T, T, u32> expand_indexed_quads(std::span<to_be_t<const T>> src, std::span<T> dst, bool is_primitive_restart_enabled, u32 primitive_restart_index)
{
T min_index = index_limit<T>();
T max_index = 0;
Expand Down Expand Up @@ -1252,8 +1252,8 @@ void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst,
namespace
{
template<typename T>
std::tuple<T, T, u32> write_index_array_data_to_buffer_impl(gsl::span<T> dst,
gsl::span<const be_t<T>> src,
std::tuple<T, T, u32> write_index_array_data_to_buffer_impl(std::span<T> dst,
std::span<const be_t<T>> src,
rsx::primitive_type draw_mode, bool restart_index_enabled, u32 restart_index,
const std::function<bool(rsx::primitive_type)>& expands)
{
Expand Down Expand Up @@ -1286,8 +1286,8 @@ namespace
}
}

std::tuple<u32, u32, u32> write_index_array_data_to_buffer(gsl::span<std::byte> dst_ptr,
gsl::span<const std::byte> src_ptr,
std::tuple<u32, u32, u32> write_index_array_data_to_buffer(std::span<std::byte> dst_ptr,
std::span<const std::byte> src_ptr,
rsx::index_array_type type, rsx::primitive_type draw_mode, bool restart_index_enabled, u32 restart_index,
const std::function<bool(rsx::primitive_type)>& expands)
{
Expand Down
9 changes: 4 additions & 5 deletions rpcs3/Emu/RSX/Common/BufferUtils.h
@@ -1,13 +1,14 @@
#pragma once

#include "Utilities/span.h"
#include "../gcm_enums.h"

#include <span>

/**
* Write count vertex attributes from src_ptr.
* src_ptr array layout is deduced from the type, vector element count and src_stride arguments.
*/
void write_vertex_array_data_to_buffer(gsl::span<std::byte> raw_dst_span, gsl::span<const std::byte> src_ptr, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride, u8 dst_stride, bool swap_endianness);
void write_vertex_array_data_to_buffer(std::span<std::byte> raw_dst_span, std::span<const std::byte> src_ptr, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride, u8 dst_stride, bool swap_endianness);

/*
* If primitive mode is not supported and need to be emulated (using an index buffer) returns false.
Expand All @@ -34,7 +35,7 @@ u32 get_index_type_size(rsx::index_array_type type);
* Returns min/max index found during the process and the number of valid indices written to the buffer.
* The function expands index buffer for non native primitive type if expands(draw_mode) return true.
*/
std::tuple<u32, u32, u32> write_index_array_data_to_buffer(gsl::span<std::byte> dst, gsl::span<const std::byte> src,
std::tuple<u32, u32, u32> write_index_array_data_to_buffer(std::span<std::byte> dst, std::span<const std::byte> src,
rsx::index_array_type, rsx::primitive_type draw_mode, bool restart_index_enabled, u32 restart_index,
const std::function<bool(rsx::primitive_type)>& expands);

Expand All @@ -61,5 +62,3 @@ template <bool unaligned = false>
void stream_data_to_memory_swapped_u32(void *dst, const void *src, u32 vertex_count, u8 stride);
template <bool unaligned = false>
bool stream_data_to_memory_swapped_and_compare_u32(void *dst, const void *src, u32 size);