mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-10-12 02:09:17 +00:00
rsx: Refactor rsx_utils header into smaller pieces
This commit is contained in:
@@ -580,8 +580,8 @@ target_sources(rpcs3_emu PRIVATE
|
||||
RSX/RSXThread.cpp
|
||||
RSX/RSXZCULL.cpp
|
||||
RSX/rsx_methods.cpp
|
||||
RSX/rsx_utils.cpp
|
||||
RSX/rsx_vertex_data.cpp
|
||||
RSX/Utils/rsx_utils.cpp
|
||||
)
|
||||
|
||||
if(NOT ANDROID AND NOT APPLE)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "Emu/system_config.h"
|
||||
#include "Emu/Cell/PPUModule.h"
|
||||
#include "Emu/IdManager.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
#include "Utilities/StrUtil.h"
|
||||
|
||||
#include "cellMic.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Emu/Cell/ErrorCodes.h"
|
||||
#include "Emu/Cell/PPUModule.h"
|
||||
#include "Emu/IdManager.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
#include "Emu/RSX/RSXThread.h"
|
||||
|
||||
#include "cellVideoOut.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "vm.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
|
||||
class cpu_thread;
|
||||
class shared_mutex;
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
#include "Emu/Memory/vm.h"
|
||||
#include "TextureUtils.h"
|
||||
#include "../RSXThread.h"
|
||||
#include "../rsx_utils.h"
|
||||
#include "../color_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
#include "../Utils/color_utils.hpp"
|
||||
#include "../Utils/image_utils.hpp"
|
||||
|
||||
#include "3rdparty/bcdec/bcdec.hpp"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "io_buffer.h"
|
||||
#include "simple_array.hpp"
|
||||
#include "../color_utils.h"
|
||||
#include "../Utils/color_utils.hpp"
|
||||
#include "../RSXTexture.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "ranged_map.hpp"
|
||||
#include "surface_cache_dma.hpp"
|
||||
#include "../gcm_enums.h"
|
||||
#include "../rsx_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
#include <list>
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "util/types.hpp"
|
||||
#include "Utilities/geometry.h"
|
||||
#include "TextureUtils.h"
|
||||
#include "../rsx_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
#include "Emu/Memory/vm.h"
|
||||
|
||||
#define ENABLE_SURFACE_CACHE_DEBUG 0
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Emu/RSX/Common/simple_array.hpp"
|
||||
#include "Emu/RSX/Core/RSXContext.h"
|
||||
#include "Emu/RSX/RSXThread.h"
|
||||
#include "Emu/RSX/Utils/algorithm.hpp"
|
||||
|
||||
#include "texture_cache_utils.h"
|
||||
#include "texture_cache_predictor.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#ifdef TEXTURE_CACHE_DEBUG
|
||||
|
||||
#include "../rsx_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
|
||||
namespace rsx {
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../rsx_utils.h"
|
||||
#include "simple_array.hpp"
|
||||
#include "TextureUtils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
|
||||
namespace rsx
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../rsx_utils.h"
|
||||
#include "TextureUtils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/algorithm.hpp"
|
||||
#include "RSXContext.h"
|
||||
|
||||
namespace rsx
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <util/types.hpp>
|
||||
#include "Emu/Cell/lv2/sys_rsx.h"
|
||||
#include "Emu/RSX/GCM.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
#include "RSXIOMap.hpp"
|
||||
|
||||
namespace rsx
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "RSXDisplay.h"
|
||||
|
||||
#include "../Common/simple_array.hpp"
|
||||
#include "../rsx_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
|
||||
namespace rsx
|
||||
{
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Emu/IdManager.h"
|
||||
#include "GLHelpers.h"
|
||||
#include "glutils/program.h"
|
||||
#include "../rsx_utils.h"
|
||||
|
||||
#include "Emu/IdManager.h"
|
||||
#include "Emu/RSX/Utils/algorithm.hpp"
|
||||
#include "Utilities/StrUtil.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "GLFragmentProgram.h"
|
||||
#include "GLPipelineCompiler.h"
|
||||
#include "../Program/ProgramStateCache.h"
|
||||
#include "../rsx_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
|
||||
struct GLTraits
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "../Common/surface_store.h"
|
||||
#include "../rsx_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
|
||||
#include "glutils/fbo.h"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "GLTexture.h"
|
||||
#include "GLTextureCache.h"
|
||||
#include "../Common/BufferUtils.h"
|
||||
#include "../Utils/image_utils.hpp"
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "Emu/system_config.h"
|
||||
|
||||
namespace gl
|
||||
{
|
||||
namespace FidelityFX
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "MM.h"
|
||||
#include <Emu/RSX/Common/simple_array.hpp>
|
||||
#include <Emu/RSX/RSXOffload.h>
|
||||
#include <Emu/RSX/Utils/rsx_utils.h>
|
||||
|
||||
#include <Emu/Memory/vm.h>
|
||||
#include <Emu/IdManager.h>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "draw_call.hpp"
|
||||
|
||||
#include "Emu/RSX/rsx_methods.h" // FIXME
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
#include "Emu/RSX/RSXThread.h"
|
||||
#include "Emu/RSX/Common/BufferUtils.h"
|
||||
#include "Emu/RSX/NV47/HW/context.h"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Emu/RSX/Core/RSXReservationLock.hpp"
|
||||
#include "Emu/RSX/Common/tiled_dma_copy.hpp"
|
||||
#include "Emu/RSX/Host/MM.h"
|
||||
#include "Emu/RSX/Utils/image_utils.hpp"
|
||||
|
||||
#include "context_accessors.define.h"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "GLSLCommon.h"
|
||||
#include "RSXFragmentProgram.h"
|
||||
|
||||
#include "Emu/RSX/color_utils.h"
|
||||
#include "Emu/RSX/Utils/color_utils.hpp"
|
||||
#include "Emu/RSX/gcm_enums.h"
|
||||
#include "Utilities/StrFmt.h"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "GLSLTypes.h"
|
||||
#include "ShaderParam.h"
|
||||
#include "../color_utils.h"
|
||||
#include "../Utils/color_utils.hpp"
|
||||
|
||||
struct RSXFragmentProgram;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "RSXTexture.h"
|
||||
|
||||
#include "rsx_utils.h"
|
||||
#include "Common/TextureUtils.h"
|
||||
#include "Program/GLSLCommon.h"
|
||||
#include "Utils/algorithm.hpp"
|
||||
#include "Utils/rsx_utils.h"
|
||||
|
||||
#include "Emu/system_config.h"
|
||||
#include "util/simd.hpp"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "gcm_enums.h"
|
||||
#include "color_utils.h"
|
||||
#include "Utils/color_utils.hpp"
|
||||
|
||||
namespace rsx
|
||||
{
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#include "RSXFIFO.h"
|
||||
#include "RSXOffload.h"
|
||||
#include "RSXZCULL.h"
|
||||
#include "rsx_utils.h"
|
||||
#include "Common/bitfield.hpp"
|
||||
#include "Common/profiling_timer.hpp"
|
||||
#include "Common/texture_cache_types.h"
|
||||
#include "Common/TextureUtils.h"
|
||||
#include "Program/RSXVertexProgram.h"
|
||||
#include "Program/RSXFragmentProgram.h"
|
||||
#include "Utils/rsx_utils.h"
|
||||
|
||||
#include "Utilities/Thread.h"
|
||||
#include "Utilities/geometry.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "Utilities/mutex.h"
|
||||
|
||||
#include "rsx_utils.h"
|
||||
#include "Utils/rsx_utils.h"
|
||||
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <util/types.hpp>
|
||||
|
||||
namespace rsx
|
||||
{
|
||||
static constexpr u32 floor_log2(u32 value)
|
||||
{
|
||||
return value <= 1 ? 0 : std::countl_zero(value) ^ 31;
|
||||
}
|
||||
|
||||
static constexpr u32 ceil_log2(u32 value)
|
||||
{
|
||||
return floor_log2(value) + u32{!!(value & (value - 1))};
|
||||
}
|
||||
|
||||
static constexpr u32 next_pow2(u32 x)
|
||||
{
|
||||
if (x <= 2) return x;
|
||||
|
||||
return static_cast<u32>((1ULL << 32) >> std::countl_zero(x - 1));
|
||||
}
|
||||
|
||||
static inline bool fcmp(float a, float b, float epsilon = 0.000001f)
|
||||
{
|
||||
return fabsf(a - b) < epsilon;
|
||||
}
|
||||
|
||||
// General purpose alignment without power-of-2 constraint
|
||||
template <typename T, typename U>
|
||||
static inline T align2(T value, U alignment)
|
||||
{
|
||||
return ((value + alignment - 1) / alignment) * alignment;
|
||||
}
|
||||
|
||||
// General purpose downward alignment without power-of-2 constraint
|
||||
template <typename T, typename U>
|
||||
static inline T align_down2(T value, U alignment)
|
||||
{
|
||||
return (value / alignment) * alignment;
|
||||
}
|
||||
|
||||
// Copy memory in inverse direction from source
|
||||
// Used to scale negatively x axis while transfering image data
|
||||
template <typename Ts = u8, typename Td = Ts>
|
||||
static void memcpy_r(void* dst, void* src, usz size)
|
||||
{
|
||||
for (u32 i = 0; i < size; i++)
|
||||
{
|
||||
*(static_cast<Td*>(dst) + i) = *(static_cast<Ts*>(src) - i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <util/types.hpp>
|
||||
#include <Utilities/geometry.h>
|
||||
#include "gcm_enums.h"
|
||||
#include "../gcm_enums.h"
|
||||
#include "Utilities/StrFmt.h"
|
||||
|
||||
namespace rsx
|
||||
@@ -0,0 +1,188 @@
|
||||
#pragma once
|
||||
|
||||
#include <util/types.hpp>
|
||||
#include "algorithm.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <libavutil/pixfmt.h>
|
||||
}
|
||||
|
||||
namespace rsx
|
||||
{
|
||||
template <typename T>
|
||||
void pad_texture(const void* input_pixels, void* output_pixels, u16 input_width, u16 input_height, u16 output_width, u16 /*output_height*/)
|
||||
{
|
||||
const T *src = static_cast<const T*>(input_pixels);
|
||||
T *dst = static_cast<T*>(output_pixels);
|
||||
|
||||
for (u16 h = 0; h < input_height; ++h)
|
||||
{
|
||||
const u32 padded_pos = h * output_width;
|
||||
const u32 pos = h * input_width;
|
||||
for (u16 w = 0; w < input_width; ++w)
|
||||
{
|
||||
dst[padded_pos + w] = src[pos + w];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns interleaved bits of X|Y|Z used as Z-order curve indices
|
||||
static inline u32 calculate_z_index(u32 x, u32 y, u32 z, u32 log2_width, u32 log2_height, u32 log2_depth)
|
||||
{
|
||||
AUDIT(x < (1u << log2_width) && y < (1u << log2_height) && z < (1u << log2_depth));
|
||||
|
||||
// offset = X' | Y' | Z' which are x,y,z bits interleaved
|
||||
u32 offset = 0;
|
||||
u32 shift_count = 0;
|
||||
do
|
||||
{
|
||||
if (log2_width)
|
||||
{
|
||||
offset |= (x & 0x1) << shift_count++;
|
||||
x >>= 1;
|
||||
log2_width--;
|
||||
}
|
||||
|
||||
if (log2_height)
|
||||
{
|
||||
offset |= (y & 0x1) << shift_count++;
|
||||
y >>= 1;
|
||||
log2_height--;
|
||||
}
|
||||
|
||||
if (log2_depth)
|
||||
{
|
||||
offset |= (z & 0x1) << shift_count++;
|
||||
z >>= 1;
|
||||
log2_depth--;
|
||||
}
|
||||
}
|
||||
while (x | y | z);
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/* Note: What the ps3 calls swizzling in this case is actually z-ordering / morton ordering of pixels
|
||||
* - Input can be swizzled or linear, bool flag handles conversion to and from
|
||||
* - It will handle any width and height that are a power of 2, square or non square
|
||||
* Restriction: It has mixed results if the height or width is not a power of 2
|
||||
* Restriction: Only works with 2D surfaces
|
||||
*/
|
||||
template <typename T, bool input_is_swizzled>
|
||||
void convert_linear_swizzle(const void* input_pixels, void* output_pixels, u16 width, u16 height, u32 pitch)
|
||||
{
|
||||
const u32 log2width = ceil_log2(width);
|
||||
const u32 log2height = ceil_log2(height);
|
||||
|
||||
// Max mask possible for square texture
|
||||
u32 x_mask = 0x55555555;
|
||||
u32 y_mask = 0xAAAAAAAA;
|
||||
|
||||
// We have to limit the masks to the lower of the two dimensions to allow for non-square textures
|
||||
u32 limit_mask = (log2width < log2height) ? log2width : log2height;
|
||||
// double the limit mask to account for bits in both x and y
|
||||
limit_mask = 1 << (limit_mask << 1);
|
||||
|
||||
//x_mask, bits above limit are 1's for x-carry
|
||||
x_mask = (x_mask | ~(limit_mask - 1));
|
||||
//y_mask. bits above limit are 0'd, as we use a different method for y-carry over
|
||||
y_mask = (y_mask & (limit_mask - 1));
|
||||
|
||||
u32 offs_y = 0;
|
||||
u32 offs_x = 0;
|
||||
u32 offs_x0 = 0; //total y-carry offset for x
|
||||
const u32 y_incr = limit_mask;
|
||||
|
||||
// NOTE: The swizzled area is always a POT region and we must scan all of it to fill in the linear.
|
||||
// It is assumed that there is no padding on the linear side for simplicity - backend upload/download will crop as needed.
|
||||
// Remember, in cases of swizzling (and also tiled addressing) it is possible for tiled pixels to fall outside of their linear memory region.
|
||||
const u32 pitch_in_blocks = pitch / sizeof(T);
|
||||
u32 row_offset = 0;
|
||||
|
||||
if constexpr (!input_is_swizzled)
|
||||
{
|
||||
for (int y = 0; y < height; ++y, row_offset += pitch_in_blocks)
|
||||
{
|
||||
auto src = static_cast<const T*>(input_pixels) + row_offset;
|
||||
auto dst = static_cast<T*>(output_pixels) + offs_y;
|
||||
offs_x = offs_x0;
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
dst[offs_x] = src[x];
|
||||
offs_x = (offs_x - x_mask) & x_mask;
|
||||
}
|
||||
|
||||
offs_y = (offs_y - y_mask) & y_mask;
|
||||
|
||||
if (offs_y == 0)
|
||||
{
|
||||
offs_x0 += y_incr;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y = 0; y < height; ++y, row_offset += pitch_in_blocks)
|
||||
{
|
||||
auto src = static_cast<const T*>(input_pixels) + offs_y;
|
||||
auto dst = static_cast<T*>(output_pixels) + row_offset;
|
||||
offs_x = offs_x0;
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
dst[x] = src[offs_x];
|
||||
offs_x = (offs_x - x_mask) & x_mask;
|
||||
}
|
||||
|
||||
offs_y = (offs_y - y_mask) & y_mask;
|
||||
|
||||
if (offs_y == 0)
|
||||
{
|
||||
offs_x0 += y_incr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write swizzled data to linear memory with support for 3 dimensions
|
||||
* Z ordering is done in all 3 planes independently with a unit being a 2x2 block per-plane
|
||||
* A unit in 3d textures is a group of 2x2x2 texels advancing towards depth in units of 2x2x1 blocks
|
||||
* i.e 32 texels per "unit"
|
||||
*/
|
||||
template <typename T>
|
||||
void convert_linear_swizzle_3d(const void* input_pixels, void* output_pixels, u16 width, u16 height, u16 depth)
|
||||
{
|
||||
if (depth == 1)
|
||||
{
|
||||
convert_linear_swizzle<T, true>(input_pixels, output_pixels, width, height, width * sizeof(T));
|
||||
return;
|
||||
}
|
||||
|
||||
auto src = static_cast<const T*>(input_pixels);
|
||||
auto dst = static_cast<T*>(output_pixels);
|
||||
|
||||
const u32 log2_w = ceil_log2(width);
|
||||
const u32 log2_h = ceil_log2(height);
|
||||
const u32 log2_d = ceil_log2(depth);
|
||||
|
||||
for (u32 z = 0; z < depth; ++z)
|
||||
{
|
||||
for (u32 y = 0; y < height; ++y)
|
||||
{
|
||||
for (u32 x = 0; x < width; ++x)
|
||||
{
|
||||
*dst++ = src[calculate_z_index(x, y, z, log2_w, log2_h, log2_d)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void convert_scale_image(u8 *dst, AVPixelFormat dst_format, int dst_width, int dst_height, int dst_pitch,
|
||||
const u8 *src, AVPixelFormat src_format, int src_width, int src_height, int src_pitch, int src_slice_h, bool bilinear);
|
||||
|
||||
void clip_image(u8 *dst, const u8 *src, int clip_x, int clip_y, int clip_w, int clip_h, int bpp, int src_pitch, int dst_pitch);
|
||||
void clip_image_may_overlap(u8 *dst, const u8 *src, int clip_x, int clip_y, int clip_w, int clip_h, int bpp, int src_pitch, int dst_pitch, u8* buffer);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "rsx_utils.h"
|
||||
#include "rsx_methods.h"
|
||||
#include "Emu/RSX/rsx_methods.h"
|
||||
#include "Emu/Cell/Modules/cellVideoOut.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -1,14 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../system_config.h"
|
||||
#include "../../system_config.h"
|
||||
#include "Utilities/address_range.h"
|
||||
#include "Utilities/geometry.h"
|
||||
#include "gcm_enums.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <libavutil/pixfmt.h>
|
||||
}
|
||||
#include "../gcm_enums.h"
|
||||
|
||||
#define RSX_SURFACE_DIMENSION_IGNORED 1
|
||||
|
||||
@@ -228,45 +223,6 @@ namespace rsx
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void pad_texture(const void* input_pixels, void* output_pixels, u16 input_width, u16 input_height, u16 output_width, u16 /*output_height*/)
|
||||
{
|
||||
const T *src = static_cast<const T*>(input_pixels);
|
||||
T *dst = static_cast<T*>(output_pixels);
|
||||
|
||||
for (u16 h = 0; h < input_height; ++h)
|
||||
{
|
||||
const u32 padded_pos = h * output_width;
|
||||
const u32 pos = h * input_width;
|
||||
for (u16 w = 0; w < input_width; ++w)
|
||||
{
|
||||
dst[padded_pos + w] = src[pos + w];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr u32 floor_log2(u32 value)
|
||||
{
|
||||
return value <= 1 ? 0 : std::countl_zero(value) ^ 31;
|
||||
}
|
||||
|
||||
static constexpr u32 ceil_log2(u32 value)
|
||||
{
|
||||
return floor_log2(value) + u32{!!(value & (value - 1))};
|
||||
}
|
||||
|
||||
static constexpr u32 next_pow2(u32 x)
|
||||
{
|
||||
if (x <= 2) return x;
|
||||
|
||||
return static_cast<u32>((1ULL << 32) >> std::countl_zero(x - 1));
|
||||
}
|
||||
|
||||
static inline bool fcmp(float a, float b, float epsilon = 0.000001f)
|
||||
{
|
||||
return fabsf(a - b) < epsilon;
|
||||
}
|
||||
|
||||
// Returns an ever-increasing tag value
|
||||
static inline u64 get_shared_tag()
|
||||
{
|
||||
@@ -282,190 +238,6 @@ namespace rsx
|
||||
CELL_GCM_LOCATION_MAIN;
|
||||
}
|
||||
|
||||
// General purpose alignment without power-of-2 constraint
|
||||
template <typename T, typename U>
|
||||
static inline T align2(T value, U alignment)
|
||||
{
|
||||
return ((value + alignment - 1) / alignment) * alignment;
|
||||
}
|
||||
|
||||
// General purpose downward alignment without power-of-2 constraint
|
||||
template <typename T, typename U>
|
||||
static inline T align_down2(T value, U alignment)
|
||||
{
|
||||
return (value / alignment) * alignment;
|
||||
}
|
||||
|
||||
// Copy memory in inverse direction from source
|
||||
// Used to scale negatively x axis while transfering image data
|
||||
template <typename Ts = u8, typename Td = Ts>
|
||||
static void memcpy_r(void* dst, void* src, usz size)
|
||||
{
|
||||
for (u32 i = 0; i < size; i++)
|
||||
{
|
||||
*(static_cast<Td*>(dst) + i) = *(static_cast<Ts*>(src) - i);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns interleaved bits of X|Y|Z used as Z-order curve indices
|
||||
static inline u32 calculate_z_index(u32 x, u32 y, u32 z, u32 log2_width, u32 log2_height, u32 log2_depth)
|
||||
{
|
||||
AUDIT(x < (1u << log2_width) && y < (1u << log2_height) && z < (1u << log2_depth));
|
||||
|
||||
// offset = X' | Y' | Z' which are x,y,z bits interleaved
|
||||
u32 offset = 0;
|
||||
u32 shift_count = 0;
|
||||
do
|
||||
{
|
||||
if (log2_width)
|
||||
{
|
||||
offset |= (x & 0x1) << shift_count++;
|
||||
x >>= 1;
|
||||
log2_width--;
|
||||
}
|
||||
|
||||
if (log2_height)
|
||||
{
|
||||
offset |= (y & 0x1) << shift_count++;
|
||||
y >>= 1;
|
||||
log2_height--;
|
||||
}
|
||||
|
||||
if (log2_depth)
|
||||
{
|
||||
offset |= (z & 0x1) << shift_count++;
|
||||
z >>= 1;
|
||||
log2_depth--;
|
||||
}
|
||||
}
|
||||
while (x | y | z);
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/* Note: What the ps3 calls swizzling in this case is actually z-ordering / morton ordering of pixels
|
||||
* - Input can be swizzled or linear, bool flag handles conversion to and from
|
||||
* - It will handle any width and height that are a power of 2, square or non square
|
||||
* Restriction: It has mixed results if the height or width is not a power of 2
|
||||
* Restriction: Only works with 2D surfaces
|
||||
*/
|
||||
template <typename T, bool input_is_swizzled>
|
||||
void convert_linear_swizzle(const void* input_pixels, void* output_pixels, u16 width, u16 height, u32 pitch)
|
||||
{
|
||||
const u32 log2width = ceil_log2(width);
|
||||
const u32 log2height = ceil_log2(height);
|
||||
|
||||
// Max mask possible for square texture
|
||||
u32 x_mask = 0x55555555;
|
||||
u32 y_mask = 0xAAAAAAAA;
|
||||
|
||||
// We have to limit the masks to the lower of the two dimensions to allow for non-square textures
|
||||
u32 limit_mask = (log2width < log2height) ? log2width : log2height;
|
||||
// double the limit mask to account for bits in both x and y
|
||||
limit_mask = 1 << (limit_mask << 1);
|
||||
|
||||
//x_mask, bits above limit are 1's for x-carry
|
||||
x_mask = (x_mask | ~(limit_mask - 1));
|
||||
//y_mask. bits above limit are 0'd, as we use a different method for y-carry over
|
||||
y_mask = (y_mask & (limit_mask - 1));
|
||||
|
||||
u32 offs_y = 0;
|
||||
u32 offs_x = 0;
|
||||
u32 offs_x0 = 0; //total y-carry offset for x
|
||||
const u32 y_incr = limit_mask;
|
||||
|
||||
// NOTE: The swizzled area is always a POT region and we must scan all of it to fill in the linear.
|
||||
// It is assumed that there is no padding on the linear side for simplicity - backend upload/download will crop as needed.
|
||||
// Remember, in cases of swizzling (and also tiled addressing) it is possible for tiled pixels to fall outside of their linear memory region.
|
||||
const u32 pitch_in_blocks = pitch / sizeof(T);
|
||||
u32 row_offset = 0;
|
||||
|
||||
if constexpr (!input_is_swizzled)
|
||||
{
|
||||
for (int y = 0; y < height; ++y, row_offset += pitch_in_blocks)
|
||||
{
|
||||
auto src = static_cast<const T*>(input_pixels) + row_offset;
|
||||
auto dst = static_cast<T*>(output_pixels) + offs_y;
|
||||
offs_x = offs_x0;
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
dst[offs_x] = src[x];
|
||||
offs_x = (offs_x - x_mask) & x_mask;
|
||||
}
|
||||
|
||||
offs_y = (offs_y - y_mask) & y_mask;
|
||||
|
||||
if (offs_y == 0)
|
||||
{
|
||||
offs_x0 += y_incr;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y = 0; y < height; ++y, row_offset += pitch_in_blocks)
|
||||
{
|
||||
auto src = static_cast<const T*>(input_pixels) + offs_y;
|
||||
auto dst = static_cast<T*>(output_pixels) + row_offset;
|
||||
offs_x = offs_x0;
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
dst[x] = src[offs_x];
|
||||
offs_x = (offs_x - x_mask) & x_mask;
|
||||
}
|
||||
|
||||
offs_y = (offs_y - y_mask) & y_mask;
|
||||
|
||||
if (offs_y == 0)
|
||||
{
|
||||
offs_x0 += y_incr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write swizzled data to linear memory with support for 3 dimensions
|
||||
* Z ordering is done in all 3 planes independently with a unit being a 2x2 block per-plane
|
||||
* A unit in 3d textures is a group of 2x2x2 texels advancing towards depth in units of 2x2x1 blocks
|
||||
* i.e 32 texels per "unit"
|
||||
*/
|
||||
template <typename T>
|
||||
void convert_linear_swizzle_3d(const void* input_pixels, void* output_pixels, u16 width, u16 height, u16 depth)
|
||||
{
|
||||
if (depth == 1)
|
||||
{
|
||||
convert_linear_swizzle<T, true>(input_pixels, output_pixels, width, height, width * sizeof(T));
|
||||
return;
|
||||
}
|
||||
|
||||
auto src = static_cast<const T*>(input_pixels);
|
||||
auto dst = static_cast<T*>(output_pixels);
|
||||
|
||||
const u32 log2_w = ceil_log2(width);
|
||||
const u32 log2_h = ceil_log2(height);
|
||||
const u32 log2_d = ceil_log2(depth);
|
||||
|
||||
for (u32 z = 0; z < depth; ++z)
|
||||
{
|
||||
for (u32 y = 0; y < height; ++y)
|
||||
{
|
||||
for (u32 x = 0; x < width; ++x)
|
||||
{
|
||||
*dst++ = src[calculate_z_index(x, y, z, log2_w, log2_h, log2_d)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void convert_scale_image(u8 *dst, AVPixelFormat dst_format, int dst_width, int dst_height, int dst_pitch,
|
||||
const u8 *src, AVPixelFormat src_format, int src_width, int src_height, int src_pitch, int src_slice_h, bool bilinear);
|
||||
|
||||
void clip_image(u8 *dst, const u8 *src, int clip_x, int clip_y, int clip_w, int clip_h, int bpp, int src_pitch, int dst_pitch);
|
||||
void clip_image_may_overlap(u8 *dst, const u8 *src, int clip_x, int clip_y, int clip_w, int clip_h, int bpp, int src_pitch, int dst_pitch, u8* buffer);
|
||||
|
||||
std::array<float, 4> get_constant_blend_colors();
|
||||
|
||||
/**
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
#include "Emu/RSX/VK/VKProgramPipeline.h"
|
||||
#include "VKProgramPipeline.h"
|
||||
#include "vkutils/descriptors.h"
|
||||
#include "vkutils/buffer_object.h"
|
||||
|
||||
#include "Emu/IdManager.h"
|
||||
#include "Emu/RSX/Utils/algorithm.hpp"
|
||||
|
||||
#include "Utilities/StrUtil.h"
|
||||
#include "util/asm.hpp"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "VKResourceManager.h"
|
||||
|
||||
#include "Emu/RSX/Common/simple_array.hpp"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
#include "Emu/RSX/rsx_cache.h"
|
||||
#include "Utilities/mutex.h"
|
||||
#include "util/asm.hpp"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "VulkanAPI.h"
|
||||
#include "Utilities/geometry.h"
|
||||
#include "Emu/RSX/Common/TextureUtils.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
|
||||
#define OCCLUSION_MAX_POOL_SIZE DESCRIPTOR_MAX_DRAW_CALLS
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "VKGSRender.h"
|
||||
|
||||
#include "../GCM.h"
|
||||
#include "../rsx_utils.h"
|
||||
#include "../Utils/rsx_utils.h"
|
||||
#include "Utilities/deferred_op.hpp"
|
||||
|
||||
#include "util/asm.hpp"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "../Common/texture_cache.h"
|
||||
#include "../Common/tiled_dma_copy.hpp"
|
||||
#include "../Utils/image_utils.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "image_helpers.h"
|
||||
#include "image.h"
|
||||
#include "../VKRenderPass.h"
|
||||
#include "../../color_utils.h"
|
||||
#include "../../Utils/color_utils.hpp"
|
||||
|
||||
namespace vk
|
||||
{
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
#include "device.h"
|
||||
#include "memory.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
// Copied from rsx_utils.h. Move to a more convenient location
|
||||
template<typename T, typename U>
|
||||
static inline T align2(T value, U alignment)
|
||||
{
|
||||
return ((value + alignment - 1) / alignment) * alignment;
|
||||
}
|
||||
}
|
||||
#include "Emu/RSX/Utils/algorithm.hpp"
|
||||
|
||||
namespace vk
|
||||
{
|
||||
@@ -236,7 +228,7 @@ namespace vk
|
||||
for (const auto& memory_type_index : *request.memory_type)
|
||||
{
|
||||
mem_req.memoryTypeBits = 1u << memory_type_index;
|
||||
mem_req.size = ::align2(request.size, request.alignment);
|
||||
mem_req.size = rsx::align2(request.size, request.alignment);
|
||||
mem_req.alignment = request.alignment;
|
||||
create_info.memoryTypeBits = 1u << memory_type_index;
|
||||
create_info.flags = m_allocation_flags;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../VulkanAPI.h"
|
||||
#include "../../rsx_utils.h"
|
||||
#include "shared.h"
|
||||
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wnullability-completeness"
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../VulkanAPI.h"
|
||||
#include "../../rsx_utils.h"
|
||||
#include "shared.h"
|
||||
#include "../../Utils/rsx_utils.h"
|
||||
|
||||
namespace vk
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "memory.h"
|
||||
#include "sampler.h"
|
||||
#include "../../color_utils.h"
|
||||
#include "../../rsx_utils.h"
|
||||
#include "../../Utils/color_utils.hpp"
|
||||
#include "../../Utils/algorithm.hpp"
|
||||
|
||||
namespace vk
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <tuple>
|
||||
#include <algorithm>
|
||||
#include "gcm_enums.h"
|
||||
#include "rsx_utils.h"
|
||||
#include "Utils/rsx_utils.h"
|
||||
|
||||
namespace rsx
|
||||
{
|
||||
|
||||
@@ -522,7 +522,7 @@
|
||||
<ClCompile Include="Emu\RSX\RSXFIFO.cpp" />
|
||||
<ClCompile Include="Emu\RSX\RSXOffload.cpp" />
|
||||
<ClCompile Include="Emu\RSX\rsx_methods.cpp" />
|
||||
<ClCompile Include="Emu\RSX\rsx_utils.cpp" />
|
||||
<ClCompile Include="Emu\RSX\Utils\rsx_utils.cpp" />
|
||||
<ClCompile Include="Crypto\aes.cpp">
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
@@ -682,7 +682,6 @@
|
||||
<ClInclude Include="Emu\NP\rpcn_config.h" />
|
||||
<ClInclude Include="Emu\NP\ip_address.h" />
|
||||
<ClInclude Include="Emu\perf_monitor.hpp" />
|
||||
<ClInclude Include="Emu\RSX\color_utils.h" />
|
||||
<ClInclude Include="Emu\RSX\Common\aligned_malloc.hpp" />
|
||||
<ClInclude Include="Emu\RSX\Common\bitfield.hpp" />
|
||||
<ClInclude Include="Emu\RSX\Common\buffer_stream.hpp" />
|
||||
@@ -1073,7 +1072,10 @@
|
||||
<ClInclude Include="Emu\Memory\vm_reservation.h" />
|
||||
<ClInclude Include="Emu\Memory\vm_var.h" />
|
||||
<ClInclude Include="Emu\RSX\rsx_methods.h" />
|
||||
<ClInclude Include="Emu\RSX\rsx_utils.h" />
|
||||
<ClInclude Include="Emu\RSX\Utils\algorithm.hpp" />
|
||||
<ClInclude Include="Emu\RSX\Utils\color_utils.hpp" />
|
||||
<ClInclude Include="Emu\RSX\Utils\image_utils.hpp" />
|
||||
<ClInclude Include="Emu\RSX\Utils\rsx_utils.h" />
|
||||
<ClInclude Include="Emu\System.h" />
|
||||
<ClInclude Include="Emu\perf_meter.hpp" />
|
||||
<ClInclude Include="Emu\GDB.h" />
|
||||
|
||||
@@ -1333,7 +1333,7 @@
|
||||
<ClCompile Include="Emu\RSX\gcm_printing.cpp">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Emu\RSX\rsx_utils.cpp">
|
||||
<ClCompile Include="Emu\RSX\Utils\rsx_utils.cpp">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Emu\RSX\rsx_vertex_data.cpp">
|
||||
@@ -2800,9 +2800,6 @@
|
||||
<ClInclude Include="Emu\RSX\gcm_printing.h">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\RSX\rsx_utils.h">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\RSX\rsx_vertex_data.h">
|
||||
<Filter>Emu\GPU\RSX\Host Mini-Driver</Filter>
|
||||
</ClInclude>
|
||||
@@ -2830,7 +2827,16 @@
|
||||
<ClInclude Include="Emu\RSX\display.h">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\RSX\color_utils.h">
|
||||
<ClInclude Include="Emu\RSX\Utils\algorithm.hpp">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\RSX\Utils\color_utils.hpp">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\RSX\Utils\image_utils.hpp">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\RSX\Utils\rsx_utils.h">
|
||||
<Filter>Emu\GPU\RSX\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\RSX\Host\RSXDMAWriter.h">
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
#include "Emu/Cell/Modules/cellAudio.h"
|
||||
#include "Emu/Cell/lv2/sys_rsxaudio.h"
|
||||
#include "Emu/RSX/RSXThread.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/image_utils.hpp"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
#include "Emu/RSX/Overlays/overlay_message.h"
|
||||
#include "Emu/Io/interception.h"
|
||||
#include "Emu/Io/recording_config.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Emu/Cell/SPUThread.h"
|
||||
#include "Emu/CPU/CPUDisAsm.h"
|
||||
#include "Emu/RSX/RSXThread.h"
|
||||
#include "Emu/RSX/rsx_utils.h"
|
||||
#include "Emu/RSX/Utils/rsx_utils.h"
|
||||
#include "Emu/IdManager.h"
|
||||
#include "Emu/System.h"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
Reference in New Issue
Block a user