Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2559,9 +2559,17 @@ uint32_t EmitAppendConsume(ValueEmitContext& ctx, const IR::Inst& inst) {
Binary(state, spv::OpINotEqual, TypeBool(state), count, ConstantU32(state, 0)),
bounds));
const auto atomic = EmitValueOrZeroIfCondition(state, condition, [&]() {
const auto pointer = EmitMemoryElementPointer(state, access, index);
const auto value = state.builder.AllocateId();
if (mem.kind == IR::ResourceKind::Lds && PrivateLdsStorage(state)) {
state.builder.AddFunction(spv::OpLoad, TypeU32(state), value, pointer);
state.builder.AddFunction(
spv::OpStore, pointer,
Binary(state, append ? spv::OpIAdd : spv::OpISub, TypeU32(state), value, count));
return value;
}
state.builder.AddFunction(append ? spv::OpAtomicIAdd : spv::OpAtomicISub, TypeU32(state),
value, EmitMemoryElementPointer(state, access, index),
value, pointer,
ConstantU32(state, mem.kind == IR::ResourceKind::Gds
? spv::ScopeDevice
: spv::ScopeWorkgroup),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ inline void ReportInvalid(const std::string& message, std::span<const uint32_t>
}
}

inline void Run(std::span<const uint32_t> original, uint8_t mode, uint8_t shape, std::string* refusal = nullptr) {
inline void Run(std::span<const uint32_t> original, uint8_t mode, uint8_t shape,
std::string* refusal = nullptr, bool* emitted = nullptr) {
if (emitted != nullptr) *emitted = false;
static const auto profile = Profile();
std::vector<uint32_t> storage(original.begin(), original.end());
if (std::getenv("KYTY_FUZZ_PAD") != nullptr) storage.resize(original.size() + 16u, 0u);
Expand Down Expand Up @@ -134,6 +136,7 @@ inline void Run(std::span<const uint32_t> original, uint8_t mode, uint8_t shape,
}
if (!IR::ResourceSpecializationFits(translated.program, specialization)) return;
auto compiled = Recompiler::CompileProgram(std::move(translated), options, specialization, 0);
if (emitted != nullptr) *emitted = !compiled.spirv.empty();
const char* policy = std::getenv("KYTY_FUZZ_SPIRV");
if (!compiled.spirv.empty() && policy != nullptr && std::strcmp(policy, "off") != 0 && policy[0] != 0) {
std::string message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ struct Case {
uint8_t mode;
uint8_t shape;
std::vector<uint32_t> words;
bool requires_spirv = false;
};

const std::vector<Case> Cases = {
{"lds-append-in-a-vertex-shader", 0x03, 0x00, {0xd8f80000u, 0u, 0xbf810000u}, true},
{"lds-consume-in-a-vertex-shader", 0x03, 0x00, {0xd8f40000u, 0u, 0xbf810000u}, true},
{"lds-append-in-a-pixel-shader", 0x04, 0x00, {0xd8f80000u, 0u, 0xbf810000u}, true},
{"lds-append-in-a-compute-shader", 0x02, 0x00, {0xd8f80000u, 0u, 0xbf810000u}, true},
{"lds-consume-in-a-compute-shader", 0x02, 0x00, {0xd8f40000u, 0u, 0xbf810000u}, true},
{"branch-target-outside-the-program", 0x00, 0x00, {0xbf827fffu, 0xbf810000u}},
{"stale-lane-spill-after-read-lane-elimination", 0x32, 0x00, {0xd7610014u, 0x0201e205u, 0xbf810000u}},
{"backward-branch-before-the-program", 0x00, 0x00, {0xbf828000u, 0xbf810000u}},
Expand Down Expand Up @@ -146,7 +152,12 @@ int main(int argc, char** argv) {
for (const auto& entry: Cases) {
if (argc >= 2 && std::string_view(argv[1]) != entry.name) continue;
found = true;
KytyFuzz::Run(entry.words, entry.mode, entry.shape);
bool emitted = false;
KytyFuzz::Run(entry.words, entry.mode, entry.shape, nullptr, &emitted);
if (entry.requires_spirv && !emitted) {
std::printf("%s: FAILED, did not emit SPIR-V\n", entry.name);
return 1;
}
std::printf("%s: ok\n", entry.name);
}
for (const auto& entry: Refusals) {
Expand Down
5 changes: 5 additions & 0 deletions docs/dev/debt/changes/fix-kyty-private-lds-append-consume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# kyty

## add Functional

- [DS_APPEND and DS_CONSUME in vertex and pixel shaders](../../../core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp) use per-invocation LDS, so their update is a load, addition or subtraction, and store. The console behavior of these instructions outside a compute workgroup is unmeasured. Closes when: compared with a PS5 shader or hardware oracle.
Loading