mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(shader): fetch packed horizontal gather texels and cover edge coordinates
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -30,10 +30,7 @@ alignas(256) std::array<std::uint32_t, Threads * 4> Input{};
|
||||
alignas(256) std::array<std::uint32_t, Threads * 4> Output{};
|
||||
alignas(4096) std::array<std::uint8_t, 4096> Texels{};
|
||||
|
||||
// IMAGE_GATHER4H_PCK (MIMG opcode 0x62) with DMASK 0xF, VDATA v[8:11], VADDR v[4:5], image
|
||||
// descriptor s[8:15] and sampler descriptor s[16:19]. The words are the raw encoding because LLVM
|
||||
// has never accepted this mnemonic; see the RDNA2 ISA opcode table entry 98.
|
||||
alignas(256) constexpr std::array<std::uint32_t, 10> PckGather4h{
|
||||
alignas(256) std::array<std::uint32_t, 10> PckGather4h{
|
||||
0x34020084, 0xe0381000, 0x80000401, 0xbf8c3f70, 0xf1880f08, 0x00820804, 0xbf8c3f70, 0xe0781000,
|
||||
0x80010801, 0xbf810000,
|
||||
};
|
||||
@@ -55,8 +52,6 @@ std::array<std::uint32_t, 8> TextureDescriptor() {
|
||||
}
|
||||
|
||||
std::array<std::uint32_t, 4> SamplerDescriptor() {
|
||||
// Clamp-to-edge on all axes with FORCE_UNNORM clear, so coordinates are normalized sampling
|
||||
// coordinates, as the hardware applies to packed horizontal gathers (measured).
|
||||
return {(2u << 3u) | (2u << 6u), 0u, 0u, 0u};
|
||||
}
|
||||
|
||||
@@ -76,9 +71,22 @@ void FillTexels() {
|
||||
}
|
||||
|
||||
void FillInput() {
|
||||
constexpr std::array<std::array<float, 2>, 16> edges{{
|
||||
{0.03125f, 0.0f}, {0.09375f, 0.25f}, {0.53125f, 0.5f}, {0.96875f, 0.75f},
|
||||
{-0.25f, -0.3f}, {1.5f, 0.99f}, {0.4f, 1.0f}, {0.2f, 2.0f},
|
||||
{0.3f, 0.6f}, {0.7f, 0.1f}, {0.0f, -1.0f}, {1.0f, 0.5f},
|
||||
{0.0625f, 0.0f}, {0.15f, 0.375f}, {0.85f, 0.875f}, {-3.0f, 0.2f},
|
||||
}};
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
|
||||
Input[tid * 4u + 0u] = std::bit_cast<std::uint32_t>(static_cast<float>(tid % Width) / static_cast<float>(Width));
|
||||
Input[tid * 4u + 1u] = std::bit_cast<std::uint32_t>(static_cast<float>(tid % Height) / static_cast<float>(Height));
|
||||
float u = static_cast<float>(tid % Width) / static_cast<float>(Width);
|
||||
float v = static_cast<float>(tid % Height) / static_cast<float>(Height);
|
||||
if (tid >= Width) {
|
||||
u = edges[tid - Width][0];
|
||||
v = edges[tid - Width][1];
|
||||
if (tid % 2u == 1u && tid < Width + 4u) u = std::nextafter(u, -1.0f);
|
||||
}
|
||||
Input[tid * 4u + 0u] = std::bit_cast<std::uint32_t>(u);
|
||||
Input[tid * 4u + 1u] = std::bit_cast<std::uint32_t>(v);
|
||||
Input[tid * 4u + 2u] = 0u;
|
||||
Input[tid * 4u + 3u] = 0u;
|
||||
}
|
||||
@@ -86,7 +94,7 @@ void FillInput() {
|
||||
|
||||
std::uint32_t TexelBits(std::int32_t x, std::int32_t y) {
|
||||
const auto cx = static_cast<std::uint32_t>(std::clamp(x, 0, static_cast<int>(Width) - 1));
|
||||
const auto cy = static_cast<std::uint32_t>(y);
|
||||
const auto cy = static_cast<std::uint32_t>(std::max(y, 0));
|
||||
if (cy >= Height) {
|
||||
return 0u;
|
||||
}
|
||||
@@ -98,10 +106,7 @@ std::uint32_t TexelBits(std::int32_t x, std::int32_t y) {
|
||||
return bits;
|
||||
}
|
||||
|
||||
// The measured rule: window element k is at floor(u*width-0.5)+k-1 with DMASK bit i picking stream
|
||||
// word i of the four concatenated raw texels; rows at or past the height read zeros. Coordinates
|
||||
// are normalized sampling coordinates, as hardware applies to a sampler without FORCE_UNNORM.
|
||||
std::array<std::uint32_t, 4> Expected(std::uint32_t tid) {
|
||||
std::array<std::uint32_t, 4> Expected(std::uint32_t tid, std::uint32_t dmask) {
|
||||
const float u = std::bit_cast<float>(Input[tid * 4u + 0u]);
|
||||
const float v = std::bit_cast<float>(Input[tid * 4u + 1u]);
|
||||
const auto anchor = static_cast<std::int32_t>(std::floor(u * static_cast<float>(Width) - 0.5f));
|
||||
@@ -111,7 +116,12 @@ std::array<std::uint32_t, 4> Expected(std::uint32_t tid) {
|
||||
const auto bits = TexelBits(anchor + static_cast<std::int32_t>(element) - 1, row);
|
||||
stream[element] = bits;
|
||||
}
|
||||
return {stream[0], stream[1], stream[2], stream[3]};
|
||||
std::array<std::uint32_t, 4> selected{};
|
||||
std::uint32_t next = 0;
|
||||
for (std::uint32_t bit = 0; bit < 4u; ++bit) {
|
||||
if (((dmask >> bit) & 1u) != 0u) selected[next++] = stream[bit];
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
ShaderRecompiler::RecompileResult Compile(AgcDriver::VulkanDevice& device) {
|
||||
@@ -136,16 +146,17 @@ ShaderRecompiler::RecompileResult Compile(AgcDriver::VulkanDevice& device) {
|
||||
return ShaderRecompiler::Recompile(request);
|
||||
}
|
||||
|
||||
void Run(AgcDriver::VulkanDevice& device) {
|
||||
void Run(AgcDriver::VulkanDevice& device, std::uint32_t dmask) {
|
||||
PckGather4h[4] = 0xf1880008u | (dmask << 8u);
|
||||
Output.fill(0xdeadbeefu);
|
||||
const auto result = Compile(device);
|
||||
device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(PckGather4h.data()));
|
||||
device.WaitIdle();
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
|
||||
const auto expected = Expected(tid);
|
||||
for (std::uint32_t component = 0; component < 4u; ++component) {
|
||||
const auto expected = Expected(tid, dmask);
|
||||
for (std::uint32_t component = 0; component < static_cast<std::uint32_t>(std::popcount(dmask)); ++component) {
|
||||
const std::uint32_t actual = Output[tid * 4u + component];
|
||||
Require(actual == expected[component], std::string("packed horizontal gather: thread ") + std::to_string(tid) + " register " + std::to_string(component) + " is 0x" + std::to_string(actual) + ", expected 0x" + std::to_string(expected[component]));
|
||||
Require(actual == expected[component], std::string("packed horizontal gather: dmask ") + std::to_string(dmask) + " thread " + std::to_string(tid) + " register " + std::to_string(component) + " is 0x" + std::to_string(actual) + ", expected 0x" + std::to_string(expected[component]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +169,7 @@ int main() {
|
||||
if (!device) return VulkanTestSkipped;
|
||||
FillTexels();
|
||||
FillInput();
|
||||
Run(*device);
|
||||
for (const std::uint32_t dmask : {0xfu, 0x1u, 0x5u, 0xau, 0x8u}) Run(*device, dmask);
|
||||
std::puts("image packed horizontal gather tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -381,9 +381,6 @@ RdnaInstruction DecodeRdnaMimg(std::uint32_t programCounter, std::span<const std
|
||||
if (nsa == 0u && addressDwords > 256u - vaddr) {
|
||||
throw std::runtime_error("MIMG address register range overflow");
|
||||
}
|
||||
// Packed horizontal gathers write one VGPR per set DMASK bit (measured on gfx1031): the
|
||||
// window element for bit k lands in the k-th destination register, each holding the texel's
|
||||
// raw packed value. A zero mask still writes a single zero dword to vdst.
|
||||
const auto dataComponents = pckGather ? static_cast<std::uint32_t>(std::popcount(dmask)) : info.gather || msaaLoad ? 4u : static_cast<std::uint32_t>(std::popcount(dmask));
|
||||
const auto dataDwords = d16 ? (dataComponents + 1u) / 2u : dataComponents;
|
||||
const auto statusDwords = (word0 & 0x00010000u) != 0u ? 1u : 0u;
|
||||
|
||||
@@ -991,16 +991,6 @@ SampleSetup MakeSampleSetup(SpirvValueEmitContext& ctx, const ImageEmitAccess& a
|
||||
return {dimensionInfo, layout, access.image.numericClass, dref, coord};
|
||||
}
|
||||
|
||||
// IMAGE_GATHER4H_PCK on gfx1031, measured against the RX 6700 XT hardware oracle: the four
|
||||
// window texels are read raw and concatenated into a little-endian bitstream (window element k at
|
||||
// bit offset k*texelBits), and DMASK bit i writes stream word i to the next destination register.
|
||||
// The window anchor is floor(x-0.5) in texel space with elements at offsets -1, 0, +1, +2, clamped
|
||||
// horizontally into [0,width); the row is floor(y), negative rows clamp to row 0 and rows at or
|
||||
// past the height return zeros; sampler addressing modes do not affect the window. A format wider
|
||||
// than 32 bits per texel returns zeros in every register. Formats of 32 bits or less are rebuilt
|
||||
// from the sampled components, which reproduces the stored bits exactly for R8_UNORM, RG8_UNORM
|
||||
// and RGBA8 (measured). Coordinates follow the repo's normalized sampling convention: texel space
|
||||
// is coordinate times image size, matching how plain gathers reach the same window through Vulkan.
|
||||
void EmitPackedHorizontalGatherOp(SpirvValueEmitContext& ctx, const ImageEmitAccess& access) {
|
||||
auto& state = ctx.state;
|
||||
const auto& mem = access.mem;
|
||||
@@ -1008,143 +998,88 @@ void EmitPackedHorizontalGatherOp(SpirvValueEmitContext& ctx, const ImageEmitAcc
|
||||
if (dimension != RdnaImageDimension::Dim1D && dimension != RdnaImageDimension::Dim2D) {
|
||||
ctx.Fail(access.inst, "is a packed horizontal gather of an image dimension whose row and slice rules are not measured");
|
||||
}
|
||||
const auto layout = Layout(mem);
|
||||
if (layout.clamp != NoImageComponent || HasFlag(mem, RdnaImageSampleFlagCompare)) {
|
||||
if (Layout(mem).clamp != NoImageComponent || HasFlag(mem, RdnaImageSampleFlagCompare)) {
|
||||
ctx.Fail(access.inst, "is a packed horizontal gather with depth comparison or an LOD clamp, which is not implemented");
|
||||
}
|
||||
const auto& dimensionInfo = RdnaImageDimensionInfoFor(dimension);
|
||||
if (AddressDimension(access).coordinateComponents < dimensionInfo.coordinateComponents) {
|
||||
if (AddressDimension(access).coordinateComponents < RdnaImageDimensionInfoFor(dimension).coordinateComponents) {
|
||||
ctx.Fail(access.inst, "has an image address with too few coordinate components");
|
||||
}
|
||||
const auto info = PackedTexelFormat(ctx, access);
|
||||
std::uint32_t texelBits = 0;
|
||||
for (std::uint32_t component = 0; component < info.componentCount; component++) {
|
||||
const auto bits = info.componentBits[component];
|
||||
const bool exact = info.type == SpirvFormatComponentType::Uint || info.type == SpirvFormatComponentType::Sint || (info.type == SpirvFormatComponentType::Unorm && bits <= 16u) || (info.type == SpirvFormatComponentType::Float && bits == 32u);
|
||||
if (!exact) {
|
||||
ctx.Fail(access.inst, "reads packed texels of a format whose bits are not recoverable from the view");
|
||||
}
|
||||
texelBits += bits;
|
||||
texelBits += info.componentBits[component];
|
||||
}
|
||||
state.module.EmitCapability(spv::CapabilityImageQuery);
|
||||
const auto image = LoadSampledImageDescriptor(state, mem.resource, access.slot);
|
||||
const bool twoDimensional = dimension == RdnaImageDimension::Dim2D;
|
||||
const auto sizeType = twoDimensional ? TypeU32Vector(state, 2) : TypeU32(state);
|
||||
const auto size = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpImageQuerySizeLod, sizeType, size, image, ConstantU32(state, 0));
|
||||
const auto widthF32 = state.module.AllocateId();
|
||||
if (twoDimensional) {
|
||||
const auto width = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeExtract, TypeU32(state), width, size, 0u);
|
||||
state.module.AddFunction(spv::OpConvertUToF, TypeF32(state), widthF32, width);
|
||||
} else {
|
||||
state.module.AddFunction(spv::OpConvertUToF, TypeF32(state), widthF32, size);
|
||||
}
|
||||
const auto floorToInt = [&](std::uint32_t value) {
|
||||
const auto floored = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpExtInst, TypeF32(state), floored, GlslStd450(state), GLSLstd450Floor, value);
|
||||
return Unary(state, spv::OpConvertFToS, TypeI32(state), floored);
|
||||
};
|
||||
// Texel-space coordinates: the measured anchor is floor(u*width-0.5) with elements at -1..+2;
|
||||
// the row is floor(v*height), negative rows clamped to 0.
|
||||
const auto anchor = floorToInt(Binary(state, spv::OpFSub, TypeF32(state), Binary(state, spv::OpFMul, TypeF32(state), AddressF32(ctx, access, 0), widthF32), ConstantF32(state, 0x3f000000u)));
|
||||
std::uint32_t rowI32 = 0;
|
||||
std::uint32_t heightI32 = 0;
|
||||
if (twoDimensional) {
|
||||
const auto height = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeExtract, TypeU32(state), height, size, 1u);
|
||||
const auto heightF32 = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpConvertUToF, TypeF32(state), heightF32, height);
|
||||
const auto rowRaw = floorToInt(Binary(state, spv::OpFMul, TypeF32(state), AddressF32(ctx, access, 1), heightF32));
|
||||
rowI32 = Select(state, TypeI32(state), Binary(state, spv::OpSLessThan, TypeBool(state), rowRaw, ConstantI32(state, 0)), ConstantI32(state, 0), rowRaw);
|
||||
heightI32 = Unary(state, spv::OpBitcast, TypeI32(state), height);
|
||||
}
|
||||
const std::uint32_t sampledType = ImageVectorType(state, access.image.numericClass, info.componentCount);
|
||||
const auto componentType = ImageScalarType(state, access.image.numericClass);
|
||||
const auto sampledImage = MakeSampledImage(state, mem.resource, mem.sampler, access.slot);
|
||||
std::uint32_t streamWords[4] = {ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0)};
|
||||
std::uint32_t rowInside = 0;
|
||||
const bool twoDimensional = dimension == RdnaImageDimension::Dim2D;
|
||||
if (texelBits <= 32u) {
|
||||
std::uint32_t lastRowI32 = 0;
|
||||
state.module.EmitCapability(spv::CapabilityImageQuery);
|
||||
const auto image = LoadSampledImageDescriptor(state, mem.resource, access.slot);
|
||||
const auto size = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpImageQuerySizeLod, twoDimensional ? TypeI32Vector(state, 2) : TypeI32(state), size, image, ConstantU32(state, 0));
|
||||
const auto extent = [&](std::uint32_t axis) {
|
||||
if (!twoDimensional) {
|
||||
return size;
|
||||
}
|
||||
const auto value = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeExtract, TypeI32(state), value, size, axis);
|
||||
return value;
|
||||
};
|
||||
const auto texelFloor = [&](std::uint32_t address, std::uint32_t length, bool centre) {
|
||||
auto scaled = Binary(state, spv::OpFMul, TypeF32(state), AddressF32(ctx, access, address), Unary(state, spv::OpConvertSToF, TypeF32(state), length));
|
||||
state.module.AddAnnotation(spv::OpDecorate, scaled, spv::DecorationNoContraction);
|
||||
if (centre) {
|
||||
scaled = Binary(state, spv::OpFSub, TypeF32(state), scaled, ConstantF32(state, 0x3f000000u));
|
||||
}
|
||||
const auto floored = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpExtInst, TypeF32(state), floored, GlslStd450(state), GLSLstd450Floor, scaled);
|
||||
return Unary(state, spv::OpConvertFToS, TypeI32(state), floored);
|
||||
};
|
||||
const auto clampInto = [&](std::uint32_t value, std::uint32_t length) {
|
||||
const auto last = Binary(state, spv::OpISub, TypeI32(state), length, ConstantI32(state, 1));
|
||||
const auto low = Select(state, TypeI32(state), Binary(state, spv::OpSLessThan, TypeBool(state), value, ConstantI32(state, 0)), ConstantI32(state, 0), value);
|
||||
return Select(state, TypeI32(state), Binary(state, spv::OpSLessThan, TypeBool(state), last, low), last, low);
|
||||
};
|
||||
const auto width = extent(0u);
|
||||
const auto anchor = texelFloor(0u, width, true);
|
||||
std::uint32_t row = 0;
|
||||
if (twoDimensional) {
|
||||
const auto heightMinusOne = Binary(state, spv::OpISub, TypeI32(state), heightI32, ConstantI32(state, 1));
|
||||
lastRowI32 = Select(state, TypeI32(state), Binary(state, spv::OpSLessThan, TypeBool(state), heightMinusOne, ConstantI32(state, 0)), ConstantI32(state, 0), heightMinusOne);
|
||||
const auto height = extent(1u);
|
||||
const auto rawRow = texelFloor(1u, height, false);
|
||||
rowInside = Binary(state, spv::OpSLessThan, TypeBool(state), rawRow, height);
|
||||
row = clampInto(rawRow, height);
|
||||
}
|
||||
for (std::uint32_t element = 0; element < 4u; element++) {
|
||||
const auto offset = Binary(state, spv::OpIAdd, TypeI32(state), anchor, ConstantI32(state, static_cast<std::int32_t>(element) - 1));
|
||||
const auto clampedLow = Select(state, TypeI32(state), Binary(state, spv::OpSLessThan, TypeBool(state), offset, ConstantI32(state, 0)), ConstantI32(state, 0), offset);
|
||||
const auto lastColumn = Binary(state, spv::OpISub, TypeI32(state), Unary(state, spv::OpConvertFToS, TypeI32(state), widthF32), ConstantI32(state, 1));
|
||||
const auto texelX = Select(state, TypeI32(state), Binary(state, spv::OpSLessThan, TypeBool(state), lastColumn, clampedLow), lastColumn, clampedLow);
|
||||
std::vector<std::uint32_t> sampleWords{spv::OpImageSampleExplicitLod};
|
||||
const auto texel = state.module.AllocateId();
|
||||
sampleWords.push_back(sampledType);
|
||||
sampleWords.push_back(texel);
|
||||
sampleWords.push_back(sampledImage);
|
||||
if (!twoDimensional) {
|
||||
const auto coordF32 = Binary(state, spv::OpFDiv, TypeF32(state), Binary(state, spv::OpFAdd, TypeF32(state), Unary(state, spv::OpConvertSToF, TypeF32(state), texelX), ConstantF32(state, 0x3f000000u)), widthF32);
|
||||
sampleWords.push_back(coordF32);
|
||||
} else {
|
||||
const auto fetchRow = Select(state, TypeI32(state), Binary(state, spv::OpSLessThan, TypeBool(state), rowI32, heightI32), rowI32, lastRowI32);
|
||||
const auto coordX = Binary(state, spv::OpFDiv, TypeF32(state), Binary(state, spv::OpFAdd, TypeF32(state), Unary(state, spv::OpConvertSToF, TypeF32(state), texelX), ConstantF32(state, 0x3f000000u)), widthF32);
|
||||
const auto coord = state.module.AllocateId();
|
||||
// Recompute height as F32 for the row centering; reuse it for the coordinate pair.
|
||||
const auto heightForCoord = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeExtract, TypeU32(state), heightForCoord, size, 1u);
|
||||
const auto heightF32ForCoord = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpConvertUToF, TypeF32(state), heightF32ForCoord, heightForCoord);
|
||||
const auto coordYPair = Binary(state, spv::OpFDiv, TypeF32(state), Binary(state, spv::OpFAdd, TypeF32(state), Unary(state, spv::OpConvertSToF, TypeF32(state), fetchRow), ConstantF32(state, 0x3f000000u)), heightF32ForCoord);
|
||||
state.module.AddFunction(spv::OpCompositeConstruct, TypeF32Vector(state, 2), coord, coordX, coordYPair);
|
||||
sampleWords.push_back(coord);
|
||||
const auto column = clampInto(Binary(state, spv::OpIAdd, TypeI32(state), anchor, ConstantI32(state, static_cast<std::int32_t>(element) - 1)), width);
|
||||
std::uint32_t coord = column;
|
||||
if (twoDimensional) {
|
||||
coord = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeConstruct, TypeI32Vector(state, 2), coord, column, row);
|
||||
}
|
||||
sampleWords.push_back(spv::ImageOperandsLodMask);
|
||||
sampleWords.push_back(ZeroF32(state));
|
||||
state.module.AddFunction(sampleWords);
|
||||
std::uint32_t bitPosition = element * texelBits;
|
||||
for (std::uint32_t component = 0; component < info.componentCount; component++) {
|
||||
const auto bits = info.componentBits[component];
|
||||
const auto scalar = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeExtract, componentType, scalar, texel, component);
|
||||
std::uint32_t value;
|
||||
if (info.type == SpirvFormatComponentType::Unorm) {
|
||||
const auto scaled = Binary(state, spv::OpFMul, TypeF32(state), scalar, ConstantF32Value(state, static_cast<float>((1u << bits) - 1u)));
|
||||
value = Unary(state, spv::OpConvertFToU, TypeU32(state), Binary(state, spv::OpFAdd, TypeF32(state), scaled, ConstantF32Value(state, 0.5f)));
|
||||
} else {
|
||||
value = SampledComponentBits(ctx, scalar, access.image.numericClass);
|
||||
}
|
||||
if (bits < 32u) {
|
||||
value = Binary(state, spv::OpBitwiseAnd, TypeU32(state), value, ConstantU32(state, (1u << bits) - 1u));
|
||||
}
|
||||
const auto lowWord = bitPosition / 32u;
|
||||
const auto shift = bitPosition % 32u;
|
||||
if (shift == 0u) {
|
||||
streamWords[lowWord] = Binary(state, spv::OpBitwiseOr, TypeU32(state), streamWords[lowWord], value);
|
||||
} else {
|
||||
streamWords[lowWord] = Binary(state, spv::OpBitwiseOr, TypeU32(state), streamWords[lowWord], Binary(state, spv::OpShiftLeftLogical, TypeU32(state), value, ConstantU32(state, shift)));
|
||||
if (shift + bits > 32u && lowWord + 1u < 4u) {
|
||||
streamWords[lowWord + 1u] = Binary(state, spv::OpBitwiseOr, TypeU32(state), streamWords[lowWord + 1u], Binary(state, spv::OpShiftRightLogical, TypeU32(state), value, ConstantU32(state, 32u - shift)));
|
||||
}
|
||||
}
|
||||
bitPosition += bits;
|
||||
const auto color = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpImageFetch, ImageVectorType(state, access.image.numericClass, 4), color, image, coord, spv::ImageOperandsLodMask, ConstantI32(state, 0));
|
||||
const auto packed = PackedImageTexel(ctx, access, color);
|
||||
const auto bits = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeExtract, TypeU32(state), bits, packed, 0u);
|
||||
const auto position = element * texelBits;
|
||||
const auto word = position / 32u;
|
||||
const auto shift = position % 32u;
|
||||
streamWords[word] = Binary(state, spv::OpBitwiseOr, TypeU32(state), streamWords[word], shift == 0u ? bits : Binary(state, spv::OpShiftLeftLogical, TypeU32(state), bits, ConstantU32(state, shift)));
|
||||
if (shift != 0u && shift + texelBits > 32u) {
|
||||
streamWords[word + 1u] = Binary(state, spv::OpBitwiseOr, TypeU32(state), streamWords[word + 1u], Binary(state, spv::OpShiftRightLogical, TypeU32(state), bits, ConstantU32(state, 32u - shift)));
|
||||
}
|
||||
}
|
||||
}
|
||||
// DMASK bit i picks stream word i into the next destination register. Words past the stream and
|
||||
// every register of an out-of-range row are zero, as measured.
|
||||
std::uint32_t selected[4] = {ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0), ConstantU32(state, 0)};
|
||||
std::uint32_t nextRegister = 0;
|
||||
for (std::uint32_t bit = 0; bit < 4u && nextRegister < 4u; bit++) {
|
||||
std::uint32_t next = 0;
|
||||
for (std::uint32_t bit = 0; bit < 4u; bit++) {
|
||||
if (((mem.dmask >> bit) & 1u) == 0u) {
|
||||
continue;
|
||||
}
|
||||
const bool withinStream = texelBits <= 32u && bit * 32u < 4u * texelBits;
|
||||
std::uint32_t value = ConstantU32(state, 0);
|
||||
if (withinStream) {
|
||||
value = streamWords[bit];
|
||||
if (twoDimensional) {
|
||||
const auto rowOk = Binary(state, spv::OpSLessThan, TypeBool(state), rowI32, heightI32);
|
||||
value = Select(state, TypeU32(state), rowOk, value, ConstantU32(state, 0));
|
||||
}
|
||||
if (texelBits <= 32u) {
|
||||
selected[next] = rowInside != 0u ? Select(state, TypeU32(state), rowInside, streamWords[bit], ConstantU32(state, 0)) : streamWords[bit];
|
||||
}
|
||||
selected[nextRegister++] = value;
|
||||
next++;
|
||||
}
|
||||
const auto result = state.module.AllocateId();
|
||||
state.module.AddFunction(spv::OpCompositeConstruct, TypeU32Vector(state, 4), result, selected[0], selected[1], selected[2], selected[3]);
|
||||
|
||||
@@ -255,6 +255,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [libSceUlt queues](../../core/libs/prx/libSceUlt/Export.cpp) use preallocated host storage instead of the supplied guest work area; its existing size formula and the 512-byte object layouts remain unverified. Waiting-queue pool thread limits and waiter priority ordering are not implemented. Finalization wakes blocked queue callers with `ULT_ERROR_STATE`.
|
||||
- [Thread cancellation](../../core/libs/prx/libkernel/Pthread/src/Thread.cpp) (libkernel) is not modelled: `scePthreadCancel` throws, so no cancel request is ever pending and `scePthreadTestcancel` and `pthread_testcancel` return without acting; the cancel state and type set by `scePthreadSetcancelstate` and `scePthreadSetcanceltype` are stored and not used
|
||||
- [MIMG `tfe` and `lwe`](../../core/shader/recompiler/RdnaDecoder/src/RdnaImageOpDecoder.cpp) never write the status VGPR after the data. On hardware it is written only when a texel fetch hits an unmapped page of a partially resident texture, or, for `lwe` on sample/gather, when the LOD is below the T# `MIN_LOD_WARN`; texture memory is always resident here, the LOD warning (texture-streaming feedback, like the T# `MIN_LOD_WARN` itself) is never reported, and `lwe` on `image_get_lod` throws.
|
||||
- [Packed horizontal gathers](../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp) (`image_gather4h_pck`, MIMG opcode 98): the four window texels are read raw and concatenated into a little-endian bitstream, with DMASK bit i writing stream word i to the next destination register; measured on RDNA2 (gfx1031) at every edge: the anchor is floor(x-0.5) with elements at -1, 0, +1 and +2 clamped horizontally into the width, the row is floor(y), negative rows clamp to row 0, rows at or past the height return zeros, sampler addressing modes do not affect the window, and formats wider than 32 bits per texel write zeros in every register. The emitter fetches each window texel at LOD 0 and packs its bits like `image_load_pck`, so the sampler's filter, addressing and LOD state are not used; formats whose bits are not recoverable from the view and D16 data throw. The anchor and row multiply the normalized coordinate by the image size without contraction. The stream rule was measured for R8_UNORM, RG8_UNORM and RGBA8; only RGBA8 has an execution test. `image_gather8h_pck` (opcode 99) never returns texel data on this hardware - across dmasks 0x1 to 0xFF including the upper nibble, RGBA8, RGBA16 and RGBA32 formats, 1D, 2D and 3D descriptors and normalized and unnormalized sampling it only zero-fills popcount(dmask) registers (sentinel-prefilled destinations) - so it decodes but throws at translation; its eight-texel semantics remain unmeasured.
|
||||
- [Unnormalized S# coordinates](../../core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp) (libSceAgcDriver) - `FORCE_UNNORMALIZED` uses a Vulkan `unnormalizedCoordinates` sampler, so the S# LOD range, LOD bias and mip filter are not applied, which is exact only on a one-level view.
|
||||
- [Unnormalized S#s](../../core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp) are accepted only when direct and used only by explicit-LOD `image_sample` without offset, comparison, derivatives or `_a`, on a single-level, single-layer 1D or 2D view of mip 0, even when the image is also sampled through a normalized S#.
|
||||
- An [unnormalized S#](../../core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp) (libSceAgcDriver) throws with unequal minification and magnification filters, anisotropy, `TRUNC_COORD`, `MC_COORD_TRUNC` or X/Y clamping other than last-texel or border.
|
||||
@@ -341,4 +342,3 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [Guest path resolution](../../core/libs/prx/libc/src/General.cpp) falls back to ASCII case-insensitive component lookup, following [shadPS4's host filesystem](https://github.com/shadps4-emu/shadPS4/blob/945dbc3cc3eee80ac3e053b438502ed936fa6bb2/src/core/file_sys/backends/host_fs.cpp). PPSA03747 requests `Skyrim.INI`, `Data/Video` and lowercase archive/plugin names that differ from the dump's filenames. Exact host names take precedence; multiple fallback matches throw instead of selecting an arbitrary file. Existing parent names are resolved when creating a new file, and guest mount aliases use the same ASCII comparison. Results are not cached, so renames and newly created files remain visible. Unicode case folding and PS5 behaviour for case-colliding host entries are unverified; host roots are used as supplied.
|
||||
- [Static scalar calls](../../core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp) (`s_call_b64` and `s_swappc_b64`) require one call per ordinary even-aligned SGPR link pair (s0:s1 through s104:s105) and one later `s_setpc_b64` return reading that exact pair. Regions must nest or be disjoint; recursion, shared links, escaping link values (including overlapping tuples and resource descriptors), invalid targets, interleaved regions, cross-region branches or fall-through, relative SGPR reads and dynamic `s_setpc_b64` in a program with calls throw. The analysis checks all decoded instructions, including unreachable code. Arbitrary indirect calls and general call frames are not implemented.
|
||||
- [s_call_b64](../../core/shader/recompiler/Translation/src/ScalarInstructions.cpp) saves `PC + 4` over `GetShaderBase` and branches to `PC + 4 + signext(SIMM16) * 4`, following [AMD RDNA2 ISA](https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf) sections 3.6.3, 12.2 and 12.3. Forward callees after `s_endpgm` are decoded. Native RDNA2/PS5 execution and title compatibility for these bounded scalar calls remain unverified; `s_rfe_b64` still throws in translation.
|
||||
- [Packed horizontal gathers](../../core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp) (`image_gather4h_pck`, MIMG opcode 98): the four window texels are read raw and concatenated into a little-endian bitstream, with DMASK bit i writing stream word i to the next destination register; measured on RDNA2 (gfx1031) at every edge: the anchor is floor(x-0.5) with elements at -1, 0, +1 and +2 clamped horizontally into the width, the row is floor(y), negative rows clamp to row 0, rows at or past the height return zeros, sampler addressing modes do not affect the window, and formats wider than 32 bits per texel write zeros in every register. The emitter rebuilds formats of 32 bits or less from the sampled components, which reproduces the stored bits exactly for R8_UNORM, RG8_UNORM and RGBA8 (measured); D16 data and sub-32-bit packing throw. Coordinates follow the normalized sampling convention, coordinate times image size, as plain gathers do. `image_gather8h_pck` (opcode 99) never returns texel data on this hardware - across dmasks 0x1 to 0xFF including the upper nibble, RGBA8, RGBA16 and RGBA32 formats, 1D, 2D and 3D descriptors and normalized and unnormalized sampling it only zero-fills popcount(dmask) registers (sentinel-prefilled destinations) - so it decodes but throws at translation; its eight-texel semantics remain unmeasured.
|
||||
|
||||
Reference in New Issue
Block a user