GPU: Precompute texture window expression [SAVEVERSION+]

This commit is contained in:
Connor McLaughlin 2020-09-20 21:28:45 +10:00
parent f761f1550f
commit cacf7a7cc9
8 changed files with 35 additions and 34 deletions

View File

@ -95,6 +95,7 @@ void GPU::SoftReset()
m_fifo.Clear();
m_blit_buffer.clear();
m_blit_remaining_words = 0;
m_draw_mode.texture_window_value = 0xFFFFFFFFu;
SetDrawMode(0);
SetTexturePalette(0);
SetTextureWindow(0);
@ -121,10 +122,10 @@ bool GPU::DoState(StateWrapper& sw)
sw.Do(&m_draw_mode.texture_page_y);
sw.Do(&m_draw_mode.texture_palette_x);
sw.Do(&m_draw_mode.texture_palette_y);
sw.Do(&m_draw_mode.texture_window_mask_x);
sw.Do(&m_draw_mode.texture_window_mask_y);
sw.Do(&m_draw_mode.texture_window_offset_x);
sw.Do(&m_draw_mode.texture_window_offset_y);
sw.Do(&m_draw_mode.texture_window_and_x);
sw.Do(&m_draw_mode.texture_window_and_y);
sw.Do(&m_draw_mode.texture_window_or_x);
sw.Do(&m_draw_mode.texture_window_or_y);
sw.Do(&m_draw_mode.texture_x_flip);
sw.Do(&m_draw_mode.texture_y_flip);
@ -1316,10 +1317,16 @@ void GPU::SetTextureWindow(u32 value)
FlushRender();
m_draw_mode.texture_window_mask_x = value & UINT32_C(0x1F);
m_draw_mode.texture_window_mask_y = (value >> 5) & UINT32_C(0x1F);
m_draw_mode.texture_window_offset_x = (value >> 10) & UINT32_C(0x1F);
m_draw_mode.texture_window_offset_y = (value >> 15) & UINT32_C(0x1F);
const u8 mask_x = Truncate8(value & UINT32_C(0x1F));
const u8 mask_y = Truncate8((value >> 5) & UINT32_C(0x1F));
const u8 offset_x = Truncate8((value >> 10) & UINT32_C(0x1F));
const u8 offset_y = Truncate8((value >> 15) & UINT32_C(0x1F));
Log_DebugPrintf("Set texture window %02X %02X %02X %02X", mask_x, mask_y, offset_x, offset_y);
m_draw_mode.texture_window_and_x = ~(mask_x * 8);
m_draw_mode.texture_window_and_y = ~(mask_y * 8);
m_draw_mode.texture_window_or_x = (offset_x & mask_x) * 8u;
m_draw_mode.texture_window_or_y = (offset_y & mask_y) * 8u;
m_draw_mode.texture_window_value = value;
m_draw_mode.texture_window_changed = true;
}

View File

