Triforce v0.3.6

This commit is contained in:
ruckus7382sfgsgdf
2026-11-14 00:33:23 -06:00
parent 2f1e350320
commit a02bcb21a9
106 changed files with 7683 additions and 1422 deletions

View File

@@ -117,6 +117,15 @@ void EmitInst(EmitContext& ctx, IR::Inst* inst) {
EmitInstOf(ctx, inst);
} catch (const NotImplementedException& e) {
throw NotImplementedException("{} ({})", e.what(), IR::NameOf(inst->GetOpcode()));
} catch (const std::runtime_error& e) { // (super build: sirit's null Id, named by the IR op that asked for it)
std::string args;
for (size_t i = 0; i < inst->NumArgs(); ++i) {
const IR::Value a{inst->Arg(i)};
args += a.IsImmediate() ? " imm" : a.IsEmpty() ? " empty" : a.IsIdentity() ? " identity"
: (" " + std::string(IR::NameOf(a.InstRecursive()->GetOpcode())) +
(a.InstRecursive()->Definition<Id>().value == 0 ? "(undefined)" : ""));
}
throw LogicError("{} ({}; args:{})", e.what(), IR::NameOf(inst->GetOpcode()), args);
}
}

View File

@@ -45,6 +45,13 @@ constexpr u32 MESH_FALLBACK_PAYLOAD_PUSH_OFFSET = MESH_FALLBACK_PUSH_OFFSET;
constexpr u32 MESH_FALLBACK_RECORDS_PUSH_OFFSET = MESH_FALLBACK_PUSH_OFFSET + 8;
constexpr u32 MESH_FALLBACK_INDIRECT_INPUT_PUSH_OFFSET = MESH_FALLBACK_PUSH_OFFSET + 16;
constexpr u32 MESH_FALLBACK_PUSH_END = MESH_FALLBACK_PUSH_OFFSET + 24;
// (hookshot) a scene vertex stage's position capture (RuntimeInfo::capture_position), after them: the u64 address its slots
// start at (0: none), the vertex index of slot 0 (a u32, the slot taken from VertexIndex wrapping) and the slots there are
// (u32). A vertex stores its position (vec4, 16 bytes) at address + (VertexIndex - first) * 16 when that is below the count
constexpr u32 CAPTURE_PUSH_OFFSET = MESH_FALLBACK_PUSH_END;
constexpr u32 CAPTURE_FIRST_PUSH_OFFSET = CAPTURE_PUSH_OFFSET + 8;
constexpr u32 CAPTURE_COUNT_PUSH_OFFSET = CAPTURE_PUSH_OFFSET + 12;
constexpr u32 CAPTURE_PUSH_END = CAPTURE_PUSH_OFFSET + 16;
// (hookshot) the fallback's mesh workgroups a draw can run: each a slot, a word of the payload buffer saying whether its task
// started it; then each task workgroup's payload. It was 1024, a record block each, and Ocarina's floor grass (433 tasks of
// 32 slots) lost 13 of 14 meshlets. At 16384, Hyrule Field's far trees (3cb76827/4f0c0b40: 721 tasks of 32) lost the tasks

View File

