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
92 changes: 43 additions & 49 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,7 @@ struct DeviceState {
// Cached physical-device no-attachment sample counts for D3D12_OPTIONS19.
UINT no_output_sample_counts = 0;
std::uint32_t f16_half_top_location = 29;
std::uint32_t bary_f16_half_top_location = 29;
leonida::BaryFallbackGsLimits bary_geometry_limits{};
float max_sampler_lod_bias = 0;
D3D12_CONSERVATIVE_RASTERIZATION_TIER conservative_raster_tier = D3D12_CONSERVATIVE_RASTERIZATION_TIER_NOT_SUPPORTED;
bool conservative_post_depth_coverage = false;
Expand Down Expand Up @@ -10984,6 +10984,7 @@ class PipelineState final
Stage& gs_stage = stages[1];
Stage& ps_stage = stages[2];
const bool bary_fallback = ps_stage.entry && ps_stage.entry->bary_fallback_location.has_value();
std::vector<std::uint32_t> bary_words;
if (bary_fallback) {
const int bary_loc = int(*ps_stage.entry->bary_fallback_location);
if (mesh) {
Expand All @@ -11008,21 +11009,40 @@ class PipelineState final
log_once("a --bary-fallback geometry stage takes triangles; topology type", desc.PrimitiveTopologyType);
return E_INVALIDARG;
}
leonida::BaryFallbackGsInfo bary_info{};
std::string bary_error;
// The VS may need its output locations rewritten before its VkShaderModule is created.
if (!leonida::link_bary_fallback_stages(
vs_stage.words, *vs_stage.entry, ps_stage.words, *ps_stage.entry, device_.f16_half_top_location,
device_.bary_geometry_limits, bary_words, &bary_info, &bary_error)) {
std::fprintf(stderr, "[rt] d3d12: %s (%s -> %s)\n", bary_error.c_str(),
vs_stage.entry->name.c_str(), ps_stage.entry->name.c_str());
return E_FAIL;
}
if (bary_info.clip_count && !device_.info.features.shaderClipDistance) {
return stream_unsupported(
"--bary-fallback geometry stage forwards ClipDistance, which needs shaderClipDistance; count",
int(bary_info.clip_count));
}
if (bary_info.cull_count && !device_.info.features.shaderCullDistance) {
return stream_unsupported(
"--bary-fallback geometry stage forwards CullDistance, which needs shaderCullDistance; count",
int(bary_info.cull_count));
}
}
if (vs_stage.entry && ps_stage.entry && !ps_stage.entry->f16_halves.empty() && gs_stage.entry) {
log_once("--f16-interp-fallback halves are linked VS->PS only; this PSO has a geometry shader", 0);
}
if (vs_stage.entry && ps_stage.entry && !gs_stage.entry &&
if (!bary_fallback && vs_stage.entry && ps_stage.entry && !gs_stage.entry &&
(!ps_stage.entry->f16_halves.empty() || !vs_stage.entry->f16_halves.empty())) {
std::string link_error;
if (!link_f16_halves(vs_stage.words, *vs_stage.entry, ps_stage.words, *ps_stage.entry,
&link_error, bary_fallback)) {
&link_error)) {
std::fprintf(stderr, "[rt] d3d12: %s\n", link_error.c_str());
return E_FAIL;
}
f16_linked_ = true;
}
bary_fallback_ = bary_fallback;
// A lazy pipeline keeps where each stage's words come from, not the words or a module: build() makes them
// again, the same way, and drops them once the pipeline exists.
lazy_ = lazy_graphics_pipelines();
Expand Down Expand Up @@ -11112,31 +11132,12 @@ class PipelineState final
stage_infos.push_back(info);
}
if (bary_fallback) { // the stage that supplies (1,0,0)/(0,1,0)/(0,0,1) at bary_fallback_input.location
std::vector<std::uint32_t> words;
leonida::BaryFallbackGsInfo bary_info{};
std::string bary_error;
if (!leonida::build_bary_fallback_gs(vs_stage.words, ps_stage.words,
*ps_stage.entry->bary_fallback_location, words, &bary_info,
&bary_error)) {
std::fprintf(stderr, "[rt] d3d12: %s\n", bary_error.c_str());
return E_FAIL;
}
if (bary_info.clip_count && !device_.info.features.shaderClipDistance) {
return stream_unsupported(
"--bary-fallback geometry stage forwards ClipDistance, which needs shaderClipDistance; count",
int(bary_info.clip_count));
}
if (bary_info.cull_count && !device_.info.features.shaderCullDistance) {
return stream_unsupported(
"--bary-fallback geometry stage forwards CullDistance, which needs shaderCullDistance; count",
int(bary_info.cull_count));
}
if (trace_pipeline_compile()) stage_bytes_ += words.size() * sizeof(std::uint32_t);
if (trace_pipeline_compile()) stage_bytes_ += bary_words.size() * sizeof(std::uint32_t);
VkShaderModule module = VK_NULL_HANDLE;
if (lazy_) {
sources_.push_back({StageSource::bary_fallback});
} else {
module = shader_module(words);
module = shader_module(bary_words);
if (!module) return E_FAIL;
}
VkPipelineShaderStageCreateInfo info{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO};
Expand Down Expand Up @@ -12165,10 +12166,8 @@ class PipelineState final

bool link_f16_halves(std::vector<std::uint32_t>& vs_words, const leonida::ShaderEntry& vs_entry,
std::vector<std::uint32_t>& ps_words, const leonida::ShaderEntry& ps_entry,
std::string* error, bool bary_fallback = false) const {
const std::uint32_t top_loc =
bary_fallback ? device_.bary_f16_half_top_location : device_.f16_half_top_location;
return leonida::link_f16_halves(vs_words, vs_entry, ps_words, ps_entry, error, top_loc);
std::string* error) const {
return leonida::link_f16_halves(vs_words, vs_entry, ps_words, ps_entry, error, device_.f16_half_top_location);
}

public:
Expand All @@ -12183,9 +12182,10 @@ class PipelineState final
return false;
}
words.assign(sources_.size(), {});
std::size_t vs = SIZE_MAX, ps = SIZE_MAX;
std::size_t vs = SIZE_MAX, ps = SIZE_MAX, bary = SIZE_MAX;
for (std::size_t i = 0; i < sources_.size(); ++i) {
const StageSource& source = sources_[i];
if (source.kind == StageSource::bary_fallback) bary = i;
if (source.kind != StageSource::library) continue;
words[i] = library->spirv(*source.entry);
if (words[i].empty()) {
Expand All @@ -12201,8 +12201,14 @@ class PipelineState final
}
if (f16_linked_) {
if (vs == SIZE_MAX || ps == SIZE_MAX ||
!link_f16_halves(words[vs], *sources_[vs].entry, words[ps], *sources_[ps].entry, &why,
bary_fallback_))
!link_f16_halves(words[vs], *sources_[vs].entry, words[ps], *sources_[ps].entry, &why))
return false;
}
if (bary != SIZE_MAX) {
if (vs == SIZE_MAX || ps == SIZE_MAX ||
!leonida::link_bary_fallback_stages(
words[vs], *sources_[vs].entry, words[ps], *sources_[ps].entry, device_.f16_half_top_location,
device_.bary_geometry_limits, words[bary], nullptr, &why))
return false;
}
for (std::size_t i = 0; i < sources_.size(); ++i) {
Expand All @@ -12215,12 +12221,6 @@ class PipelineState final
if (sources_[i].kind == StageSource::rect_list) {
if (vs == SIZE_MAX) return false;
words[i] = leonida::rect_list_geometry(words[vs], why);
} else if (sources_[i].kind == StageSource::bary_fallback) {
if (vs == SIZE_MAX || ps == SIZE_MAX || !sources_[ps].entry->bary_fallback_location ||
!leonida::build_bary_fallback_gs(words[vs], words[ps],
*sources_[ps].entry->bary_fallback_location, words[i], nullptr,
&why))
return false;
} else if (sources_[i].kind == StageSource::depth_only) {
words[i] = leonida::depth24_depth_only_fragment(depth24_bias_);
} else {
Expand Down Expand Up @@ -12265,9 +12265,8 @@ class PipelineState final
const leonida::ShaderEntry* compute_entry_ = nullptr; // compute: the translated shader build_compute reads
bool compute_failed_ = false; // compute: could not be built; not retried
std::atomic<bool> skip_logged_{false}; // compute: the skipped program's first dispatch was logged
bool lazy_ = false; // graphics: built at the first draw (lazy_graphics_pipelines)
bool f16_linked_ = false; // graphics: the VS and PS words had their f16 halves linked
bool bary_fallback_ = false; // graphics: synthesized --bary-fallback geometry stage
bool lazy_ = false; // graphics: built at the first draw (lazy_graphics_pipelines)
bool f16_linked_ = false; // graphics: the VS and PS words had their f16 halves linked without a geometry stage
leonida::Depth24Bias depth24_bias_{};
unsigned rgba4_mask_ = 0; // graphics: the B4G4R4A4 targets stored as RGBA8 that the pixel shader is quantised for
bool dual_source_ = false; // graphics: a SRC1 blend factor; the pixel shader's SV_Target1 is Location 0, Index 1
Expand Down Expand Up @@ -13579,14 +13578,9 @@ class Device final
? info.f16_half_top_location
: leonida::f16_half_top_location(
props.limits.maxVertexOutputComponents, props.limits.maxFragmentInputComponents);
state_.bary_f16_half_top_location = state_.f16_half_top_location;
if (info.f16_half_top_location == 0 &&
props.limits.maxGeometryInputComponents && props.limits.maxGeometryOutputComponents) {
state_.bary_f16_half_top_location = std::min(
state_.f16_half_top_location,
leonida::f16_half_top_location(props.limits.maxGeometryInputComponents,
props.limits.maxGeometryOutputComponents));
}
state_.bary_geometry_limits = {props.limits.maxGeometryInputComponents,
props.limits.maxGeometryOutputComponents,
props.limits.maxGeometryTotalOutputComponents};
}
if (const auto get_props2 = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2>(
info.get_instance_proc(info.instance, "vkGetPhysicalDeviceProperties2"))) {
Expand Down
Loading