@ -306,7 +306,7 @@ protected:
};
// Sprites/rectangles should be clipped to 12 bits before drawing.
static constexpr s32 TruncateVertexPosition(s32 x) { return SignExtendN<11, s32>(x); }
static constexpr s32 TruncateVertexPosition(s32 x) { return SignExtendN<12, s32>(x); }
struct NativeVertex
{
@ -581,10 +581,10 @@ protected:
u32 texture_page_y;
u32 texture_palette_x;
u32 texture_palette_y;
u8 texture_window_mask_x; // in 8 pixel steps
u8 texture_window_mask_y; // in 8 pixel steps
u8 texture_window_offset_x; // in 8 pixel steps
u8 texture_window_offset_y; // in 8 pixel steps
u8 texture_window_and_x;
u8 texture_window_and_y;
u8 texture_window_or_x;
u8 texture_window_or_y;
bool texture_x_flip;
bool texture_y_flip;
bool texture_page_changed;

View File

@ -228,10 +228,6 @@ bool GPU::HandleSetTextureWindowCommand()
{
const u32 param = FifoPop() & 0x00FFFFFFu;
SetTextureWindow(param);
Log_DebugPrintf("Set texture window %02X %02X %02X %02X", m_draw_mode.texture_window_mask_x,
m_draw_mode.texture_window_mask_y, m_draw_mode.texture_window_offset_x,
m_draw_mode.texture_window_offset_y);
AddCommandTicks(1);
EndCommand();
return true;

View File

@ -948,10 +948,10 @@ void GPU_HW::DispatchRenderCommand()
{
m_draw_mode.ClearTextureWindowChangedFlag();
m_batch_ubo_data.u_texture_window_mask[0] = ZeroExtend32(m_draw_mode.texture_window_mask_x);
m_batch_ubo_data.u_texture_window_mask[1] = ZeroExtend32(m_draw_mode.texture_window_mask_y);
m_batch_ubo_data.u_texture_window_offset[0] = ZeroExtend32(m_draw_mode.texture_window_offset_x);
m_batch_ubo_data.u_texture_window_offset[1] = ZeroExtend32(m_draw_mode.texture_window_offset_y);
m_batch_ubo_data.u_texture_window_and[0] = ZeroExtend32(m_draw_mode.texture_window_and_x);
m_batch_ubo_data.u_texture_window_and[1] = ZeroExtend32(m_draw_mode.texture_window_and_y);
m_batch_ubo_data.u_texture_window_or[0] = ZeroExtend32(m_draw_mode.texture_window_or_x);
m_batch_ubo_data.u_texture_window_or[1] = ZeroExtend32(m_draw_mode.texture_window_or_y);
m_batch_ubo_dirty = true;
}

View File

@ -119,8 +119,8 @@ protected:
struct BatchUBOData
{
u32 u_texture_window_mask[2];
u32 u_texture_window_offset[2];
u32 u_texture_window_and[2];
u32 u_texture_window_or[2];
float u_src_alpha_factor;
float u_dst_alpha_factor;
u32 u_interlaced_displayed_field;

View File

@ -68,7 +68,7 @@ float4 RGBA5551ToRGBA8(uint v)
void GPU_HW_ShaderGen::WriteBatchUniformBuffer(std::stringstream& ss)
{
DeclareUniformBuffer(ss,
{"uint2 u_texture_window_mask", "uint2 u_texture_window_offset", "float u_src_alpha_factor",
{"uint2 u_texture_window_and", "uint2 u_texture_window_or", "float u_src_alpha_factor",
"float u_dst_alpha_factor", "uint u_interlaced_displayed_field",
"bool u_set_mask_while_drawing"},
false);
@ -700,16 +700,16 @@ CONSTANT float4 TRANSPARENT_PIXEL_COLOR = float4(0.0, 0.0, 0.0, 0.0);
uint2 ApplyTextureWindow(uint2 coords)
{
uint x = (uint(coords.x) & ~(u_texture_window_mask.x * 8u)) | ((u_texture_window_offset.x & u_texture_window_mask.x) * 8u);
uint y = (uint(coords.y) & ~(u_texture_window_mask.y * 8u)) | ((u_texture_window_offset.y & u_texture_window_mask.y) * 8u);
uint x = (uint(coords.x) & u_texture_window_and.x) | u_texture_window_or.x;
uint y = (uint(coords.y) & u_texture_window_and.y) | u_texture_window_or.y;
return uint2(x, y);
}
uint2 ApplyUpscaledTextureWindow(uint2 coords)
{
uint x = (uint(coords.x) & ~(u_texture_window_mask.x * 8u * RESOLUTION_SCALE)) | ((u_texture_window_offset.x & u_texture_window_mask.x) * 8u * RESOLUTION_SCALE);
uint y = (uint(coords.y) & ~(u_texture_window_mask.y * 8u * RESOLUTION_SCALE)) | ((u_texture_window_offset.y & u_texture_window_mask.y) * 8u * RESOLUTION_SCALE);
return uint2(x, y);
uint2 native_coords = coords / uint2(RESOLUTION_SCALE, RESOLUTION_SCALE);
uint2 coords_offset = coords % uint2(RESOLUTION_SCALE, RESOLUTION_SCALE);
return (ApplyTextureWindow(native_coords) * uint2(RESOLUTION_SCALE, RESOLUTION_SCALE)) + coords_offset;
}
uint2 FloatToIntegerCoords(float2 coords)

View File

@ -602,10 +602,8 @@ void GPU_SW::ShadePixel(u32 x, u32 y, u8 color_r, u8 color_g, u8 color_b, u8 tex
{
// Apply texture window
// TODO: Precompute the second half
texcoord_x = (texcoord_x & ~(m_draw_mode.texture_window_mask_x * 8u)) |
((m_draw_mode.texture_window_offset_x & m_draw_mode.texture_window_mask_x) * 8u);
texcoord_y = (texcoord_y & ~(m_draw_mode.texture_window_mask_y * 8u)) |
((m_draw_mode.texture_window_offset_y & m_draw_mode.texture_window_mask_y) * 8u);
texcoord_x = (texcoord_x & m_draw_mode.texture_window_and_x) | m_draw_mode.texture_window_or_x;
texcoord_y = (texcoord_y & m_draw_mode.texture_window_and_y) | m_draw_mode.texture_window_or_y;
VRAMPixel texture_color;
switch (m_draw_mode.GetTextureMode())

View File

@ -2,7 +2,7 @@
#include "types.h"
static constexpr u32 SAVE_STATE_MAGIC = 0x43435544;
static constexpr u32 SAVE_STATE_VERSION = 40;
static constexpr u32 SAVE_STATE_VERSION = 41;
#pragma pack(push, 4)
struct SAVE_STATE_HEADER