@@ -323,7 +323,16 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
}
const Id pointer{
AttrPointer(ctx, generic.pointer_type, vertex, generic.id, ctx.Const(element))};
const Id value{ctx.OpLoad(generic.component_type, pointer)};
Id value{ctx.OpLoad(generic.component_type, pointer)};
if (ctx.stage == Stage::Fragment && ctx.noperspective_as_smooth_inputs[index]) {
// Written times Position.w and interpolated perspective-correct: undo with 1/w.
// Only float inputs are marked, and DefineInputs forces FragCoord for them.
ASSERT(generic.load_op == InputGenericLoadOp::None && ValidId(ctx.input_position));
const Id frag_w{ctx.OpLoad(
ctx.F32[1],
ctx.OpAccessChain(ctx.input_f32, ctx.input_position, ctx.Const(3u)))};
value = ctx.OpFMul(ctx.F32[1], value, frag_w);
}
return [&ctx, generic, value]() {
switch (generic.load_op) {
case InputGenericLoadOp::Bitcast:
@@ -502,7 +511,7 @@ void EmitSetFragColor(EmitContext& ctx, u32 index, u32 component, Id value) {
const Id pointer{ctx.OpAccessChain(ctx.output_f32, ctx.frag_color.at(index), component_id)};
if (frag_nan_guard) { // (amd-fix, mma_layout.h) NaN -> 0, the rest clamped to +-1e30
const Id clamped{ctx.OpNMin(ctx.F32[1], ctx.OpNMax(ctx.F32[1], value, ctx.Const(-1e30f)), ctx.Const(1e30f))};
value = ctx.OpSelect(ctx.F32[1], ctx.OpIsNan(ctx.U1, value), ctx.Const(0.0f), clamped);
value = ctx.OpSelect(ctx.F32[1], IsNan(ctx, value, 32), ctx.Const(0.0f), clamped);
}
ctx.OpStore(pointer, value);
} else if (type == AttributeType::UnsignedInt) {

View File

@@ -155,7 +155,7 @@ Id EmitConvertF16F32(EmitContext& ctx, Id value) {
return ctx.OpFConvert(ctx.F16[1], value);
#else
const auto result = ctx.OpFConvert(ctx.F16[1], value);
const auto isOverflowing = ctx.OpIsNan(ctx.U1, result);
const auto isOverflowing = IsNan(ctx, result, 16); // (hookshot: mma_layout.h nan_bits)
return ctx.OpSelect(ctx.F16[1], isOverflowing, ctx.Constant(ctx.F16[1], 0), result);
#endif
}

View File

@@ -4,6 +4,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h"
#include "shader_recompiler/backend/spirv/mma_layout.h"
#include "shader_recompiler/backend/spirv/spirv_emit_context.h"
#include "shader_recompiler/frontend/ir/modifiers.h"
@@ -381,16 +382,40 @@ Id EmitFPUnordGreaterThanEqual64(EmitContext& ctx, Id lhs, Id rhs) {
return FPUnordCompare(&EmitContext::OpFUnordGreaterThanEqual, ctx, lhs, rhs);
}
// (hookshot) isnan of a scalar float of that many bits. With nan_bits (mma_layout.h: AMD's older Windows shader compiler) it is
// a test of the value's bits, a NaN being an exponent of all ones and a mantissa that is not 0, which no float-mode setting of the
// compiler can fold away; else OpIsNan, as before
Id IsNan(EmitContext& ctx, Id value, u32 bits) {
if (!nan_bits) {
return ctx.OpIsNan(ctx.U1, value);
}
if (bits == 64) {
const Id words{ctx.OpBitcast(ctx.U32[2], value)};
const Id high{ctx.OpBitwiseAnd(ctx.U32[1], ctx.OpCompositeExtract(ctx.U32[1], words, 1U),
ctx.Const(0x7fffffffu))};
const Id low{ctx.OpCompositeExtract(ctx.U32[1], words, 0U)};
const Id infinity{ctx.Const(0x7ff00000u)};
return ctx.OpLogicalOr(ctx.U1, ctx.OpUGreaterThan(ctx.U1, high, infinity),
ctx.OpLogicalAnd(ctx.U1, ctx.OpIEqual(ctx.U1, high, infinity),
ctx.OpINotEqual(ctx.U1, low, ctx.u32_zero_value)));
}
if (bits == 16) {
value = ctx.OpFConvert(ctx.F32[1], value); // (exact: a NaN stays a NaN, and nothing else becomes one)
}
const Id magnitude{ctx.OpBitwiseAnd(ctx.U32[1], ctx.OpBitcast(ctx.U32[1], value), ctx.Const(0x7fffffffu))};
return ctx.OpUGreaterThan(ctx.U1, magnitude, ctx.Const(0x7f800000u));
}
Id EmitFPIsNan16(EmitContext& ctx, Id value) {
return ctx.OpIsNan(ctx.U1, value);
return IsNan(ctx, value, 16);
}
Id EmitFPIsNan32(EmitContext& ctx, Id value) {
return ctx.OpIsNan(ctx.U1, value);
return IsNan(ctx, value, 32);
}
Id EmitFPIsNan64(EmitContext& ctx, Id value) {
return ctx.OpIsNan(ctx.U1, value);
return IsNan(ctx, value, 64);
}
} // namespace Shader::Backend::SPIRV

View File

@@ -9,6 +9,7 @@
#include "common/settings.h"
#include "shader_recompiler/backend/spirv/emit_spirv.h"
#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h"
#include "shader_recompiler/backend/spirv/mma_layout.h"
#include "shader_recompiler/backend/spirv/spirv_emit_context.h"
#include "shader_recompiler/frontend/ir/modifiers.h"
@@ -445,9 +446,10 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info,
case TextureType::Color2DRect:
return calculate_coords(2);
case TextureType::ColorArray2D:
case TextureType::ColorCube:
return calculate_coords(3);
default:
// (hookshot) a cube's coordinates are a direction: no texel to nudge by, and its size query has two components, not
// three (the cube case here made invalid SPIR-V: OpImageQuerySizeLod's result of three components on a cube)
return coords;
}
}
@@ -488,6 +490,64 @@ void AddOffsetToCoordinates(EmitContext& ctx, const IR::TextureInstInfo& info, I
}
coords = ctx.OpIAdd(result_type, coords, offset);
}
// (hookshot, mma_layout.h fetch_bounds) Whether a texel fetch of image at coords (with its level, or its sample, when it has one)
// is inside the image, as U1; coords, lod and sample are made ones that are (a coordinate out of range 0, a level or sample past
// the last 0), so that the fetch itself never leaves the image, and the caller answers zero for it. NVIDIA's GPUs answer an
// out-of-bounds fetch with zero (measured on an RTX 3090 with robustness off: every texture type, past each edge, past the last
// level and the last sample; the alpha of a format without one is 1 there, as in range, and 0 here: the translation does not
// know the format). Vulkan leaves such a fetch undefined without robustImageAccess, and on AMD the ground fog's depth reads at
// points projected off screen took the other branch: a pale box at the screen's edges (found by Ocarina of Lain's author on
// an RX 9070). Id{}: a type left as it was: a texel buffer while robustBufferAccess2 is on (on by default: the Robust buffers
// row), which answers its out-of-bounds reads with zero already (fetch_bounds_buffers), and the cube types, which no fetch reads
Id FetchInBounds(EmitContext& ctx, const IR::TextureInstInfo& info, Id image, Id& coords, Id& lod, Id& sample) {
u32 dims{};
switch (info.type) {
case TextureType::Buffer:
if (!fetch_bounds_buffers) {
return Id{};
}
dims = 1;
break;
case TextureType::Color1D:
dims = 1;
break;
case TextureType::ColorArray1D:
case TextureType::Color2D:
case TextureType::Color2DRect:
dims = 2;
break;
case TextureType::ColorArray2D:
case TextureType::Color3D:
dims = 3;
break;
default:
return Id{};
}
const Id size_type{ctx.U32[dims]};
Id level_ok{};
Id size{};
if (Sirit::ValidId(lod)) {
const Id levels{ctx.OpImageQueryLevels(ctx.U32[1], image)};
level_ok = ctx.OpULessThan(ctx.U1, lod, levels);
lod = ctx.OpSelect(ctx.U32[1], level_ok, lod, ctx.u32_zero_value);
size = ctx.OpImageQuerySizeLod(size_type, image, lod);
} else {
size = ctx.OpImageQuerySize(size_type, image); // (a texel buffer, or a multisampled image)
}
// (unsigned: a negative coordinate is past the end too)
const Id inside{ctx.OpULessThan(dims == 1 ? ctx.U1 : ctx.TypeVector(ctx.U1, dims), coords, size)};
coords = ctx.OpSelect(size_type, inside, coords, ctx.ConstantNull(size_type));
Id in_bounds{dims == 1 ? inside : ctx.OpAll(ctx.U1, inside)};
if (Sirit::ValidId(level_ok)) {
in_bounds = ctx.OpLogicalAnd(ctx.U1, in_bounds, level_ok);
}
if (Sirit::ValidId(sample)) {
const Id sample_ok{ctx.OpULessThan(ctx.U1, sample, ctx.OpImageQuerySamples(ctx.U32[1], image))};
sample = ctx.OpSelect(ctx.U32[1], sample_ok, sample, ctx.u32_zero_value);
in_bounds = ctx.OpLogicalAnd(ctx.U1, in_bounds, sample_ok);
}
return in_bounds;
}
} // Anonymous namespace
Id EmitBindlessImageSampleImplicitLod(EmitContext&) {
@@ -724,6 +784,17 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c
// This image is multisampled, lod must be implicit
lod = Id{};
}
if (fetch_bounds) { // (hookshot: FetchInBounds)
const Id image{TextureImage(ctx, info, index)};
const Id in_bounds{FetchInBounds(ctx, info, image, coords, lod, ms)};
const ImageOperands operands(lod, ms);
Id color{Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst,
result_type, image, coords, operands.MaskOptional(), operands.Span())};
if (Sirit::ValidId(in_bounds)) {
color = ctx.OpSelect(result_type, in_bounds, color, ctx.ConstantNull(result_type));
}
return is_integer ? ctx.OpBitcast(ctx.F32[4], color) : color;
}
const ImageOperands operands(lod, ms);
const Id color{Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst,
result_type, TextureImage(ctx, info, index), coords,

View File

@@ -644,4 +644,7 @@ Id EmitDPdyFine(EmitContext& ctx, Id op_a);
Id EmitDPdxCoarse(EmitContext& ctx, Id op_a);
Id EmitDPdyCoarse(EmitContext& ctx, Id op_a);
// (hookshot) Helpers the emitters share, not IR instructions
Id IsNan(EmitContext& ctx, Id value, u32 bits); // (OpIsNan, or a test of the bits: mma_layout.h nan_bits)
} // namespace Shader::Backend::SPIRV

