Skip to content

Commit b40d40d

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 e69f20e commit b40d40d

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
@@ -114,6 +114,37 @@ void Translator::EmitPrologue() {
114114
} else {
115115
ir.SetVectorReg(dst_vreg++, ir.Imm32(0.0f));
116116
}
117+
case LogicalStage::TessellationControl: {
118+
ir.SetVectorReg(IR::VectorReg::V1,
119+
ir.GetAttributeU32(IR::Attribute::PackedHullInvocationInfo));
120+
// Test
121+
// ir.SetPatch(IR::Patch::TessellationLodLeft, ir.Imm32(1.0f));
122+
// ir.SetPatch(IR::Patch::TessellationLodTop, ir.Imm32(1.0f));
123+
// ir.SetPatch(IR::Patch::TessellationLodRight, ir.Imm32(1.0f));
124+
// ir.SetPatch(IR::Patch::TessellationLodBottom, ir.Imm32(1.0f));
125+
// ir.SetPatch(IR::Patch::TessellationLodInteriorU, ir.Imm32(1.0f));
126+
// ir.SetPatch(IR::Patch::TessellationLodInteriorV, ir.Imm32(1.0f));
127+
break;
128+
}
129+
case LogicalStage::TessellationEval:
130+
ir.SetVectorReg(IR::VectorReg::V0,
131+
ir.GetAttribute(IR::Attribute::TessellationEvaluationPointU));
132+
ir.SetVectorReg(IR::VectorReg::V1,
133+
ir.GetAttribute(IR::Attribute::TessellationEvaluationPointV));
134+
// I think V2 is actually the patch id within the patches running on the local CU, used in
135+
// compiler generated address calcs,
136+
// and V3 is the patch id within the draw
137+
ir.SetVectorReg(IR::VectorReg::V2, ir.GetAttributeU32(IR::Attribute::TessPatchIdInVgt));
138+
ir.SetVectorReg(IR::VectorReg::V3, ir.GetAttributeU32(IR::Attribute::PrimitiveId));
139+
break;
140+
case LogicalStage::Fragment:
141+
// https://github.com/chaotic-cx/mesa-mirror/blob/72326e15/src/amd/vulkan/radv_shader_args.c#L258
142+
// The first two VGPRs are used for i/j barycentric coordinates. In the vast majority of
143+
// cases it will be only those two, but if shader is using both e.g linear and perspective
144+
// inputs it can be more For now assume that this isn't the case.
145+
dst_vreg = IR::VectorReg::V2;
146+
for (u32 i = 0; i < 4; i++) {
147+
ir.SetVectorReg(dst_vreg++, ir.GetAttribute(IR::Attribute::FragCoord, i));
117148
}
118149
if (runtime_info.fs_info.addr_flags.front_face_ena) {
119150
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)