1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

rsx: Replace gsl::byte with C++17’s std::byte

This commit is contained in:
Emmanuel Gil Peyrot 2019-11-09 15:17:41 +01:00
parent 6ea02c23a0
commit ef368c5171
18 changed files with 52 additions and 57 deletions

View File

@ -171,11 +171,6 @@ using get_uint_t = typename get_int_impl<N>::utype;
template <std::size_t N>
using get_sint_t = typename get_int_impl<N>::stype;
namespace gsl
{
using std::byte;
}
// Formatting helper, type-specific preprocessing for improving safety and functionality
template <typename T, typename = void>
struct fmt_unveil;

View File

@ -14,9 +14,9 @@ struct frame_trace_data
std::string name;
std::pair<std::string, std::string> programs;
rsx::rsx_state state;
std::array<std::vector<gsl::byte>, 4> color_buffer;
std::array<std::vector<gsl::byte>, 2> depth_stencil;
std::vector<gsl::byte> index;
std::array<std::vector<std::byte>, 4> color_buffer;
std::array<std::vector<std::byte>, 2> depth_stencil;
std::vector<std::byte> index;
u32 vertex_count;
};

View File

@ -42,13 +42,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<gsl::byte> unformated_span)
gsl::span<T> as_span_workaround(gsl::span<std::byte> unformated_span)
{
return{ (T*)unformated_span.data(), ::narrow<int>(unformated_span.size_bytes() / sizeof(T)) };
}
template <typename T>
gsl::span<T> as_const_span(gsl::span<const gsl::byte> unformated_span)
gsl::span<T> as_const_span(gsl::span<const std::byte> unformated_span)
{
return{ (T*)unformated_span.data(), ::narrow<int>(unformated_span.size_bytes() / sizeof(T)) };
}
@ -457,7 +457,7 @@ namespace
}
}
void write_vertex_array_data_to_buffer(gsl::span<gsl::byte> raw_dst_span, gsl::span<const gsl::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(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)
{
verify(HERE), (vector_element_count > 0);
const u32 src_read_stride = rsx::get_vertex_type_size_on_host(type, vector_element_count);
@ -1171,8 +1171,8 @@ namespace
}
}
std::tuple<u32, u32, u32> write_index_array_data_to_buffer(gsl::span<gsl::byte> dst_ptr,
gsl::span<const gsl::byte> src_ptr,
std::tuple<u32, u32, u32> write_index_array_data_to_buffer(gsl::span<std::byte> dst_ptr,
gsl::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)
{

View File

@ -9,7 +9,7 @@
* 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<gsl::byte> raw_dst_span, gsl::span<const gsl::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(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);
/*
* If primitive mode is not supported and need to be emulated (using an index buffer) returns false.
@ -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<gsl::byte> dst, gsl::span<const gsl::byte> src,
std::tuple<u32, u32, u32> write_index_array_data_to_buffer(gsl::span<std::byte> dst, gsl::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);

View File

@ -28,13 +28,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<gsl::byte> unformated_span)
gsl::span<T> as_span_workaround(gsl::span<std::byte> unformated_span)
{
return{ (T*)unformated_span.data(), ::narrow<int>(unformated_span.size_bytes() / sizeof(T)) };
}
template <typename T>
gsl::span<T> as_const_span(gsl::span<const gsl::byte> unformated_span)
gsl::span<T> as_const_span(gsl::span<const std::byte> unformated_span)
{
return{ (T*)unformated_span.data(), ::narrow<int>(unformated_span.size_bytes() / sizeof(T)) };
}
@ -326,7 +326,7 @@ namespace
* Sometimes texture provides a pitch even if texture is swizzled (and then packed) and in such case it's ignored. It's passed via suggested_pitch and is used only if padded_row is false.
*/
template <u8 block_edge_in_texel, typename SRC_TYPE>
std::vector<rsx_subresource_layout> get_subresources_layout_impl(const gsl::byte *texture_data_pointer, u16 width_in_texel, u16 height_in_texel, u16 depth, u8 layer_count, u16 mipmap_count, u32 suggested_pitch_in_bytes, bool padded_row, bool border)
std::vector<rsx_subresource_layout> get_subresources_layout_impl(const std::byte *texture_data_pointer, u16 width_in_texel, u16 height_in_texel, u16 depth, u8 layer_count, u16 mipmap_count, u32 suggested_pitch_in_bytes, bool padded_row, bool border)
{
/**
* Note about size type: RSX texture width is stored in a 16 bits int and pitch is stored in a 20 bits int.
@ -387,7 +387,7 @@ namespace
slice_sz = src_pitch_in_block * block_size_in_bytes * full_height_in_block * depth;
current_subresource_layout.pitch_in_block = src_pitch_in_block;
current_subresource_layout.data = gsl::span<const gsl::byte>(texture_data_pointer + offset_in_src, slice_sz);
current_subresource_layout.data = gsl::span<const std::byte>(texture_data_pointer + offset_in_src, slice_sz);
offset_in_src += slice_sz;
miplevel_width_in_texel = std::max(miplevel_width_in_texel / 2, 1);
@ -461,7 +461,7 @@ std::vector<rsx_subresource_layout> get_subresources_layout_impl(const RsxTextur
int format = texture.format() & ~(CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_UN);
const u32 texaddr = rsx::get_address(texture.offset(), texture.location());
auto pixels = vm::_ptr<const gsl::byte>(texaddr);
auto pixels = vm::_ptr<const std::byte>(texaddr);
const bool is_swizzled = !(texture.format() & CELL_GCM_TEXTURE_LN);
const bool has_border = !texture.border_type();
@ -516,7 +516,7 @@ std::vector<rsx_subresource_layout> get_subresources_layout(const rsx::vertex_te
return get_subresources_layout_impl(texture);
}
texture_memory_info upload_texture_subresource(gsl::span<gsl::byte> dst_buffer, const rsx_subresource_layout &src_layout, int format, bool is_swizzled, const texture_uploader_capabilities& caps)
texture_memory_info upload_texture_subresource(gsl::span<std::byte> dst_buffer, const rsx_subresource_layout &src_layout, int format, bool is_swizzled, const texture_uploader_capabilities& caps)
{
u16 w = src_layout.width_in_block;
u16 h = src_layout.height_in_block;

View File

@ -88,7 +88,7 @@ namespace rsx
struct rsx_subresource_layout
{
gsl::span<const gsl::byte> data;
gsl::span<const std::byte> data;
u16 width_in_texel;
u16 height_in_texel;
u16 width_in_block;
@ -132,7 +132,7 @@ size_t get_placed_texture_storage_size(const rsx::vertex_texture &texture, size_
std::vector<rsx_subresource_layout> get_subresources_layout(const rsx::fragment_texture &texture);
std::vector<rsx_subresource_layout> get_subresources_layout(const rsx::vertex_texture &texture);
texture_memory_info upload_texture_subresource(gsl::span<gsl::byte> dst_buffer, const rsx_subresource_layout &src_layout, int format, bool is_swizzled, const texture_uploader_capabilities& caps);
texture_memory_info upload_texture_subresource(gsl::span<std::byte> dst_buffer, const rsx_subresource_layout &src_layout, int format, bool is_swizzled, const texture_uploader_capabilities& caps);
u8 get_format_block_size_in_bytes(int format);
u8 get_format_block_size_in_texel(int format);

View File

@ -10,7 +10,7 @@
namespace
{
template <typename T>
gsl::span<T> as_const_span(gsl::span<const gsl::byte> unformated_span)
gsl::span<T> as_const_span(gsl::span<const std::byte> unformated_span)
{
return{ (T*)unformated_span.data(), ::narrow<int>(unformated_span.size_bytes() / sizeof(T)) };
}

View File

@ -2405,7 +2405,7 @@ namespace rsx
subres.height_in_block = subres.height_in_texel = image_height;
subres.pitch_in_block = full_width;
subres.depth = 1;
subres.data = { vm::_ptr<const gsl::byte>(image_base), src.pitch * image_height };
subres.data = { vm::_ptr<const std::byte>(image_base), src.pitch * image_height };
subresource_layout.push_back(subres);
vram_texture = upload_image_from_cpu(cmd, rsx_range, image_width, image_height, 1, 1, src.pitch, gcm_format, texture_upload_context::blit_engine_src,
@ -2537,7 +2537,7 @@ namespace rsx
subres.height_in_block = subres.height_in_texel = dst_dimensions.height;
subres.pitch_in_block = pitch_in_block;
subres.depth = 1;
subres.data = { vm::get_super_ptr<const gsl::byte>(dst.rsx_address), dst.pitch * dst_dimensions.height };
subres.data = { vm::get_super_ptr<const std::byte>(dst.rsx_address), dst.pitch * dst_dimensions.height };
subresource_layout.push_back(subres);
cached_dest = upload_image_from_cpu(cmd, rsx_range, dst_dimensions.width, dst_dimensions.height, 1, 1, dst.pitch,

View File

@ -177,8 +177,8 @@ protected:
void notify_tile_unbound(u32 tile) override;
void on_semaphore_acquire_wait() override;
std::array<std::vector<gsl::byte>, 4> copy_render_targets_to_memory() override;
std::array<std::vector<gsl::byte>, 2> copy_depth_stencil_buffer_to_memory() override;
std::array<std::vector<std::byte>, 4> copy_render_targets_to_memory() override;
std::array<std::vector<std::byte>, 2> copy_depth_stencil_buffer_to_memory() override;
void on_decompiler_init() override;
void on_decompiler_exit() override;

View File

@ -414,12 +414,12 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk
}
}
std::array<std::vector<gsl::byte>, 4> GLGSRender::copy_render_targets_to_memory()
std::array<std::vector<std::byte>, 4> GLGSRender::copy_render_targets_to_memory()
{
return {};
}
std::array<std::vector<gsl::byte>, 2> GLGSRender::copy_depth_stencil_buffer_to_memory()
std::array<std::vector<std::byte>, 2> GLGSRender::copy_depth_stencil_buffer_to_memory()
{
return {};
}

View File

@ -456,7 +456,7 @@ namespace gl
}
void fill_texture(rsx::texture_dimension_extended dim, u16 mipmap_count, int format, u16 width, u16 height, u16 depth,
const std::vector<rsx_subresource_layout> &input_layouts, bool is_swizzled, GLenum gl_format, GLenum gl_type, std::vector<gsl::byte>& staging_buffer)
const std::vector<rsx_subresource_layout> &input_layouts, bool is_swizzled, GLenum gl_format, GLenum gl_type, std::vector<std::byte>& staging_buffer)
{
int mip_level = 0;
texture_uploader_capabilities caps{ true, false, false, 4 };
@ -635,7 +635,7 @@ namespace gl
// Calculate staging buffer size
const u32 aligned_pitch = align<u32>(width * get_format_block_size_in_bytes(gcm_format), 4);
size_t texture_data_sz = depth * height * aligned_pitch;
std::vector<gsl::byte> data_upload_buf(texture_data_sz);
std::vector<std::byte> data_upload_buf(texture_data_sz);
// TODO: GL drivers support byteswapping and this should be used instead of doing so manually
const auto format_type = get_format_type(gcm_format);

View File

@ -107,7 +107,7 @@ namespace
u32 offset_in_index_buffer = mapping.second;
std::tie(min_index, max_index, index_count) = write_index_array_data_to_buffer(
{ reinterpret_cast<gsl::byte*>(ptr), max_size },
{ reinterpret_cast<std::byte*>(ptr), max_size },
command.raw_index_buffer, type,
rsx::method_registers.current_draw_clause.primitive,
rsx::method_registers.restart_index_enabled(),

View File

@ -830,12 +830,12 @@ namespace rsx
return t + timestamp_subvalue;
}
gsl::span<const gsl::byte> thread::get_raw_index_array(const draw_clause& draw_indexed_clause) const
gsl::span<const std::byte> thread::get_raw_index_array(const draw_clause& draw_indexed_clause) const
{
if (!element_push_buffer.empty())
{
//Indices provided via immediate mode
return{(const gsl::byte*)element_push_buffer.data(), ::narrow<u32>(element_push_buffer.size() * sizeof(u32))};
return{(const std::byte*)element_push_buffer.data(), ::narrow<u32>(element_push_buffer.size() * sizeof(u32))};
}
const rsx::index_array_type type = rsx::method_registers.index_type();
@ -850,11 +850,11 @@ namespace rsx
const u32 first = draw_indexed_clause.min_index();
const u32 count = draw_indexed_clause.get_elements_count();
const auto ptr = vm::_ptr<const gsl::byte>(address);
const auto ptr = vm::_ptr<const std::byte>(address);
return{ ptr + first * type_size, count * type_size };
}
gsl::span<const gsl::byte> thread::get_raw_vertex_buffer(const rsx::data_array_format_info& vertex_array_info, u32 base_offset, const draw_clause& draw_array_clause) const
gsl::span<const std::byte> thread::get_raw_vertex_buffer(const rsx::data_array_format_info& vertex_array_info, u32 base_offset, const draw_clause& draw_array_clause) const
{
u32 offset = vertex_array_info.offset();
u32 address = rsx::get_address(rsx::get_vertex_offset_from_base(base_offset, offset & 0x7fffffff), offset >> 31);
@ -864,7 +864,7 @@ namespace rsx
const u32 first = draw_array_clause.min_index();
const u32 count = draw_array_clause.get_elements_count();
const gsl::byte* ptr = vm::_ptr<const gsl::byte>(address);
const std::byte* ptr = vm::_ptr<const std::byte>(address);
return {ptr + first * vertex_array_info.stride(), count * vertex_array_info.stride() + element_size};
}
@ -896,7 +896,7 @@ namespace rsx
const auto& info = vertex_push_buffers[index];
const u8 element_size = info.size * sizeof(u32);
gsl::span<const gsl::byte> vertex_src = { (const gsl::byte*)vertex_push_buffers[index].data.data(), vertex_push_buffers[index].vertex_count * element_size };
gsl::span<const std::byte> vertex_src = { (const std::byte*)vertex_push_buffers[index].data.data(), vertex_push_buffers[index].vertex_count * element_size };
result.emplace_back(vertex_array_buffer{ info.type, info.size, element_size, vertex_src, index, false });
continue;
}

View File

@ -128,7 +128,7 @@ namespace rsx
rsx::vertex_base_type type;
u8 attribute_size;
u8 stride;
gsl::span<const gsl::byte> data;
gsl::span<const std::byte> data;
u8 index;
bool is_be;
};
@ -153,7 +153,7 @@ namespace rsx
struct draw_indexed_array_command
{
gsl::span<const gsl::byte> raw_index_buffer;
gsl::span<const std::byte> raw_index_buffer;
};
struct draw_inlined_array
@ -714,8 +714,8 @@ namespace rsx
flags32_t read_barrier(u32 memory_address, u32 memory_range, bool unconditional);
virtual void sync_hint(FIFO_hint /*hint*/, u64 /*arg*/) {}
gsl::span<const gsl::byte> get_raw_index_array(const draw_clause& draw_indexed_clause) const;
gsl::span<const gsl::byte> get_raw_vertex_buffer(const rsx::data_array_format_info&, u32 base_offset, const draw_clause& draw_array_clause) const;
gsl::span<const std::byte> get_raw_index_array(const draw_clause& draw_indexed_clause) const;
gsl::span<const std::byte> get_raw_vertex_buffer(const rsx::data_array_format_info&, u32 base_offset, const draw_clause& draw_array_clause) const;
std::vector<std::variant<vertex_array_buffer, vertex_array_register, empty_vertex_array>>
get_vertex_buffers(const rsx::rsx_state& state, u64 consumed_attrib_mask) const;
@ -821,16 +821,16 @@ namespace rsx
* Copy rtt values to buffer.
* TODO: It's more efficient to combine multiple call of this function into one.
*/
virtual std::array<std::vector<gsl::byte>, 4> copy_render_targets_to_memory() {
return std::array<std::vector<gsl::byte>, 4>();
virtual std::array<std::vector<std::byte>, 4> copy_render_targets_to_memory() {
return std::array<std::vector<std::byte>, 4>();
}
/**
* Copy depth and stencil content to buffers.
* TODO: It's more efficient to combine multiple call of this function into one.
*/
virtual std::array<std::vector<gsl::byte>, 2> copy_depth_stencil_buffer_to_memory() {
return std::array<std::vector<gsl::byte>, 2>();
virtual std::array<std::vector<std::byte>, 2> copy_depth_stencil_buffer_to_memory() {
return std::array<std::vector<std::byte>, 2>();
}
virtual std::pair<std::string, std::string> get_programs() const { return std::make_pair("", ""); }

View File

@ -245,7 +245,7 @@ namespace vk
subres.height_in_block = subres.height_in_texel = surface_height * samples_y;
subres.pitch_in_block = rsx_pitch / get_bpp();
subres.depth = 1;
subres.data = { (const gsl::byte*)vm::get_super_ptr(base_addr), s32(rsx_pitch * surface_height * samples_y) };
subres.data = { (const std::byte*)vm::get_super_ptr(base_addr), s32(rsx_pitch * surface_height * samples_y) };
if (LIKELY(g_cfg.video.resolution_scale_percent == 100 && samples() == 1))
{

View File

@ -722,7 +722,7 @@ namespace vk
check_caps = false;
}
gsl::span<gsl::byte> mapped{ (gsl::byte*)mapped_buffer, ::narrow<int>(image_linear_size) };
gsl::span<std::byte> mapped{ (std::byte*)mapped_buffer, ::narrow<int>(image_linear_size) };
opt = upload_texture_subresource(mapped, layout, format, is_swizzled, caps);
upload_heap.unmap();

View File

@ -144,8 +144,8 @@ namespace
VkDeviceSize offset_in_index_buffer = m_index_buffer_ring_info.alloc<4>(upload_size);
void* buf = m_index_buffer_ring_info.map(offset_in_index_buffer, upload_size);
gsl::span<gsl::byte> dst;
std::vector<gsl::byte> tmp;
gsl::span<std::byte> dst;
std::vector<std::byte> tmp;
if (emulate_restart)
{
tmp.resize(upload_size);
@ -153,7 +153,7 @@ namespace
}
else
{
dst = gsl::span<gsl::byte>(static_cast<gsl::byte*>(buf), upload_size);
dst = gsl::span<std::byte>(static_cast<std::byte*>(buf), upload_size);
}
/**

View File

@ -13,7 +13,7 @@ constexpr auto qstr = QString::fromStdString;
namespace
{
template <typename T>
gsl::span<T> as_const_span(gsl::span<const gsl::byte> unformated_span)
gsl::span<T> as_const_span(gsl::span<const std::byte> unformated_span)
{
return{ (T*)unformated_span.data(), ::narrow<int>(unformated_span.size_bytes() / sizeof(T)) };
}
@ -427,7 +427,7 @@ void Buffer::ShowWindowed()
namespace
{
std::array<u8, 3> get_value(gsl::span<const gsl::byte> orig_buffer, rsx::surface_color_format format, size_t idx)
std::array<u8, 3> get_value(gsl::span<const std::byte> orig_buffer, rsx::surface_color_format format, size_t idx)
{
switch (format)
{
@ -486,7 +486,7 @@ namespace
/**
* Return a new buffer that can be passed to QImage.
*/
u8* convert_to_QImage_buffer(rsx::surface_color_format format, gsl::span<const gsl::byte> orig_buffer, size_t width, size_t height) noexcept
u8* convert_to_QImage_buffer(rsx::surface_color_format format, gsl::span<const std::byte> orig_buffer, size_t width, size_t height) noexcept
{
unsigned char* buffer = (unsigned char*)malloc(width * height * 4);
for (u32 i = 0; i < width * height; i++)
@ -532,7 +532,7 @@ void rsx_debugger::OnClickDrawCalls()
{
if (width && height && !draw_call.depth_stencil[0].empty())
{
gsl::span<const gsl::byte> orig_buffer = draw_call.depth_stencil[0];
gsl::span<const std::byte> orig_buffer = draw_call.depth_stencil[0];
unsigned char *buffer = (unsigned char *)malloc(width * height * 4);
if (draw_call.state.surface_depth_fmt() == rsx::surface_depth_format::z24s8)
@ -573,7 +573,7 @@ void rsx_debugger::OnClickDrawCalls()
{
if (width && height && !draw_call.depth_stencil[1].empty())
{
gsl::span<const gsl::byte> orig_buffer = draw_call.depth_stencil[1];
gsl::span<const std::byte> orig_buffer = draw_call.depth_stencil[1];
unsigned char *buffer = (unsigned char *)malloc(width * height * 4);
for (u32 row = 0; row < height; row++)