mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 02:24:38 +00:00
* Add shader debug print opcode that uses NonSemantic DebugPrintf extension * small correction for flags in Inst * Fix IR Debug Print. Add StringLiteral op * add missing microinstruction changes for debugprint * cleanup. delete vaarg stuff. Smuggle format string in Info and flags * more cleanup * more * (dont merge??) update sirit submodule * fix num args 4 -> 5 * add notes about DebugPrint IR op * use NumArgsOf again * copyright * update sirit submodule * fix clangformat * add new Value variant for string literal. Use arg0 for fmt string * remove string pool changes * Update src/shader_recompiler/ir/value.cpp Co-authored-by: TheTurtle <47210458+raphaelthegreat@users.noreply.github.com> --------- Co-authored-by: TheTurtle <47210458+raphaelthegreat@users.noreply.github.com>
69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h"
|
|
#include "shader_recompiler/backend/spirv/spirv_emit_context.h"
|
|
#include "shader_recompiler/ir/debug_print.h"
|
|
|
|
namespace Shader::Backend::SPIRV {
|
|
|
|
void EmitPrologue(EmitContext& ctx) {
|
|
ctx.DefineBufferOffsets();
|
|
}
|
|
|
|
void ConvertDepthMode(EmitContext& ctx) {
|
|
const Id type{ctx.F32[1]};
|
|
const Id position{ctx.OpLoad(ctx.F32[4], ctx.output_position)};
|
|
const Id z{ctx.OpCompositeExtract(type, position, 2u)};
|
|
const Id w{ctx.OpCompositeExtract(type, position, 3u)};
|
|
const Id screen_depth{ctx.OpFMul(type, ctx.OpFAdd(type, z, w), ctx.Constant(type, 0.5f))};
|
|
const Id vector{ctx.OpCompositeInsert(ctx.F32[4], screen_depth, position, 2u)};
|
|
ctx.OpStore(ctx.output_position, vector);
|
|
}
|
|
|
|
void EmitEpilogue(EmitContext& ctx) {
|
|
if (ctx.stage == Stage::Vertex && ctx.runtime_info.vs_info.emulate_depth_negative_one_to_one) {
|
|
ConvertDepthMode(ctx);
|
|
}
|
|
}
|
|
|
|
void EmitDiscard(EmitContext& ctx) {
|
|
ctx.OpDemoteToHelperInvocationEXT();
|
|
}
|
|
|
|
void EmitDiscardCond(EmitContext& ctx, Id condition) {
|
|
const Id kill_label{ctx.OpLabel()};
|
|
const Id merge_label{ctx.OpLabel()};
|
|
ctx.OpSelectionMerge(merge_label, spv::SelectionControlMask::MaskNone);
|
|
ctx.OpBranchConditional(condition, kill_label, merge_label);
|
|
ctx.AddLabel(kill_label);
|
|
ctx.OpDemoteToHelperInvocationEXT();
|
|
ctx.OpBranch(merge_label);
|
|
ctx.AddLabel(merge_label);
|
|
}
|
|
|
|
void EmitEmitVertex(EmitContext& ctx) {
|
|
ctx.OpEmitVertex();
|
|
}
|
|
|
|
void EmitEmitPrimitive(EmitContext& ctx) {
|
|
ctx.OpEndPrimitive();
|
|
}
|
|
|
|
void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream) {
|
|
throw NotImplementedException("Geometry streams");
|
|
}
|
|
|
|
void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream) {
|
|
throw NotImplementedException("Geometry streams");
|
|
}
|
|
|
|
void EmitDebugPrint(EmitContext& ctx, IR::Inst* inst, Id fmt, Id arg0, Id arg1, Id arg2, Id arg3) {
|
|
IR::DebugPrintFlags flags = inst->Flags<IR::DebugPrintFlags>();
|
|
std::array<Id, IR::DEBUGPRINT_NUM_FORMAT_ARGS> fmt_args = {arg0, arg1, arg2, arg3};
|
|
auto fmt_args_span = std::span<Id>(fmt_args.begin(), fmt_args.begin() + flags.num_args);
|
|
ctx.OpDebugPrintf(fmt, fmt_args_span);
|
|
}
|
|
|
|
} // namespace Shader::Backend::SPIRV
|