Skip to content

Commit c4ba18e

Browse files
roamicdiegolix29
authored andcommitted
recompiler: fixed fragment shader built-in attribute access (shadps4-emu#1676)
* recompiler: fixed fragment shader built-in attribute access * handle en/addr separately * handle other registers as well
1 parent d27ebdf commit c4ba18e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/shader_recompiler/frontend/translate/translate.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,37 @@ void Translator::EmitPrologue() {
137137
} else {
138138
ir.SetVectorReg(dst_vreg++, ir.Imm32(0.0f));
139139
}
140+
case LogicalStage::TessellationControl: {
141+
ir.SetVectorReg(IR::VectorReg::V1,
142+
ir.GetAttributeU32(IR::Attribute::PackedHullInvocationInfo));
143+
// Test
144+
// ir.SetPatch(IR::Patch::TessellationLodLeft, ir.Imm32(1.0f));
145+
// ir.SetPatch(IR::Patch::TessellationLodTop, ir.Imm32(1.0f));
146+
// ir.SetPatch(IR::Patch::TessellationLodRight, ir.Imm32(1.0f));
147+
// ir.SetPatch(IR::Patch::TessellationLodBottom, ir.Imm32(1.0f));
148+
// ir.SetPatch(IR::Patch::TessellationLodInteriorU, ir.Imm32(1.0f));
149+
// ir.SetPatch(IR::Patch::TessellationLodInteriorV, ir.Imm32(1.0f));
150+
break;
151+
}
152+
case LogicalStage::TessellationEval:
153+
ir.SetVectorReg(IR::VectorReg::V0,
154+
ir.GetAttribute(IR::Attribute::TessellationEvaluationPointU));
155+
ir.SetVectorReg(IR::VectorReg::V1,
156+
ir.GetAttribute(IR::Attribute::TessellationEvaluationPointV));
157+
// I think V2 is actually the patch id within the patches running on the local CU, used in
158+
// compiler generated address calcs,
159+
// and V3 is the patch id within the draw
160+
ir.SetVectorReg(IR::VectorReg::V2, ir.GetAttributeU32(IR::Attribute::TessPatchIdInVgt));
161+
ir.SetVectorReg(IR::VectorReg::V3, ir.GetAttributeU32(IR::Attribute::PrimitiveId));
162+
break;
163+
case LogicalStage::Fragment:
164+
// https://github.com/chaotic-cx/mesa-mirror/blob/72326e15/src/amd/vulkan/radv_shader_args.c#L258
165+
// The first two VGPRs are used for i/j barycentric coordinates. In the vast majority of
166+
// cases it will be only those two, but if shader is using both e.g linear and perspective
167+
// inputs it can be more For now assume that this isn't the case.
168+
dst_vreg = IR::VectorReg::V2;
169+
for (u32 i = 0; i < 4; i++) {
170+
ir.SetVectorReg(dst_vreg++, ir.GetAttribute(IR::Attribute::FragCoord, i));
140171
}
141172
if (runtime_info.fs_info.addr_flags.front_face_ena) {
142173
if (runtime_info.fs_info.en_flags.front_face_ena) {

src/shader_recompiler/runtime_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <span>
88
#include <boost/container/static_vector.hpp>
99
#include "common/types.h"
10+
#include "video_core/amdgpu/liverpool.h"
1011
#include "shader_recompiler/frontend/tessellation.h"
1112
#include "video_core/amdgpu/liverpool.h"
1213
#include "video_core/amdgpu/types.h"

0 commit comments

Comments
 (0)