span: implement as_span workarounds as utils::bless

Minor cleanup.
This commit is contained in:
Nekotekina 2021-05-31 15:25:02 +03:00
parent d862817485
commit a1608b636f
3 changed files with 57 additions and 77 deletions

View file

@ -4,6 +4,7 @@
#include "table_item_delegate.h"
#include "Emu/RSX/RSXThread.h"
#include "Emu/RSX/gcm_printing.h"
#include "util/asm.hpp"
#include <QHBoxLayout>
#include <QHeaderView>
@ -23,12 +24,12 @@ enum GCMEnumTypes
constexpr auto qstr = QString::fromStdString;
namespace
namespace utils
{
template <typename T>
std::span<T> as_const_span(std::span<const std::byte> unformated_span)
template <typename T, typename U>
[[nodiscard]] auto bless(const std::span<U>& span)
{
return{ reinterpret_cast<T*>(unformated_span.data()), unformated_span.size_bytes() / sizeof(T) };
return std::span<T>(bless<T>(span.data()), sizeof(U) * span.size() / sizeof(T));
}
}
@ -420,12 +421,12 @@ namespace
{
case rsx::surface_color_format::b8:
{
const u8 value = as_const_span<const u8>(orig_buffer)[idx];
const u8 value = utils::bless<const u8>(orig_buffer)[idx];
return{ value, value, value };
}
case rsx::surface_color_format::x32:
{
const be_t<u32> stored_val = as_const_span<const be_t<u32>>(orig_buffer)[idx];
const be_t<u32> stored_val = utils::bless<const be_t<u32>>(orig_buffer)[idx];
const u32 swapped_val = stored_val;
const f32 float_val = std::bit_cast<f32>(swapped_val);
const u8 val = float_val * 255.f;
@ -435,19 +436,19 @@ namespace
case rsx::surface_color_format::x8b8g8r8_o8b8g8r8:
case rsx::surface_color_format::x8b8g8r8_z8b8g8r8:
{
const auto ptr = as_const_span<const u8>(orig_buffer);
const auto ptr = utils::bless<const u8>(orig_buffer);
return{ ptr[1 + idx * 4], ptr[2 + idx * 4], ptr[3 + idx * 4] };
}
case rsx::surface_color_format::a8r8g8b8:
case rsx::surface_color_format::x8r8g8b8_o8r8g8b8:
case rsx::surface_color_format::x8r8g8b8_z8r8g8b8:
{
const auto ptr = as_const_span<const u8>(orig_buffer);
const auto ptr = utils::bless<const u8>(orig_buffer);
return{ ptr[3 + idx * 4], ptr[2 + idx * 4], ptr[1 + idx * 4] };
}
case rsx::surface_color_format::w16z16y16x16:
{
const auto ptr = as_const_span<const u16>(orig_buffer);
const auto ptr = utils::bless<const u16>(orig_buffer);
const f16 h0 = static_cast<f16>(ptr[4 * idx]);
const f16 h1 = static_cast<f16>(ptr[4 * idx + 1]);
const f16 h2 = static_cast<f16>(ptr[4 * idx + 2]);
@ -532,7 +533,7 @@ void rsx_debugger::OnClickDrawCalls()
{
for (u32 col = 0; col < width; col++)
{
const u32 depth_val = as_const_span<const u32>(orig_buffer)[row * width + col];
const u32 depth_val = utils::bless<const u32>(orig_buffer)[row * width + col];
const u8 displayed_depth_val = 255 * depth_val / 0xFFFFFF;
buffer[4 * col + 0 + width * row * 4] = displayed_depth_val;
buffer[4 * col + 1 + width * row * 4] = displayed_depth_val;
@ -547,7 +548,7 @@ void rsx_debugger::OnClickDrawCalls()
{
for (u32 col = 0; col < width; col++)
{
const u16 depth_val = as_const_span<const u16>(orig_buffer)[row * width + col];
const u16 depth_val = utils::bless<const u16>(orig_buffer)[row * width + col];
const u8 displayed_depth_val = 255 * depth_val / 0xFFFF;
buffer[4 * col + 0 + width * row * 4] = displayed_depth_val;
buffer[4 * col + 1 + width * row * 4] = displayed_depth_val;
@ -571,7 +572,7 @@ void rsx_debugger::OnClickDrawCalls()
{
for (u32 col = 0; col < width; col++)
{
const u8 stencil_val = as_const_span<const u8>(orig_buffer)[row * width + col];
const u8 stencil_val = utils::bless<const u8>(orig_buffer)[row * width + col];
buffer[4 * col + 0 + width * row * 4] = stencil_val;
buffer[4 * col + 1 + width * row * 4] = stencil_val;
buffer[4 * col + 2 + width * row * 4] = stencil_val;