Skip to content
Open
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
33 changes: 30 additions & 3 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,10 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view
if (cache_hit) {
try {
Reader in{payload};
const auto physical_table_srvs = in.word();
auto vertex = decode(in.take(in.word()));
auto elements = vertex_layout(effective_layout(vertex), vertex);
return verified({std::move(vertex), decode(in.remaining), std::move(elements), targets});
return verified({std::move(vertex), decode(in.remaining), std::move(elements), targets, physical_table_srvs});
} catch (const UnsupportedComputeShader &) {
throw;
} catch (const std::runtime_error &) {
Expand Down Expand Up @@ -950,6 +951,7 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view
}
pair.input_layout = vertex_layout(effective_layout(pair.vertex), pair.vertex);
if (!root.empty()) {
const bool raw_fixed = fixed_entry && !reflected && a.substr(0, 4) != "DXBC" && b.substr(0, 4) != "DXBC";
for (auto *stage : {&pair.vertex, &pair.pixel}) {
const bool vertex = stage == &pair.vertex;
const auto visibility = vertex ? D3D12_SHADER_VISIBILITY_VERTEX : D3D12_SHADER_VISIBILITY_PIXEL;
Expand Down Expand Up @@ -981,15 +983,20 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view
const auto slot = binding.byte_offset / 32;
const auto kind =
compute_uav(binding.kind) ? D3D12_DESCRIPTOR_RANGE_TYPE_UAV : D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
uint64_t next = 0;
uint64_t next = 0, extent = 0;
bool found = false;
bool resource_table = false;
bool in_cbv = false;
for (unsigned i = 0; i < p.DescriptorTable.NumDescriptorRanges; ++i) {
const auto &range = p.DescriptorTable.pDescriptorRanges[i];
const uint64_t first =
range.OffsetInDescriptorsFromTableStart == D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND
? next
: range.OffsetInDescriptorsFromTableStart;
next = first + range.NumDescriptors;
extent = (std::max)(extent, next);
resource_table |= range.RangeType != D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
in_cbv |= first <= slot && slot < next && range.RangeType == D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
// Scalar buffer loads also consume CBV table records. The
// resolver supplies a raw SRV over the recorded CBV window.
if (first <= slot && slot < next && (kind == range.RangeType ||
Expand All @@ -1014,6 +1021,22 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view
found |= used;
}
apply_scalar_table_layout(binding, p.DescriptorTable);
// A raw fixed stage has the guest table address and uses physical
// byte offsets. The runtime must prove an outlying read against
// the bound heap record before using it. The declared range type
// does not reach the shader, so a texture read from a CBV range
// slot gets the same proof: the record must be a typed SRV.
if (!found && raw_fixed && resource_table && extent && (slot >= extent || in_cbv) &&
binding.shader_register < 32 && binding.array_count == 1) {
const bool fixed_buffer = binding.kind == ComputeViewKind::buffer_srv && !binding.dynamic_scalar_load &&
binding.required_bytes && binding.required_bytes <= (16u << 20);
const bool texture = binding.kind == ComputeViewKind::texture_srv &&
(binding.image_dimension <= 2 || binding.image_dimension == 5);
if (fixed_buffer || texture) {
pair.physical_table_srvs |= std::uint32_t{1} << binding.shader_register;
found = true;
}
}
if (!found)
throw UnsupportedComputeShader(std::string("graphics descriptor range does not cover resource: ") +
(vertex ? "VS" : "PS") + " root " + std::to_string(binding.root_parameter) +
Expand All @@ -1024,6 +1047,7 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view
if (write_cache && !cache.empty()) {
auto vertex = encode(pair.vertex);
payload.clear();
word(payload, pair.physical_table_srvs);
word(payload, static_cast<uint32_t>(vertex.size()));
payload += vertex;
payload += encode(pair.pixel);
Expand Down Expand Up @@ -1326,6 +1350,8 @@ std::optional<std::string> format_graphics_runtime_manifest(const DirectGraphics
} else {
return std::nullopt;
}
if (pair.physical_table_srvs & (std::uint32_t{1} << i))
srv_lines << "tablecheck " << i << ' ' << (b.kind == ComputeViewKind::buffer_srv ? b.required_bytes : 0) << '\n';
}
for (unsigned j = 0; j < uav_count; ++j) {
const auto &b = bindings.views[bindings.srv_count + j];
Expand Down Expand Up @@ -1363,7 +1389,8 @@ std::optional<std::string> format_graphics_runtime_manifest(const DirectGraphics
params = (std::max)(params, out.index / 4 + 1);

std::ostringstream out;
out << "x2w-manifest " << (fixed_stream ? 3 : uav_count ? 2 : 1) << "\nud " << (total_constants ? total_constants : 1u) << '\n';
const unsigned version = pair.physical_table_srvs ? 4 : fixed_stream ? 3 : uav_count ? 2 : 1;
out << "x2w-manifest " << version << "\nud " << (total_constants ? total_constants : 1u) << '\n';
for (const auto &e : pair.input_layout)
out << "fixedvb " << e.offset << ' ' << e.format << '\n';
if (!total_constants) {
Expand Down
3 changes: 3 additions & 0 deletions src/gfx1013_compute_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ struct ComputeViewBinding {
enum class ScalarTable { unknown, reflected_cbv, declared_cbv, srv };
ScalarTable scalar_table = ScalarTable::unknown;
bool requires_identity_dst_sel = false;
// A graphics scalar buffer load with an SGPR offset has no fixed byte bound.
bool dynamic_scalar_load = false;
};
inline bool runtime_root_buffer_uav(const ComputeViewBinding &binding) {
return binding.kind == ComputeViewKind::root_buffer_uav && binding.byte_offset == 0 &&
Expand Down Expand Up @@ -216,6 +218,7 @@ struct DirectGraphicsPair {
std::vector<NativeVertexElement> input_layout;
// GuestShaderStage::target_components of the pixel stage: the target types an RTV variant asked for.
std::array<unsigned char, 8> target_components{};
std::uint32_t physical_table_srvs = 0;
GraphicsConstantLayout constant_layout() const {
GraphicsConstantLayout layout;
for (auto *stage : {&vertex, &pixel})
Expand Down
9 changes: 7 additions & 2 deletions src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ struct DirectCompute {
}
std::set<std::pair<unsigned,unsigned>> read_write_raw_views;
string resource(const Inst &i, const State &s, unsigned base, ComputeViewKind kind, unsigned bytes,
unsigned *bound_register = nullptr, bool requires_identity_dst_sel = false) {
unsigned *bound_register = nullptr, bool requires_identity_dst_sel = false,
bool scalar_load = false) {
const auto &symbol = s.at(base);
const bool indexed = symbol.type == Symbol::Type::indexed_descriptor;
if (indexed && symbol.value == compute_resource_heap)
Expand All @@ -544,6 +545,9 @@ struct DirectCompute {
if (requires_identity_dst_sel)
for (unsigned j = 0; j < count; ++j)
it[j].requires_identity_dst_sel = true;
if (graphics_input && scalar_load && (i.b >> 25) != 125)
for (unsigned j = 0; j < count; ++j)
it[j].dynamic_scalar_load = true;
if (bound_register) *bound_register = it->shader_register;
const bool raw = kind == ComputeViewKind::raw_buffer_uav || kind == ComputeViewKind::buffer_srv ||
kind == ComputeViewKind::raw_vector_srv || kind == ComputeViewKind::byte_window_srv ||
Expand Down Expand Up @@ -995,7 +999,8 @@ struct DirectCompute {
refuse(i.pc, "scalar load exceeds synthesized descriptor byte bound");
h = root_buffer_handle(low.value, span);
} else
h = resource(i, s, i.src[0], ComputeViewKind::buffer_srv, so == 125 ? off + 4 * n : 4);
h = resource(i, s, i.src[0], ComputeViewKind::buffer_srv, so == 125 ? off + 4 * n : 4,
nullptr, false, true);
auto addr = so == 125 ? to_string(off)
: ir.binary("and", ir.binary("add", operand32(i, so, limit), to_string(off)), "4294967292");
for (unsigned j = 0; j < n; j += 4) {
Expand Down
Loading
Loading