This commit is contained in:
lizzie 2026-01-25 02:28:34 +00:00 committed by crueter
parent 271695f020
commit e8f0fd8a69
7 changed files with 25 additions and 73 deletions

View File

@ -327,9 +327,9 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
return ctx.OpConvertSToF(ctx.F32[1], value);
case InputGenericLoadOp::UToF:
return ctx.OpConvertUToF(ctx.F32[1], value);
default:
case InputGenericLoadOp::None:
return value;
};
}
}();
}
switch (attr) {

View File

@ -200,10 +200,8 @@ Id GetAttributeType(EmitContext& ctx, AttributeType type) {
case AttributeType::Float:
return ctx.F32[4];
case AttributeType::SignedInt:
case AttributeType::SignedNorm:
return ctx.TypeVector(ctx.TypeInt(32, true), 4);
case AttributeType::UnsignedInt:
case AttributeType::UnsignedNorm:
return ctx.U32[4];
case AttributeType::SignedScaled:
return ctx.profile.support_scaled_attributes ? ctx.F32[4] : ctx.TypeVector(ctx.TypeInt(32, true), 4);
@ -219,10 +217,6 @@ InputGenericInfo GetAttributeInfo(EmitContext& ctx, AttributeType type, Id id) {
switch (type) {
case AttributeType::Float:
return InputGenericInfo{id, ctx.input_f32, ctx.F32[1], InputGenericLoadOp::None};
case AttributeType::UnsignedNorm:
return InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::UNorm};
case AttributeType::SignedNorm:
return InputGenericInfo{id, ctx.input_s32, ctx.TypeInt(32, true), InputGenericLoadOp::SNorm};
case AttributeType::UnsignedInt:
return InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::Bitcast};
case AttributeType::SignedInt:
@ -780,19 +774,9 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
return OpConvertSToF(F32[1], value);
case InputGenericLoadOp::UToF:
return OpConvertUToF(F32[1], value);
case InputGenericLoadOp::SNorm: {
Id const fp16_value = OpShiftRightArithmetic(U32[1], value, Const(16U));
Id const max_value = Const(unsigned(std::numeric_limits<s16>::max()));
return OpFDiv(F32[1], OpConvertSToF(F32[1], fp16_value), max_value);
}
case InputGenericLoadOp::UNorm: {
Id const fp16_value = OpShiftRightLogical(U32[1], value, Const(16U));
Id const max_value = Const(unsigned(std::numeric_limits<u16>::max()));
return OpFDiv(F32[1], OpConvertSToF(F32[1], fp16_value), max_value);
}
default:
case InputGenericLoadOp::None:
return value;
};
}
}()};
OpReturnValue(result);
++label_index;

View File