View File

@@ -4,6 +4,9 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <utility>
#include <vector>
#include "shader_recompiler/backend/spirv/emit_spirv.h"
#include "shader_recompiler/backend/spirv/emit_spirv_instructions.h"
#include "shader_recompiler/backend/spirv/spirv_emit_context.h"
@@ -20,6 +23,74 @@ void ConvertDepthMode(EmitContext& ctx) {
ctx.OpStore(ctx.output_position, vector);
}
/// Output variable and the unscaled value it held before ScaleNoPerspectiveOutputs.
using ScaledOutputs = std::vector<std::pair<Id, Id>>;
/// Write screen-linear generic outputs times Position.w (see RuntimeInfo::noperspective_outputs).
/// Returns the unscaled values so a geometry shader can restore them after EmitVertex.
ScaledOutputs ScaleNoPerspectiveOutputs(EmitContext& ctx) {
ScaledOutputs saved;
if (ctx.runtime_info.noperspective_outputs.none() || !Sirit::ValidId(ctx.output_position)) {
return saved;
}
const Id position{ctx.OpLoad(ctx.F32[4], ctx.output_position)};
const Id w{ctx.OpCompositeExtract(ctx.F32[1], position, 3u)};
for (size_t index = 0; index < ctx.output_generics.size(); ++index) {
if (!ctx.runtime_info.noperspective_outputs.test(index)) {
continue;
}
Id last{};
for (const GenericElementInfo& element : ctx.output_generics[index]) {
if (!Sirit::ValidId(element.id) || element.id.value == last.value ||
element.num_components == 0) {
continue;
}
last = element.id;
const Id type{ctx.F32[element.num_components]};
const Id value{ctx.OpLoad(type, element.id)};
const Id scaled{element.num_components == 1 ? ctx.OpFMul(type, value, w)
: ctx.OpVectorTimesScalar(type, value, w)};
ctx.OpStore(element.id, scaled);
saved.emplace_back(element.id, value);
}
}
return saved;
}
/// A geometry shader keeps its outputs between EmitVertex calls: restore the unscaled values.
void RestoreNoPerspectiveOutputs(EmitContext& ctx, const ScaledOutputs& saved) {
for (const auto& [id, value] : saved) {
ctx.OpStore(id, value);
}
}
/// (hookshot) RuntimeInfo::capture_position: the position as the stage leaves it, stored at the pushed address's slot for
/// this vertex (CAPTURE_PUSH_OFFSET), when the address is not 0 and the slot below the pushed count. What is drawn is not
/// changed: the store is the stage's last act, and reads only what it wrote
void CapturePosition(EmitContext& ctx) {
const auto push = [&](Id type, u32 member) {
const Id pointer{ctx.TypePointer(spv::StorageClass::PushConstant, type)};
return ctx.OpLoad(type, ctx.OpAccessChain(pointer, ctx.rescaling_push_constants, ctx.Const(member)));
};
const Id address{push(ctx.U64, ctx.capture_address_member_index)};
const Id first{push(ctx.U32[1], ctx.capture_first_member_index)};
const Id count{push(ctx.U32[1], ctx.capture_count_member_index)};
const Id slot{ctx.OpISub(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.capture_vertex_index), first)};
const Id zero{ctx.Constant(ctx.U64, u64{0})};
const Id wanted{ctx.OpLogicalAnd(ctx.U1, ctx.OpINotEqual(ctx.U1, address, zero), ctx.OpULessThan(ctx.U1, slot, count))};
const Id store_label{ctx.OpLabel()};
const Id end_label{ctx.OpLabel()};
ctx.OpSelectionMerge(end_label, spv::SelectionControlMask::MaskNone);
ctx.OpBranchConditional(wanted, store_label, end_label);
ctx.AddLabel(store_label);
const Id offset{ctx.OpIMul(ctx.U64, ctx.OpUConvert(ctx.U64, slot), ctx.Constant(ctx.U64, u64{16}))};
const Id at{ctx.OpIAdd(ctx.U64, address, offset)};
const Id position{ctx.OpLoad(ctx.F32[4], ctx.output_position)};
ctx.OpStore(ctx.OpConvertUToPtr(ctx.capture_pointer, at), position, spv::MemoryAccessMask::Aligned, 16U);
ctx.OpBranch(end_label);
ctx.AddLabel(end_label);
}
void SetFixedPipelinePointSize(EmitContext& ctx) {
if (ctx.runtime_info.fixed_state_point_size) {
const float point_size{*ctx.runtime_info.fixed_state_point_size};
@@ -151,6 +222,12 @@ void EmitEpilogue(EmitContext& ctx) {
!ctx.profile.support_native_ndc) {
ConvertDepthMode(ctx);
}
if (ctx.stage == Stage::VertexB || ctx.stage == Stage::TessellationEval) {
ScaleNoPerspectiveOutputs(ctx);
}
if (ctx.stage == Stage::VertexB && ctx.wants_capture) { // (after the depth's conversion: the position as drawn)
CapturePosition(ctx);
}
if (ctx.stage == Stage::Fragment) {
AlphaTest(ctx);
}
@@ -160,6 +237,7 @@ void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream) {
if (ctx.runtime_info.convert_depth_mode && !ctx.profile.support_native_ndc) {
ConvertDepthMode(ctx);
}
const ScaledOutputs scaled{ScaleNoPerspectiveOutputs(ctx)};
if (!ctx.profile.support_geometry_streams) {
throw NotImplementedException("Geometry streams");
} else if (stream.IsImmediate()) {
@@ -170,6 +248,7 @@ void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream) {
}
// Restore fixed pipeline point size after emitting the vertex
SetFixedPipelinePointSize(ctx);
RestoreNoPerspectiveOutputs(ctx, scaled);
}
void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream) {

View File

@@ -25,5 +25,15 @@ inline bool frag_nan_guard = false;
// the colour pass is then rejected in spots: holes showing the bright sky, blown up by bloom (the glowing flowers).
// On for every card but NVIDIA (vk_coopmat.cpp); RX_VK_NO_INVARIANT=1 off. From NX2navi patch 0007.
inline bool position_invariant = false;
// (hookshot) An out-of-bounds texel fetch answers zero, as NVIDIA's GPUs answer it (measured on an RTX 3090), rather than
// whatever the host's does (EmitImageFetch). Vulkan leaves it undefined without robustImageAccess; on AMD the ground fog's
// off-screen depth reads drew a pale box at the screen's edges. Every card but NVIDIA (gpu/vk/vk_vendor.h); RX_VK_FETCH_BOUNDS
inline bool fetch_bounds = false;
// (hookshot) and texel buffers' fetches too: only when robustBufferAccess2 is off (the Debug tab's Robust buffers Off, RX_VK_ROBUST=0,
// or a driver without it), which otherwise answers their out-of-bounds reads with zero already (vk_coopmat.cpp)
inline bool fetch_bounds_buffers = false;
// (hookshot) isnan tested on the value's bits (IsNan in emit_spirv_floating_point.cpp), not OpIsNan, for AMD's older Windows
// shader compiler (RX 5000 and RX 6000: gpu/vk/vk_vendor.h); RX_VK_NAN_BITS=0 or 1
inline bool nan_bits = false;
} // namespace Shader::Backend::SPIRV

