XenosRecomp/XenosRecomp/shader_recompiler.h
Isaac Marovitz a0e2d16fb0
MSL Shader Generation
Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
2025-03-21 22:07:17 -04:00

56 lines
1.7 KiB
C++

#pragma once
#include "shader.h"
#include "shader_code.h"
struct StringBuffer
{
std::string out;
template<class... Args>
void print(fmt::format_string<Args...> fmt, Args&&... args)
{
fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
}
template<class... Args>
void println(fmt::format_string<Args...> fmt, Args&&... args)
{
fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
out += '\n';
}
};
struct ShaderRecompiler : StringBuffer
{
uint32_t indentation = 0;
bool isPixelShader = false;
const uint8_t* constantTableData = nullptr;
std::unordered_map<uint32_t, VertexElement> vertexElements;
std::unordered_map<uint32_t, std::string> interpolators;
std::unordered_map<uint32_t, const ConstantInfo*> float4Constants;
std::unordered_map<uint32_t, const char*> boolConstants;
std::unordered_map<uint32_t, const char*> samplers;
std::unordered_map<uint32_t, uint32_t> ifEndLabels;
uint32_t specConstantsMask = 0;
#ifdef UNLEASHED_RECOMP
bool hasMtxProjection = false;
bool hasMtxPrevInvViewProjection = false;
#endif
void indent()
{
for (uint32_t i = 0; i < indentation; i++)
out += '\t';
}
uint32_t printDstSwizzle(uint32_t dstSwizzle, bool operand);
void printDstSwizzle01(uint32_t dstRegister, uint32_t dstSwizzle);
void recompile(const VertexFetchInstruction& instr, uint32_t address);
void recompile(const TextureFetchInstruction& instr, bool bicubic);
void recompile(const AluInstruction& instr);
void recompile(const uint8_t* shaderData, const std::string_view& include);
};