From 9653c0bafc586ecdc64a5aa8821bdfebeef45d3b Mon Sep 17 00:00:00 2001 From: DrChat Date: Tue, 3 Apr 2018 19:08:30 -0500 Subject: [PATCH] [GPU] Allow dynamic building of GPU packets --- src/xenia/gpu/xenos.h | 25 +++++++++------------ src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc | 4 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/xenia/gpu/xenos.h b/src/xenia/gpu/xenos.h index e0dd8e35c..d6a24a856 100644 --- a/src/xenia/gpu/xenos.h +++ b/src/xenia/gpu/xenos.h @@ -601,20 +601,18 @@ enum Type3Opcode { }; // clang-format on -template -constexpr inline uint32_t MakePacketType0() { +inline uint32_t MakePacketType0(uint16_t index, uint16_t count, + bool one_reg = false) { // ttcccccc cccccccc oiiiiiii iiiiiiii - static_assert(index <= 0x7FFF, "index must be <= 0x7FFF"); - static_assert(count >= 1 && count <= 0x4000, - "count must be >= 1 and <= 0x4000"); + assert(index <= 0x7FFF); + assert(count >= 1 && count <= 0x4000); return (0u << 30) | (((count - 1) & 0x3FFF) << 16) | (index & 0x7FFF); } -template -constexpr inline uint32_t MakePacketType1() { +inline uint32_t MakePacketType1(uint16_t index_1, uint16_t index_2) { // tt?????? ??222222 22222111 11111111 - static_assert(index_1 <= 0x7FF, "index_1 must be <= 0x7FF"); - static_assert(index_2 <= 0x7FF, "index_2 must be <= 0x7FF"); + assert(index_1 <= 0x7FF); + assert(index_2 <= 0x7FF); return (1u << 30) | ((index_2 & 0x7FF) << 11) | (index_1 & 0x7FF); } @@ -623,12 +621,11 @@ constexpr inline uint32_t MakePacketType2() { return (2u << 30); } -template -constexpr inline uint32_t MakePacketType3() { +inline uint32_t MakePacketType3(Type3Opcode opcode, uint16_t count, + bool predicate = false) { // ttcccccc cccccccc ?ooooooo ???????p - static_assert(opcode <= 0x7F, "opcode must be <= 0x7F"); - static_assert(count >= 1 && count <= 0x4000, - "count must be >= 1 and <= 0x4000"); + assert(opcode <= 0x7F); + assert(count >= 1 && count <= 0x4000); return (3u << 30) | (((count - 1) & 0x3FFF) << 16) | ((opcode & 0x7F) << 8) | (predicate ? 1 : 0); } diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc index 560cec820..d2675f125 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc @@ -374,7 +374,7 @@ void VdSwap(lpvoid_t buffer_ptr, // ptr into primary ringbuffer // Write in the texture fetch. dwords[offset++] = - xenos::MakePacketType0(); + xenos::MakePacketType0(gpu::XE_GPU_REG_SHADER_CONSTANT_FETCH_00_0, 6); dwords[offset++] = fetch.dword_0; dwords[offset++] = fetch.dword_1; dwords[offset++] = fetch.dword_2; @@ -382,7 +382,7 @@ void VdSwap(lpvoid_t buffer_ptr, // ptr into primary ringbuffer dwords[offset++] = fetch.dword_4; dwords[offset++] = fetch.dword_5; - dwords[offset++] = xenos::MakePacketType3(); + dwords[offset++] = xenos::MakePacketType3(xenos::PM4_XE_SWAP, 4); dwords[offset++] = 'SWAP'; dwords[offset++] = (*frontbuffer_ptr) & 0x1FFFFFFF;