mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
shader: reuse prepared binding offsets and shared resource switch
This commit is contained in:
@@ -288,7 +288,7 @@ uint32_t LoadSubwordInBounds(ValueEmitContext& ctx, const MemoryResourceAccess&
|
|||||||
|
|
||||||
uint32_t LoadWordPrepared(ValueEmitContext& ctx, const IR::Inst& inst, const IR::MemoryInfo& mem,
|
uint32_t LoadWordPrepared(ValueEmitContext& ctx, const IR::Inst& inst, const IR::MemoryInfo& mem,
|
||||||
const MemoryResourceAccess& resource) {
|
const MemoryResourceAccess& resource) {
|
||||||
const auto index = DwordIndex(ctx, inst, mem);
|
const auto index = DwordIndex(ctx, inst, mem, resource.byte_offset);
|
||||||
return EmitValueOrZeroIfCondition(
|
return EmitValueOrZeroIfCondition(
|
||||||
ctx.state, EmitMemoryElementInBounds(ctx.state, resource, index),
|
ctx.state, EmitMemoryElementInBounds(ctx.state, resource, index),
|
||||||
[&]() { return LoadWordInBounds(ctx, resource, index); });
|
[&]() { return LoadWordInBounds(ctx, resource, index); });
|
||||||
@@ -304,7 +304,7 @@ uint32_t LoadWord(ValueEmitContext& ctx, const IR::Inst& inst, IR::MemoryInfo me
|
|||||||
uint32_t LoadSubwordPrepared(ValueEmitContext& ctx, const IR::Inst& inst, const IR::MemoryInfo& mem,
|
uint32_t LoadSubwordPrepared(ValueEmitContext& ctx, const IR::Inst& inst, const IR::MemoryInfo& mem,
|
||||||
const MemoryResourceAccess& resource, uint32_t bits,
|
const MemoryResourceAccess& resource, uint32_t bits,
|
||||||
bool sign_extend) {
|
bool sign_extend) {
|
||||||
const auto address = ByteAddress(ctx, inst, mem);
|
const auto address = ByteAddress(ctx, inst, mem, resource.byte_offset);
|
||||||
const auto index = Binary(
|
const auto index = Binary(
|
||||||
ctx.state, spv::OpShiftRightLogical, TypeU32(ctx.state), address,
|
ctx.state, spv::OpShiftRightLogical, TypeU32(ctx.state), address,
|
||||||
ConstantU32(ctx.state, std::countr_zero(resource.element_bits / 8u)));
|
ConstantU32(ctx.state, std::countr_zero(resource.element_bits / 8u)));
|
||||||
@@ -466,7 +466,7 @@ void StoreSubwordInBounds(ValueEmitContext& ctx, const IR::MemoryInfo& mem,
|
|||||||
|
|
||||||
void StoreSubwordPrepared(ValueEmitContext& ctx, const IR::Inst& inst, const IR::MemoryInfo& mem,
|
void StoreSubwordPrepared(ValueEmitContext& ctx, const IR::Inst& inst, const IR::MemoryInfo& mem,
|
||||||
const MemoryResourceAccess& resource, uint32_t bits, uint32_t data) {
|
const MemoryResourceAccess& resource, uint32_t bits, uint32_t data) {
|
||||||
const auto address = ByteAddress(ctx, inst, mem);
|
const auto address = ByteAddress(ctx, inst, mem, resource.byte_offset);
|
||||||
const auto index = Binary(
|
const auto index = Binary(
|
||||||
ctx.state, spv::OpShiftRightLogical, TypeU32(ctx.state), address,
|
ctx.state, spv::OpShiftRightLogical, TypeU32(ctx.state), address,
|
||||||
ConstantU32(ctx.state, std::countr_zero(resource.element_bits / 8u)));
|
ConstantU32(ctx.state, std::countr_zero(resource.element_bits / 8u)));
|
||||||
@@ -603,22 +603,8 @@ void StoreWord(ValueEmitContext& ctx, const IR::Inst& inst, IR::MemoryInfo mem)
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto merge = state.builder.AllocateId();
|
EmitIndexSwitch(state, selected, buffer.indirect_resources.size(), 0u,
|
||||||
std::vector<uint32_t> labels(buffer.indirect_resources.size());
|
[&](uint32_t item) { store(buffer.indirect_resources[item]); });
|
||||||
std::vector<uint32_t> branches {spv::OpSwitch, selected, merge};
|
|
||||||
for (uint32_t i = 0; i < labels.size(); ++i) {
|
|
||||||
labels[i] = state.builder.AllocateId();
|
|
||||||
branches.push_back(i);
|
|
||||||
branches.push_back(labels[i]);
|
|
||||||
}
|
|
||||||
state.builder.AddFunction(spv::OpSelectionMerge, merge, spv::SelectionControlMaskNone);
|
|
||||||
state.builder.AddFunction(branches);
|
|
||||||
for (uint32_t i = 0; i < labels.size(); ++i) {
|
|
||||||
EmitLabel(state, labels[i]);
|
|
||||||
store(buffer.indirect_resources[i]);
|
|
||||||
state.builder.AddFunction(spv::OpBranch, merge);
|
|
||||||
}
|
|
||||||
EmitLabel(state, merge);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,7 +667,7 @@ PreparedFormattedMemory PrepareFormattedMemory(ValueEmitContext& ctx, const IR::
|
|||||||
PreparedFormattedMemory plan;
|
PreparedFormattedMemory plan;
|
||||||
plan.info = info;
|
plan.info = info;
|
||||||
plan.resource = resource;
|
plan.resource = resource;
|
||||||
const auto start = ByteAddress(ctx, inst, mem);
|
const auto start = ByteAddress(ctx, inst, mem, resource.byte_offset);
|
||||||
// Check the whole, unaligned format span before aligning the actual memory address.
|
// Check the whole, unaligned format span before aligning the actual memory address.
|
||||||
const auto end = Binary(ctx.state, spv::OpIAdd, TypeU32(ctx.state), start,
|
const auto end = Binary(ctx.state, spv::OpIAdd, TypeU32(ctx.state), start,
|
||||||
ConstantU32(ctx.state, info.byte_size - 1u));
|
ConstantU32(ctx.state, info.byte_size - 1u));
|
||||||
|
|||||||
Reference in New Issue
Block a user