Skip to content

Commit

Permalink
Replace gsl::span for std::span (c++20)
Browse files Browse the repository at this point in the history
  • Loading branch information
AniLeo committed Mar 17, 2020
1 parent 3566faa commit c6cd5b2
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .travis/build-linux.bash
Expand Up @@ -8,7 +8,7 @@ export LD_LIBRARY_PATH=$QT_BASE_DIR/lib/x86_64-linux-gnu:$QT_BASE_DIR/lib

cd rpcs3

git submodule update --quiet --init asmjit 3rdparty/ffmpeg 3rdparty/pugixml 3rdparty/span 3rdparty/libpng 3rdparty/cereal 3rdparty/hidapi 3rdparty/xxHash 3rdparty/yaml-cpp 3rdparty/libusb 3rdparty/FAudio Vulkan/glslang
git submodule update --quiet --init asmjit 3rdparty/ffmpeg 3rdparty/pugixml 3rdparty/libpng 3rdparty/cereal 3rdparty/hidapi 3rdparty/xxHash 3rdparty/yaml-cpp 3rdparty/libusb 3rdparty/FAudio Vulkan/glslang

# Download pre-compiled llvm libs
curl -sLO https://github.com/RPCS3/llvm-mirror/releases/download/custom-build/llvmlibs-linux.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion .travis/build-mac.bash
Expand Up @@ -15,7 +15,7 @@ cp target/release/libportability.dylib vulkan-sdk/lib/libVulkan.dylib
install_name_tool -id ${PWD}/vulkan-sdk/lib/libVulkan.dylib vulkan-sdk/lib/libVulkan.dylib
export VULKAN_SDK=${PWD}/vulkan-sdk

git submodule update --quiet --init asmjit 3rdparty/ffmpeg 3rdparty/pugixml 3rdparty/span 3rdparty/libpng 3rdparty/cereal 3rdparty/hidapi 3rdparty/libusb 3rdparty/xxHash 3rdparty/yaml-cpp 3rdparty/FAudio Vulkan/glslang
git submodule update --quiet --init asmjit 3rdparty/ffmpeg 3rdparty/pugixml 3rdparty/libpng 3rdparty/cereal 3rdparty/hidapi 3rdparty/libusb 3rdparty/xxHash 3rdparty/yaml-cpp 3rdparty/FAudio Vulkan/glslang

mkdir build; cd build
cmake .. -DWITH_LLVM=OFF -DUSE_NATIVE_INSTRUCTIONS=OFF -G Ninja
Expand Down
6 changes: 0 additions & 6 deletions 3rdparty/CMakeLists.txt
Expand Up @@ -196,11 +196,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)
Expand Down Expand Up @@ -425,7 +420,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::discord-rpc ALIAS 3rdparty_discord-rpc)
add_library(3rdparty::alsa ALIAS ${ALSA_TARGET})
Expand Down
2 changes: 0 additions & 2 deletions Utilities/span.h

This file was deleted.

1 change: 0 additions & 1 deletion appveyor.yml
Expand Up @@ -45,7 +45,6 @@ install:
git submodule -q update --init `
3rdparty/cereal `
3rdparty/ffmpeg `
3rdparty/span `
3rdparty/hidapi `
3rdparty/libpng `
3rdparty/libusb `
Expand Down
5 changes: 2 additions & 3 deletions rpcs3/Emu/CMakeLists.txt
Expand Up @@ -55,8 +55,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 @@ -448,7 +447,7 @@ target_link_libraries(rpcs3_emu
3rdparty::vulkan 3rdparty::glew
3rdparty::libusb
PRIVATE
3rdparty::span 3rdparty::xxhash
3rdparty::xxhash
)


Expand Down
30 changes: 15 additions & 15 deletions rpcs3/Emu/RSX/Common/BufferUtils.cpp
Expand Up @@ -47,13 +47,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(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 @@ -468,7 +468,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)
{
verify(HERE), (vector_element_count > 0);
const u32 src_read_stride = rsx::get_vertex_type_size_on_host(type, vector_element_count);
Expand Down Expand Up @@ -550,7 +550,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<u16>(raw_dst_span);
for (u32 i = 0; i < count; ++i)
{
u32 src_value;
Expand Down Expand Up @@ -667,7 +667,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 @@ -840,7 +840,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 @@ -900,7 +900,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 @@ -924,7 +924,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 @@ -977,7 +977,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 @@ -1148,8 +1148,8 @@ 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 @@ -1182,21 +1182,21 @@ 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)
{
switch (type)
{
case rsx::index_array_type::u16:
{
return write_index_array_data_to_buffer_impl<u16>(as_span_workaround<u16>(dst_ptr),
return write_index_array_data_to_buffer_impl<u16>(as_span<u16>(dst_ptr),
as_const_span<const be_t<u16>>(src_ptr), draw_mode, restart_index_enabled, restart_index, expands);
}
case rsx::index_array_type::u32:
{
return write_index_array_data_to_buffer_impl<u32>(as_span_workaround<u32>(dst_ptr),
return write_index_array_data_to_buffer_impl<u32>(as_span<u32>(dst_ptr),
as_const_span<const be_t<u32>>(src_ptr), draw_mode, restart_index_enabled, restart_index, expands);
}
default:
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/RSX/Common/BufferUtils.h
@@ -1,15 +1,15 @@
#pragma once

#include <vector>
#include <span>

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

/**
* 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 @@ -36,7 +36,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 Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/Common/ProgramStateCache.h
Expand Up @@ -6,8 +6,8 @@
#include "Utilities/hash.h"
#include "Utilities/mutex.h"
#include "util/logs.hpp"
#include "Utilities/span.h"

#include <span>
#include <deque>

enum class SHADER_TYPE
Expand Down Expand Up @@ -490,7 +490,7 @@ class program_state_cache
return __null_pipeline_handle;
}

void fill_fragment_constants_buffer(gsl::span<f32> dst_buffer, const RSXFragmentProgram &fragment_program, bool sanitize = false) const
void fill_fragment_constants_buffer(std::span<f32> dst_buffer, const RSXFragmentProgram &fragment_program, bool sanitize = false) const
{
const auto I = m_fragment_shader_cache.find(fragment_program);
if (I == m_fragment_shader_cache.end())
Expand Down

0 comments on commit c6cd5b2

Please sign in to comment.