@ -143,8 +143,6 @@ enum class InputGenericLoadOp {
Bitcast,
SToF,
UToF,
SNorm,
UNorm,
};
struct InputGenericInfo {

View File

@ -18,8 +18,6 @@ namespace Shader {
enum class AttributeType : u8 {
Disabled,
SignedNorm,
UnsignedNorm,
SignedInt,
UnsignedInt,
SignedScaled,

View File

@ -105,27 +105,17 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
if (maxwell3d.dirty.flags[Dirty::VertexInput]) {
if (features.has_dynamic_vertex_input) {
// Dirty flag will be reset by the command buffer update
// 0u, // Invalid
// 1u, // SignedNorm
// 2u, // UnsignedNorm
// 3u, // SignedInt
// 4u, // UnsignedInt
// 5u, // UnsignedScaled
// 6u, // SignedScaled
// 7u, // Float
// We sparsely store the bits for each of them, so if they clash we don't deal
// with the fixed pipeline taking in invalid vertices! :)
const auto& attrs = regs.vertex_attrib_format;
attribute_types[0] = 0;
attribute_types[1] = 0;
attribute_types[2] = 0;
attribute_types = {0, 0, 0};
static_assert(Maxwell::NumVertexAttributes == 32);
for (size_t i = 0; i < Maxwell::NumVertexAttributes; ++i) {
u32 const mask = attrs[i].constant != 0 ? 0 : 0x07; // non-constant equates invalid
u32 const mask = attrs[i].constant != 0 ? 0 : 1; // non-constant equates invalid
u32 const type = u32(attrs[i].type.Value());
attribute_types[0] |= u64((type >> 0) & 1) << i;
attribute_types[1] |= u64((type >> 1) & 1) << i;
attribute_types[2] |= u64((type >> 2) & 1) << i;
attribute_types[0] |= u32((type >> 0) & mask) << i;
attribute_types[1] |= u32((type >> 1) & mask) << i;
attribute_types[2] |= u32((type >> 2) & mask) << i;
}
} else {
maxwell3d.dirty.flags[Dirty::VertexInput] = false;

View File

@ -278,8 +278,8 @@ struct FixedPipelineState {
return offsetof(FixedPipelineState, xfb_state);
}
u32 DynamicAttributeType(size_t i) const noexcept {
return u32((((attribute_types[0] >> i) & 1) << 0)
[[nodiscard]] inline Maxwell::VertexAttribute::Type DynamicAttributeType(size_t i) const noexcept {
return Maxwell::VertexAttribute::Type((((attribute_types[0] >> i) & 1) << 0)
| (((attribute_types[1] >> i) & 1) << 1)
| (((attribute_types[2] >> i) & 1) << 2));
}

View File

@ -104,40 +104,22 @@ Shader::CompareFunction MaxwellToCompareFunction(Maxwell::ComparisonOp compariso
case Maxwell::ComparisonOp::Always_GL:
return Shader::CompareFunction::Always;
}
UNIMPLEMENTED_MSG("Unimplemented comparison op={}", comparison);
UNIMPLEMENTED_MSG("op={}", comparison);
return {};
}
Shader::AttributeType CastAttributeType(const FixedPipelineState::VertexAttribute& attr) {
if (attr.enabled == 0) {
return Shader::AttributeType::Disabled;
}
switch (attr.Type()) {
case Maxwell::VertexAttribute::Type::UnusedEnumDoNotUseBecauseItWillGoAway:
ASSERT(false && "Invalid vertex attribute type!");
return Shader::AttributeType::Disabled;
case Maxwell::VertexAttribute::Type::SNorm: return Shader::AttributeType::SignedNorm;
case Maxwell::VertexAttribute::Type::UNorm: return Shader::AttributeType::UnsignedNorm;
case Maxwell::VertexAttribute::Type::Float: return Shader::AttributeType::Float;
case Maxwell::VertexAttribute::Type::SInt: return Shader::AttributeType::SignedInt;
Shader::AttributeType MaxwellToAttributeType(Maxwell::VertexAttribute::Type type) noexcept {
switch (type) {
case Maxwell::VertexAttribute::Type::UnusedEnumDoNotUseBecauseItWillGoAway: return Shader::AttributeType::Disabled;
case Maxwell::VertexAttribute::Type::UInt: return Shader::AttributeType::UnsignedInt;
case Maxwell::VertexAttribute::Type::SInt: return Shader::AttributeType::SignedInt;
case Maxwell::VertexAttribute::Type::UScaled: return Shader::AttributeType::UnsignedScaled;
case Maxwell::VertexAttribute::Type::SScaled: return Shader::AttributeType::SignedScaled;
}
return Shader::AttributeType::Float;
case Maxwell::VertexAttribute::Type::Float: return Shader::AttributeType::Float;
case Maxwell::VertexAttribute::Type::UNorm: return Shader::AttributeType::Float;
case Maxwell::VertexAttribute::Type::SNorm: return Shader::AttributeType::Float;
}
Shader::AttributeType AttributeType(const FixedPipelineState& state, size_t index) {
switch (state.DynamicAttributeType(index)) {
case 0: return Shader::AttributeType::Disabled;
case 1: return Shader::AttributeType::SignedNorm;
case 2: return Shader::AttributeType::UnsignedNorm;
case 3: return Shader::AttributeType::SignedInt;
case 4: return Shader::AttributeType::UnsignedInt;
case 5: return Shader::AttributeType::UnsignedScaled;
case 6: return Shader::AttributeType::SignedScaled;
case 7: return Shader::AttributeType::Float;
}
UNIMPLEMENTED_MSG("op={}", index);
return Shader::AttributeType::Disabled;
}
@ -179,12 +161,12 @@ Shader::RuntimeInfo MakeRuntimeInfo(std::span<const Shader::IR::Program> program
info.convert_depth_mode = gl_ndc;
}
if (key.state.dynamic_vertex_input) {
for (size_t index = 0; index < Maxwell::NumVertexAttributes; ++index) {
info.generic_input_types[index] = AttributeType(key.state, index);
}
for (size_t i = 0; i < Maxwell::NumVertexAttributes; ++i)
info.generic_input_types[i] = MaxwellToAttributeType(key.state.DynamicAttributeType(i));
} else {
std::ranges::transform(key.state.attributes, info.generic_input_types.begin(),
&CastAttributeType);
std::ranges::transform(key.state.attributes, info.generic_input_types.begin(), [](auto const attr) {
return attr.enabled ? MaxwellToAttributeType(attr.Type()) : Shader::AttributeType::Disabled;
});
}
break;
case Shader::Stage::TessellationEval: