shader: share formatted loads and support packed D16 XYZW buffers

Co-authored-by: fxpw <fxpw@outlook.com>
This commit is contained in:
nmzik
2026-10-14 04:09:57 +02:00
parent 1905b28b3c
commit 6abfe3bbe4
8 changed files with 170 additions and 40 deletions
@@ -1534,14 +1534,23 @@ void ApplyResourceSpecialization(Program& program, const ResourceSpecialization&
if (memory.formatted && !memory.typed) {
const auto& buffer = buffers[memory.resource];
const auto format = Format::GetFormatInfo(buffer.descriptor_format);
for (uint32_t component = 0; component < count; component++) {
const bool d16 = memory.data_bits == 16u;
const auto components = d16 ? memory.component_count : count;
std::array<uint32_t, 4> constants {};
for (uint32_t component = 0; component < components; component++) {
if (format.type == Format::ComponentType::Unknown ||
GetDstSel(buffer.descriptor_swizzle, component) != 1u) continue;
const auto one = Format::FormattedConstantBits(
auto one = Format::FormattedConstantBits(
format, Format::FormattedSourceKind::One);
if (d16 && one == 0x3f800000u) one = 0x3c00u;
constants[d16 ? component / 2u : component] |=
one << (d16 ? (component % 2u) * 16u : 0u);
}
for (uint32_t component = 0; component < count; component++) {
if (constants[component] == 0u) continue;
values[component] = Value(&*block->PrependNewInst(
it, ValueOpcode::SelectU32,
{inst.Arg(inst.NumArgs() - 1), Value(one), Value(0u)}));
{inst.Arg(inst.NumArgs() - 1), Value(constants[component]), Value(0u)}));
}
}
Value result = values[0];