Skip to content

Commit

Permalink
Fix BE endianess arch support in semaphore_406e (RPCS3#6116)
Browse files Browse the repository at this point in the history
Add raw() methods for endianness support types and make use of it.
  • Loading branch information
elad335 authored and Yahfz committed Jul 11, 2019
1 parent f3d00c6 commit a48b6d0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
10 changes: 10 additions & 0 deletions Utilities/BEType.h
Expand Up @@ -490,6 +490,11 @@ class se_t<T, true, Align>
return storage::from(m_data);
}

stype& raw()
{
return m_data;
}

se_t& operator=(const se_t&) = default;

se_t& operator=(type value)
Expand Down Expand Up @@ -533,6 +538,11 @@ class se_t<T, false, Align>
return std::bit_cast<type>(m_data);
}

stype& raw()
{
return m_data;
}

se_t& operator=(const se_t& value) = default;

se_t& operator=(type value)
Expand Down
26 changes: 12 additions & 14 deletions rpcs3/Emu/RSX/Capture/rsx_capture.cpp
Expand Up @@ -370,26 +370,24 @@ namespace rsx
frame_capture_data::tile_state tilestate;
for (u32 i = 0; i < limits::tiles_count; ++i)
{
// Avoid byteswapping
auto tile = rsx->tiles[i].pack();
const auto tile = rsx->tiles[i].pack();
auto& tstate = tilestate.tiles[i];
tstate.tile = std::bit_cast<u32>(tile.tile);
tstate.limit = std::bit_cast<u32>(tile.limit);
tstate.pitch = rsx->tiles[i].binded ? std::bit_cast<u32>(tile.pitch) : 0;
tstate.format = rsx->tiles[i].binded ? std::bit_cast<u32>(tile.format) : 0;
tstate.tile = tile.tile;
tstate.limit = tile.limit;
tstate.pitch = rsx->tiles[i].binded ? u32{tile.pitch} : 0;
tstate.format = rsx->tiles[i].binded ? u32{tile.format} : 0;
}

for (u32 i = 0; i < limits::zculls_count; ++i)
{
// Avoid byteswapping
auto zc = rsx->zculls[i].pack();
const auto zc = rsx->zculls[i].pack();
auto& zcstate = tilestate.zculls[i];
zcstate.region = std::bit_cast<u32>(zc.region);
zcstate.size = std::bit_cast<u32>(zc.size);
zcstate.start = std::bit_cast<u32>(zc.start);
zcstate.offset = std::bit_cast<u32>(zc.offset);
zcstate.status0 = rsx->zculls[i].binded ? std::bit_cast<u32>(zc.status0) : 0;
zcstate.status1 = rsx->zculls[i].binded ? std::bit_cast<u32>(zc.status1) : 0;
zcstate.region = zc.region;
zcstate.size = zc.size;
zcstate.start = zc.start;
zcstate.offset = zc.offset;
zcstate.status0 = rsx->zculls[i].binded ? u32{zc.status0} : 0;
zcstate.status1 = rsx->zculls[i].binded ? u32{zc.status1} : 0;
}

const u64 tsnum = XXH64(&tilestate, sizeof(frame_capture_data::tile_state), 0);
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Emu/RSX/CgBinaryFragmentProgram.cpp
Expand Up @@ -228,7 +228,8 @@ void CgBinaryDisasm::TaskFP()
verify(HERE), ((m_buffer_size - m_offset) % sizeof(u32) == 0);
for (u32 i = 0; i < (m_buffer_size - m_offset) / sizeof(u32); i++)
{
data[i] = se_storage<u32>::swap(data[i]); // WTF, cannot use be_t<> there?
// Get BE data
data[i] = be_t<u32>{data[i]}.raw();
}

enum
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/CgBinaryProgram.h
Expand Up @@ -375,7 +375,7 @@ class CgBinaryDisasm
verify(HERE), (m_buffer_size - m_offset) % sizeof(u32) == 0;
for (u32 i = 0; i < (m_buffer_size - m_offset) / sizeof(u32); i++)
{
vdata[i] = se_storage<u32>::swap(vdata[i]); // WTF, cannot use be_t<> there?
vdata[i] = be_t<u32>{vdata[i]}.raw();
}

for (u32 i = 0; i < prog.ucodeSize / sizeof(u32); i++)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/RSXThread.cpp
Expand Up @@ -325,7 +325,7 @@ namespace rsx
{
//Endianness is swapped because common upload code expects input in BE
//TODO: Implement fast upload path for LE inputs and do away with this
element_push_buffer.push_back(se_storage<u32>::swap(index));
element_push_buffer.push_back(be_t<u32>{index}.raw());
}

u32 thread::get_push_buffer_index_count() const
Expand Down
14 changes: 6 additions & 8 deletions rpcs3/Emu/RSX/rsx_methods.cpp
Expand Up @@ -64,12 +64,10 @@ namespace rsx
rsx->sync_point_request = true;
const u32 addr = get_address(method_registers.semaphore_offset_406e(), method_registers.semaphore_context_dma_406e());

#ifdef IS_LE_MACHINE
arg = se_storage<u32>::swap(arg);
const auto& sema = vm::_ref<le_t<u32>>(addr);
#else
const auto& sema = vm::_ref<u32>(addr);
#endif
// Get raw BE value
arg = be_t<u32>{arg}.raw();
const auto& sema = vm::_ref<nse_t<u32>>(addr);

// TODO: Remove vblank semaphore hack
if (sema == arg || addr == rsx->ctxt_addr + 0x30) return;

Expand Down Expand Up @@ -244,8 +242,8 @@ namespace rsx
{
case rsx::vertex_base_type::ub:
case rsx::vertex_base_type::ub256:
// One-way byteswap
arg = se_storage<u32>::swap(arg);
// Get BE data
arg = be_t<u32>{arg}.raw();
break;
}

Expand Down

0 comments on commit a48b6d0

Please sign in to comment.