format source files

This commit is contained in:
nmzik
2026-07-18 08:56:38 +02:00
parent 6c1bd853ac
commit 601c82a031
53 changed files with 1622 additions and 1573 deletions
@@ -18,16 +18,17 @@ enum class ComponentType {
struct BufferFormatInfo {
Prospero::BufferFormat format = Prospero::BufferFormat::kInvalid;
ComponentType type = ComponentType::Unknown;
uint32_t component_count = 0;
uint32_t byte_size = 0;
uint32_t component_bits[4] = {};
uint32_t component_bit_offset[4] = {};
bool packed_bitfield = false;
ComponentType type = ComponentType::Unknown;
uint32_t component_count = 0;
uint32_t byte_size = 0;
uint32_t component_bits[4] = {};
uint32_t component_bit_offset[4] = {};
bool packed_bitfield = false;
};
constexpr Prospero::BufferFormat DecodeTBufferFormat(uint32_t data_format, uint32_t number_format) {
return static_cast<Prospero::BufferFormat>(((number_format & 0x7u) << 4u) | (data_format & 0xfu));
return static_cast<Prospero::BufferFormat>(((number_format & 0x7u) << 4u) |
(data_format & 0xfu));
}
constexpr ComponentType GetFormatComponentType(Prospero::BufferFormat format) {
@@ -1,8 +1,8 @@
#include "graphics/shader/recompiler/ShaderIR.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include "common/assert.h"
#include "graphics/shader/recompiler/BufferFormat.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include <algorithm>
#include <fmt/format.h>
@@ -403,7 +403,6 @@ Decoder::Operand M0Operand() {
return operand;
}
namespace {
bool LowerScalarSelect(const Decoder::Instruction& decoded, BasicBlock* block, std::string* error) {
@@ -1145,7 +1144,6 @@ bool LowerDecodedInstruction(const Decoder::Instruction& inst, BasicBlock* block
return LowerImplemented(inst, block, error);
}
bool LowerImplemented(const Decoder::Instruction& decoded, BasicBlock* block, std::string* error) {
Instruction inst;
inst.pc = decoded.pc;
@@ -14,36 +14,34 @@ bool IsVectorCarryOutOpcode(Decoder::Opcode opcode);
bool ScalarResultWritesSccNonZero(Decoder::Opcode opcode);
bool ScalarResultIs64Bit(Decoder::Opcode opcode);
Operand MakeSccOperand();
Operand MakeImmediateU32(uint32_t value);
Operand MakePcRelativeU32(uint32_t value);
bool AppendScalarResultSccNonZero(const Decoder::Instruction& decoded, BasicBlock* block,
std::string* error);
Operand MakeSccOperand();
Operand MakeImmediateU32(uint32_t value);
Operand MakePcRelativeU32(uint32_t value);
bool AppendScalarResultSccNonZero(const Decoder::Instruction& decoded, BasicBlock* block,
std::string* error);
uint32_t VectorByteConvertIndex(Decoder::Opcode opcode);
void CopyOperandModifiers(const Decoder::Operand& decoded, Operand& operand);
bool LowerRegisterOperand(const Decoder::Operand& decoded, Operand* operand,
std::string* error);
bool LowerSourceOperand(const Decoder::Operand& decoded, Operand* operand, std::string* error);
void ApplyDppDestinationMask(const Decoder::Instruction& decoded, Operand& dst);
uint32_t ResourceIndexFromOperand(const Decoder::Operand& operand);
MemoryInfo MemoryInfoFromDecoded(const Decoder::Instruction& decoded, ResourceKind kind);
uint32_t RawScalarLoadBase(const Decoder::Operand& operand);
void ClearRegisterOffsetModifiers(Decoder::Operand& operand);
bool TryGetScalarDestinationCode(const Decoder::Operand& operand, uint32_t& code);
bool TryOffsetScalarDestination(const Decoder::Operand& operand, uint32_t index,
Decoder::Operand* result);
bool LowerRegisterOperand(const Decoder::Operand& decoded, Operand* operand, std::string* error);
bool LowerSourceOperand(const Decoder::Operand& decoded, Operand* operand, std::string* error);
void ApplyDppDestinationMask(const Decoder::Instruction& decoded, Operand& dst);
uint32_t ResourceIndexFromOperand(const Decoder::Operand& operand);
MemoryInfo MemoryInfoFromDecoded(const Decoder::Instruction& decoded, ResourceKind kind);
uint32_t RawScalarLoadBase(const Decoder::Operand& operand);
void ClearRegisterOffsetModifiers(Decoder::Operand& operand);
bool TryGetScalarDestinationCode(const Decoder::Operand& operand, uint32_t& code);
bool TryOffsetScalarDestination(const Decoder::Operand& operand, uint32_t index,
Decoder::Operand* result);
Decoder::Operand OffsetDecodedRegister(const Decoder::Operand& operand, uint32_t index);
MemoryInfo OffsetMemoryInfo(const Decoder::Instruction& decoded, ResourceKind kind,
uint32_t dword_index);
uint32_t TypedBufferComponentOffsetBytes(const Decoder::Instruction& decoded,
uint32_t component_index);
uint32_t TypedBufferFormatComponentCount(const Decoder::Instruction& decoded);
bool LowerMoveImmediateU32(uint32_t pc, const Decoder::Operand& dst, uint32_t value,
BasicBlock* block, std::string* error);
MemoryInfo OffsetBufferMemoryInfo(const Decoder::Instruction& decoded,
uint32_t component_index);
MemoryInfo ByteOffsetMemoryInfo(const Decoder::Instruction& decoded, ResourceKind kind,
uint32_t byte_offset);
MemoryInfo OffsetMemoryInfo(const Decoder::Instruction& decoded, ResourceKind kind,
uint32_t dword_index);
uint32_t TypedBufferComponentOffsetBytes(const Decoder::Instruction& decoded,
uint32_t component_index);
uint32_t TypedBufferFormatComponentCount(const Decoder::Instruction& decoded);
bool LowerMoveImmediateU32(uint32_t pc, const Decoder::Operand& dst, uint32_t value,
BasicBlock* block, std::string* error);
MemoryInfo OffsetBufferMemoryInfo(const Decoder::Instruction& decoded, uint32_t component_index);
MemoryInfo ByteOffsetMemoryInfo(const Decoder::Instruction& decoded, ResourceKind kind,
uint32_t byte_offset);
ResourceKind FlatSegmentResourceKind(uint32_t segment);
const Decoder::Operand& DecodedSourceAt(const Decoder::Instruction& decoded, uint32_t index);
Decoder::Operand M0Operand();
@@ -1,8 +1,7 @@
#include "graphics/shader/recompiler/ShaderIR.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include "common/assert.h"
#include "graphics/shader/recompiler/BufferFormat.h"
#include "graphics/shader/recompiler/ShaderIR.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include <algorithm>
#include <fmt/format.h>
@@ -1,8 +1,7 @@
#include "graphics/shader/recompiler/ShaderIR.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include "common/assert.h"
#include "graphics/shader/recompiler/BufferFormat.h"
#include "graphics/shader/recompiler/ShaderIR.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include <algorithm>
#include <fmt/format.h>
@@ -470,7 +469,6 @@ bool LowerImageOperation(const Decoder::Instruction& decoded, BasicBlock* block,
return true;
}
} // namespace
bool LowerMemoryInstruction(const Decoder::Instruction& decoded, BasicBlock* block,
@@ -647,7 +645,6 @@ bool LowerMemoryInstruction(const Decoder::Instruction& decoded, BasicBlock* blo
}
}
bool IsMemoryOpcode(Decoder::Opcode opcode) {
switch (opcode) {
case Decoder::Opcode::SLoadDword:
@@ -1,8 +1,7 @@
#include "graphics/shader/recompiler/ShaderIR.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include "common/assert.h"
#include "graphics/shader/recompiler/BufferFormat.h"
#include "graphics/shader/recompiler/ShaderIR.h"
#include "graphics/shader/recompiler/shaderIR/ShaderIRInternal.h"
#include <algorithm>
#include <fmt/format.h>
@@ -425,7 +424,6 @@ constexpr LowerMap LOWER_OPS[] = {
{Decoder::Opcode::ImageGather4H, Opcode::ImageGather4},
};
} // namespace
void SetError(std::string* error, const char* message) {
@@ -913,9 +913,11 @@ uint32_t AddressSourceCount(const IR::Instruction& inst, uint32_t first_src);
bool IsFormattedBufferComponent(const IR::Instruction& inst);
Prospero::BufferFormat FormattedBufferFormat(const EmitterState& state, const IR::Instruction& inst);
Prospero::BufferFormat FormattedBufferFormat(const EmitterState& state,
const IR::Instruction& inst);
IR::Instruction WithFormatComponentByteOffset(const IR::Instruction& inst, Prospero::BufferFormat format);
IR::Instruction WithFormatComponentByteOffset(const IR::Instruction& inst,
Prospero::BufferFormat format);
uint32_t EmitTBufferBitcastF32ToU32(EmitterState* state, uint32_t value);
@@ -953,7 +955,7 @@ bool EmitTypedTBufferLoad(EmitterState* state, const IR::Instruction& inst,
bool EmitFormattedBufferLoad(EmitterState* state, const IR::Instruction& inst);
uint32_t FormattedBufferDwordStoreComponentCount(Prospero::BufferFormat format,
uint32_t opcode_components);
uint32_t opcode_components);
bool EmitBufferIntegerFormatStore(EmitterState* state, const IR::Instruction& inst);
@@ -726,13 +726,16 @@ bool IsFormattedBufferComponent(const IR::Instruction& inst) {
inst.memory.data_dwords == 1u;
}
Prospero::BufferFormat FormattedBufferFormat(const EmitterState& state, const IR::Instruction& inst) {
Prospero::BufferFormat FormattedBufferFormat(const EmitterState& state,
const IR::Instruction& inst) {
return inst.memory.typed
? Format::DecodeTBufferFormat(inst.memory.data_format, inst.memory.number_format)
: static_cast<Prospero::BufferFormat>(StorageBufferFormat(state, inst.memory, inst.pc));
: static_cast<Prospero::BufferFormat>(
StorageBufferFormat(state, inst.memory, inst.pc));
}
IR::Instruction WithFormatComponentByteOffset(const IR::Instruction& inst, Prospero::BufferFormat format) {
IR::Instruction WithFormatComponentByteOffset(const IR::Instruction& inst,
Prospero::BufferFormat format) {
auto rebased = inst;
if (inst.memory.typed || inst.memory.component_index == 0u) {
return rebased;
@@ -972,7 +975,7 @@ bool EmitFormattedBufferLoad(EmitterState* state, const IR::Instruction& inst) {
}
uint32_t FormattedBufferDwordStoreComponentCount(Prospero::BufferFormat format,
uint32_t opcode_components) {
uint32_t opcode_components) {
switch (format) {
case Prospero::BufferFormat::k32UInt:
case Prospero::BufferFormat::k32SInt:
+27 -17
View File
@@ -9,9 +9,9 @@
#include "common/magicEnum.h"
#include "common/profiler.h"
#include "common/stringUtils.h"
#include "graphics/guest_gpu/gpu_defs.h"
#include "graphics/guest_gpu/graphicsRun.h"
#include "graphics/guest_gpu/hardwareContext.h"
#include "graphics/guest_gpu/gpu_defs.h"
#include "graphics/shader/recompiler/ShaderDecoder.h"
#include "graphics/shader/recompiler/ShaderRecompiler.h"
#include "graphics/shader/shaderVertexMetadata.h"
@@ -562,14 +562,18 @@ static uint32_t VertexAttribFormatToBufferFormat(uint32_t format) {
{Prospero::VertexAttribFormat::k10_11_11Float, Prospero::BufferFormat::k10_11_11Float},
{Prospero::VertexAttribFormat::k2_10_10_10UNorm, Prospero::BufferFormat::k2_10_10_10UNorm},
{Prospero::VertexAttribFormat::k2_10_10_10SNorm, Prospero::BufferFormat::k2_10_10_10SNorm},
{Prospero::VertexAttribFormat::k2_10_10_10UScaled, Prospero::BufferFormat::k2_10_10_10UScaled},
{Prospero::VertexAttribFormat::k2_10_10_10SScaled, Prospero::BufferFormat::k2_10_10_10SScaled},
{Prospero::VertexAttribFormat::k2_10_10_10UScaled,
Prospero::BufferFormat::k2_10_10_10UScaled},
{Prospero::VertexAttribFormat::k2_10_10_10SScaled,
Prospero::BufferFormat::k2_10_10_10SScaled},
{Prospero::VertexAttribFormat::k2_10_10_10UInt, Prospero::BufferFormat::k2_10_10_10UInt},
{Prospero::VertexAttribFormat::k2_10_10_10SInt, Prospero::BufferFormat::k2_10_10_10SInt},
{Prospero::VertexAttribFormat::k10_10_10_2UNorm, Prospero::BufferFormat::k10_10_10_2UNorm},
{Prospero::VertexAttribFormat::k10_10_10_2SNorm, Prospero::BufferFormat::k10_10_10_2SNorm},
{Prospero::VertexAttribFormat::k10_10_10_2UScaled, Prospero::BufferFormat::k10_10_10_2UScaled},
{Prospero::VertexAttribFormat::k10_10_10_2SScaled, Prospero::BufferFormat::k10_10_10_2SScaled},
{Prospero::VertexAttribFormat::k10_10_10_2UScaled,
Prospero::BufferFormat::k10_10_10_2UScaled},
{Prospero::VertexAttribFormat::k10_10_10_2SScaled,
Prospero::BufferFormat::k10_10_10_2SScaled},
{Prospero::VertexAttribFormat::k10_10_10_2UInt, Prospero::BufferFormat::k10_10_10_2UInt},
{Prospero::VertexAttribFormat::k10_10_10_2SInt, Prospero::BufferFormat::k10_10_10_2SInt},
{Prospero::VertexAttribFormat::k8_8_8_8UNorm, Prospero::BufferFormat::k8_8_8_8UNorm},
@@ -581,19 +585,25 @@ static uint32_t VertexAttribFormatToBufferFormat(uint32_t format) {
{Prospero::VertexAttribFormat::k32_32UInt, Prospero::BufferFormat::k32_32UInt},
{Prospero::VertexAttribFormat::k32_32SInt, Prospero::BufferFormat::k32_32SInt},
{Prospero::VertexAttribFormat::k32_32Float, Prospero::BufferFormat::k32_32Float},
{Prospero::VertexAttribFormat::k16_16_16_16UNorm, Prospero::BufferFormat::k16_16_16_16UNorm},
{Prospero::VertexAttribFormat::k16_16_16_16SNorm, Prospero::BufferFormat::k16_16_16_16SNorm},
{Prospero::VertexAttribFormat::k16_16_16_16UScaled, Prospero::BufferFormat::k16_16_16_16UScaled},
{Prospero::VertexAttribFormat::k16_16_16_16SScaled, Prospero::BufferFormat::k16_16_16_16SScaled},
{Prospero::VertexAttribFormat::k16_16_16_16UNorm,
Prospero::BufferFormat::k16_16_16_16UNorm},
{Prospero::VertexAttribFormat::k16_16_16_16SNorm,
Prospero::BufferFormat::k16_16_16_16SNorm},
{Prospero::VertexAttribFormat::k16_16_16_16UScaled,
Prospero::BufferFormat::k16_16_16_16UScaled},
{Prospero::VertexAttribFormat::k16_16_16_16SScaled,
Prospero::BufferFormat::k16_16_16_16SScaled},
{Prospero::VertexAttribFormat::k16_16_16_16UInt, Prospero::BufferFormat::k16_16_16_16UInt},
{Prospero::VertexAttribFormat::k16_16_16_16SInt, Prospero::BufferFormat::k16_16_16_16SInt},
{Prospero::VertexAttribFormat::k16_16_16_16Float, Prospero::BufferFormat::k16_16_16_16Float},
{Prospero::VertexAttribFormat::k16_16_16_16Float,
Prospero::BufferFormat::k16_16_16_16Float},
{Prospero::VertexAttribFormat::k32_32_32UInt, Prospero::BufferFormat::k32_32_32UInt},
{Prospero::VertexAttribFormat::k32_32_32SInt, Prospero::BufferFormat::k32_32_32SInt},
{Prospero::VertexAttribFormat::k32_32_32Float, Prospero::BufferFormat::k32_32_32Float},
{Prospero::VertexAttribFormat::k32_32_32_32UInt, Prospero::BufferFormat::k32_32_32_32UInt},
{Prospero::VertexAttribFormat::k32_32_32_32SInt, Prospero::BufferFormat::k32_32_32_32SInt},
{Prospero::VertexAttribFormat::k32_32_32_32Float, Prospero::BufferFormat::k32_32_32_32Float},
{Prospero::VertexAttribFormat::k32_32_32_32Float,
Prospero::BufferFormat::k32_32_32_32Float},
};
for (const auto& entry: format_map) {
@@ -793,9 +803,9 @@ static bool ShaderGetStaticInputInfoVS(const HW::VertexShaderInfo* regs,
static void ShaderGetStaticInputInfoPS(
const HW::PixelShaderInfo* regs, const HW::ShaderRegisters* sh,
const ShaderVertexInputInfo* vs_info,
const ShaderVertexInputInfo* vs_info,
std::span<const Prospero::ColorComponentMapping, 8> target_export_mapping,
ShaderPixelInputInfo* ps_info) {
ShaderPixelInputInfo* ps_info) {
KYTY_PROFILER_FUNCTION();
EXIT_IF(vs_info == nullptr);
@@ -834,10 +844,10 @@ static void ShaderGetStaticInputInfoPS(
: 0;
for (int i = 0; i < 8; i++) {
ps_info->target_output_mode[i] = sh->target_output_mode[i];
ps_info->target_export_mapping[i] =
sh->target_output_mode[i] != 0 ? target_export_mapping[i]
: Prospero::ColorComponentMapping {};
ps_info->target_output_mode[i] = sh->target_output_mode[i];
ps_info->target_export_mapping[i] = sh->target_output_mode[i] != 0
? target_export_mapping[i]
: Prospero::ColorComponentMapping {};
}
ps_info->mrt_output_mask = 0;
}
+20 -20
View File
@@ -96,26 +96,26 @@ struct ShaderComputeInputInfo {
};
struct ShaderPixelInputInfo {
uint32_t interpolator_settings[32] = {0};
uint32_t input_num = 0;
uint32_t ps_system_input_base = 0;
uint8_t target_output_mode[8] = {};
std::array<Prospero::ColorComponentMapping, 8> target_export_mapping = {};
uint32_t mrt_output_mask = 0;
uint32_t descriptor_set = 0;
bool ps_pos_x = false;
bool ps_pos_y = false;
bool ps_pos_xy = false;
bool ps_pos_z = false;
bool ps_pos_w = false;
bool ps_front_face = false;
bool ps_no_perspective = false;
bool ps_pixel_kill_enable = false;
bool ps_depth_export_enable = false;
bool ps_sample_mask_export_enable = false;
bool ps_early_z = false;
bool ps_execute_on_noop = false;
ShaderStageRuntime stage;
uint32_t interpolator_settings[32] = {0};
uint32_t input_num = 0;
uint32_t ps_system_input_base = 0;
uint8_t target_output_mode[8] = {};
std::array<Prospero::ColorComponentMapping, 8> target_export_mapping = {};
uint32_t mrt_output_mask = 0;
uint32_t descriptor_set = 0;
bool ps_pos_x = false;
bool ps_pos_y = false;
bool ps_pos_xy = false;
bool ps_pos_z = false;
bool ps_pos_w = false;
bool ps_front_face = false;
bool ps_no_perspective = false;
bool ps_pixel_kill_enable = false;
bool ps_depth_export_enable = false;
bool ps_sample_mask_export_enable = false;
bool ps_early_z = false;
bool ps_execute_on_noop = false;
ShaderStageRuntime stage;
bool HasPositionInput() const { return ps_pos_x || ps_pos_y || ps_pos_z || ps_pos_w; }
};