shader: Address feedback

This commit is contained in:
FernandoS27 2021-04-03 02:34:07 +02:00 committed by ameerj
parent 80df541a08
commit ed6a1b1a3d
3 changed files with 16 additions and 13 deletions

View file

@ -25,7 +25,13 @@ enum class FpRounding : u8 {
RZ, // Round towards zero RZ, // Round towards zero
}; };
enum class MemoryScope : u32 { DontCare, Warp, Workgroup, Device, System }; enum class MemoryScope : u32 {
DontCare,
Warp,
Workgroup,
Device,
System,
};
struct FpControl { struct FpControl {
bool no_contraction{false}; bool no_contraction{false};

View file

@ -46,7 +46,9 @@ using StorageBufferSet =
using StorageInstVector = boost::container::small_vector<StorageInst, 24>; using StorageInstVector = boost::container::small_vector<StorageInst, 24>;
using VisitedBlocks = boost::container::flat_set<IR::Block*, std::less<IR::Block*>, using VisitedBlocks = boost::container::flat_set<IR::Block*, std::less<IR::Block*>,
boost::container::small_vector<IR::Block*, 4>>; boost::container::small_vector<IR::Block*, 4>>;
using StorageWritesMap = std::map<StorageBufferAddr, bool>; using StorageWritesSet =
boost::container::flat_set<StorageBufferAddr, std::less<StorageBufferAddr>,
boost::container::small_vector<StorageBufferAddr, 16>>;
/// Returns true when the instruction is a global memory instruction /// Returns true when the instruction is a global memory instruction
bool IsGlobalMemory(const IR::Inst& inst) { bool IsGlobalMemory(const IR::Inst& inst) {
@ -266,7 +268,7 @@ std::optional<StorageBufferAddr> Track(IR::Block* block, const IR::Value& value,
/// Collects the storage buffer used by a global memory instruction and the instruction itself /// Collects the storage buffer used by a global memory instruction and the instruction itself
void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageBufferSet& storage_buffer_set, void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageBufferSet& storage_buffer_set,
StorageInstVector& to_replace, StorageWritesMap& writes_map) { StorageInstVector& to_replace, StorageWritesSet& writes_set) {
// NVN puts storage buffers in a specific range, we have to bias towards these addresses to // NVN puts storage buffers in a specific range, we have to bias towards these addresses to
// avoid getting false positives // avoid getting false positives
static constexpr Bias nvn_bias{ static constexpr Bias nvn_bias{
@ -295,12 +297,8 @@ void CollectStorageBuffers(IR::Block& block, IR::Inst& inst, StorageBufferSet& s
} }
} }
// Collect storage buffer and the instruction // Collect storage buffer and the instruction
const bool is_a_write{IsGlobalMemoryWrite(inst)}; if (IsGlobalMemoryWrite(inst)) {
auto it{writes_map.find(*storage_buffer)}; writes_set.insert(*storage_buffer);
if (it == writes_map.end()) {
writes_map[*storage_buffer] = is_a_write;
} else {
it->second = it->second || is_a_write;
} }
storage_buffer_set.insert(*storage_buffer); storage_buffer_set.insert(*storage_buffer);
to_replace.push_back(StorageInst{ to_replace.push_back(StorageInst{
@ -375,14 +373,14 @@ void Replace(IR::Block& block, IR::Inst& inst, const IR::U32& storage_index,
void GlobalMemoryToStorageBufferPass(IR::Program& program) { void GlobalMemoryToStorageBufferPass(IR::Program& program) {
StorageBufferSet storage_buffers; StorageBufferSet storage_buffers;
StorageInstVector to_replace; StorageInstVector to_replace;
StorageWritesMap writes_map; StorageWritesSet writes_set;
for (IR::Block* const block : program.post_order_blocks) { for (IR::Block* const block : program.post_order_blocks) {
for (IR::Inst& inst : block->Instructions()) { for (IR::Inst& inst : block->Instructions()) {
if (!IsGlobalMemory(inst)) { if (!IsGlobalMemory(inst)) {
continue; continue;
} }
CollectStorageBuffers(*block, inst, storage_buffers, to_replace, writes_map); CollectStorageBuffers(*block, inst, storage_buffers, to_replace, writes_set);
} }
} }
Info& info{program.info}; Info& info{program.info};
@ -392,7 +390,7 @@ void GlobalMemoryToStorageBufferPass(IR::Program& program) {
.cbuf_index{storage_buffer.index}, .cbuf_index{storage_buffer.index},
.cbuf_offset{storage_buffer.offset}, .cbuf_offset{storage_buffer.offset},
.count{1}, .count{1},
.is_written{writes_map[storage_buffer]}, .is_written{writes_set.contains(storage_buffer)},
}); });
++storage_index; ++storage_index;
} }

View file

@ -275,7 +275,6 @@ void VisitInst(Pass& pass, IR::Block* block, IR::Inst& inst) {
case IR::Opcode::GetOFlag: case IR::Opcode::GetOFlag:
inst.ReplaceUsesWith(pass.ReadVariable(OverflowFlagTag{}, block)); inst.ReplaceUsesWith(pass.ReadVariable(OverflowFlagTag{}, block));
break; break;
break;
default: default:
break; break;
} }