View File

@@ -524,6 +524,12 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf
if (runtime_info.mesh_fallback || runtime_info.mesh_fallback_vertex) {
wants_mesh_fallback = true; // (before any DefineRescalingInputPushConstant, which is made once)
}
// (hookshot) a scene vertex stage's position capture: its members go in the one push block, so decided before it is made.
// Not with the render area's block (a second push block; full-screen passes, never the scene's geometry)
if (runtime_info.capture_position && stage == Stage::VertexB && !runtime_info.mesh_fallback_vertex &&
profile.unified_descriptor_binding && profile.support_int64 && !program.info.uses_render_area) {
wants_capture = true;
}
DefineCommonTypes(program.info);
DefineCommonConstants();
DefineInterfaces(program);
@@ -576,6 +582,21 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf
mesh_info = program.mesh;
DefineRescalingInputPushConstant();
}
if (wants_capture) { // (the store itself: EmitEpilogue, emit_spirv_special.cpp)
if (!Sirit::ValidId(U64)) {
AddCapability(spv::Capability::Int64);
U64 = Name(TypeInt(64, false), "u64");
}
AddCapability(spv::Capability::PhysicalStorageBufferAddresses);
AddExtension("SPV_KHR_physical_storage_buffer");
SetMemoryModel(spv::AddressingModel::PhysicalStorageBuffer64, spv::MemoryModel::GLSL450);
// (Vulkan's VertexIndex, base vertex included: the redraw draws the same indices with the same base)
capture_vertex_index = Sirit::ValidId(vertex_index)
? vertex_index
: DefineInput(*this, U32[1], true, spv::BuiltIn::VertexIndex);
capture_pointer = TypePointer(spv::StorageClass::PhysicalStorageBuffer, F32[4]);
program.info.captures_position = true;
}
DefineMesh(program);
DefineLocalMemory(program);
DefineSharedMemory(program);
@@ -592,6 +613,13 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf
DefineGlobalMemoryFunctions(program.info);
DefineRescalingInput(program.info);
DefineRenderArea(program.info);
// (the capture's push block, when nothing above made it. Not made before them: the block is made once, with the members
// wanted by then, and DefineGlobalMemoryFunctions asks for the page table's (wants_guest_pages) only as it runs. Made
// earlier, the block had no such member, the stage read the table's address from member 0, and the GPU was lost at the
// first frame in play)
if (wants_capture) {
DefineRescalingInputPushConstant();
}
}
EmitContext::~EmitContext() = default;
@@ -1603,6 +1631,14 @@ void EmitContext::DefineRescalingInputPushConstant() {
mesh_fallback_indirect_input_member_index = member_index++;
}
}
if (wants_capture) {
members.push_back(U64);
capture_address_member_index = member_index++;
members.push_back(U32[1]);
capture_first_member_index = member_index++;
members.push_back(U32[1]);
capture_count_member_index = member_index++;
}
const Id push_constant_struct{TypeStruct(std::span(members.data(), members.size()))};
Decorate(push_constant_struct, spv::Decoration::Block);
Name(push_constant_struct, "ResolutionInfo");
@@ -1641,6 +1677,14 @@ void EmitContext::DefineRescalingInputPushConstant() {
MESH_FALLBACK_INDIRECT_INPUT_PUSH_OFFSET);
}
}
if (wants_capture) {
MemberDecorate(push_constant_struct, capture_address_member_index, spv::Decoration::Offset, CAPTURE_PUSH_OFFSET);
MemberDecorate(push_constant_struct, capture_first_member_index, spv::Decoration::Offset, CAPTURE_FIRST_PUSH_OFFSET);
MemberDecorate(push_constant_struct, capture_count_member_index, spv::Decoration::Offset, CAPTURE_COUNT_PUSH_OFFSET);
MemberName(push_constant_struct, capture_address_member_index, "capture_address");
MemberName(push_constant_struct, capture_first_member_index, "capture_first");
MemberName(push_constant_struct, capture_count_member_index, "capture_count");
}
const Id pointer_type{TypePointer(spv::StorageClass::PushConstant, push_constant_struct)};
rescaling_push_constants = AddGlobalVariable(pointer_type, spv::StorageClass::PushConstant);
Name(rescaling_push_constants, "rescaling_push_constants");
@@ -2017,6 +2061,12 @@ void EmitContext::DefineImages(const Info& info, u32& binding, u32& scaling_inde
void EmitContext::DefineInputs(const IR::Program& program) {
const Info& info{program.info};
const VaryingState loads{info.loads.mask | info.passthrough.mask};
const bool noperspective_as_smooth{
stage == Stage::Fragment && runtime_info.scaled_noperspective_inputs &&
std::ranges::any_of(info.interpolation,
[](Interpolation mode) {
return mode == Interpolation::NoPerspective;
})};
if (info.uses_workgroup_id) {
workgroup_id = DefineInput(*this, U32[3], false, spv::BuiltIn::WorkgroupId);
@@ -2084,7 +2134,8 @@ void EmitContext::DefineInputs(const IR::Program& program) {
layer = DefineInput(*this, U32[1], false, spv::BuiltIn::Layer);
Decorate(layer, spv::Decoration::Flat);
}
if (loads.AnyComponent(IR::Attribute::PositionX)) {
if (loads.AnyComponent(IR::Attribute::PositionX) ||
info.passthrough.AnyComponent(IR::Attribute::PositionX) || noperspective_as_smooth) {
const bool is_fragment{stage == Stage::Fragment};
if (!is_fragment && profile.has_broken_spirv_position_input) {
need_input_position_indirect = true;
@@ -2189,7 +2240,12 @@ void EmitContext::DefineInputs(const IR::Program& program) {
case Interpolation::Smooth:
break;
case Interpolation::NoPerspective:
Decorate(id, spv::Decoration::NoPerspective);
// The previous stage may write it times Position.w (noperspective_outputs).
if (!runtime_info.scaled_noperspective_inputs) {
Decorate(id, spv::Decoration::NoPerspective);
} else {
noperspective_as_smooth_inputs[index] = true;
}
break;
case Interpolation::Flat:
Decorate(id, spv::Decoration::Flat);

View File

@@ -369,6 +369,8 @@ public:
bool need_input_position_indirect{};
Id input_position{};
std::array<InputGenericInfo, 32> input_generics{};
/// Screen-linear fragment inputs read through perspective interpolation, times FragCoord.w.
std::array<bool, 32> noperspective_as_smooth_inputs{};
Id output_point_size{};
Id output_position{};
@@ -429,6 +431,13 @@ public:
u32 mesh_fallback_payload_member_index{};
u32 mesh_fallback_records_member_index{};
u32 mesh_fallback_indirect_input_member_index{};
/// (hookshot) RuntimeInfo::capture_position: the push block's capture members, the vertex index and a vec4 pointer type
bool wants_capture{};
u32 capture_address_member_index{};
u32 capture_first_member_index{};
u32 capture_count_member_index{};
Id capture_vertex_index{};
Id capture_pointer{};
/// A pointer to the u32 at a PhysicalStorageBuffer device address
Id MeshFallbackWord(Id address);