From 0f3540b1ff24cd2fb1a795c7516c1fd364655a63 Mon Sep 17 00:00:00 2001 From: nmzik Date: Mon, 17 Aug 2026 02:23:47 +0200 Subject: [PATCH] shader: unify stage input metadata --- .../shader/recompiler/ShaderRecompiler.cpp | 41 +- .../shader/recompiler/ShaderRecompiler.h | 40 +- .../recompiler/backend/spirv/SpirvEmitter.cpp | 17 +- .../recompiler/backend/spirv/SpirvEmitter.h | 6 +- .../backend/spirv/spirvEmitterAnalysis.cpp | 14 +- .../backend/spirv/spirvEmitterExport.cpp | 13 +- .../backend/spirv/spirvEmitterInternal.h | 13 +- .../backend/spirv/spirvEmitterMemory.cpp | 2 +- .../backend/spirv/spirvEmitterModule.cpp | 49 +-- .../backend/spirv/spirvEmitterValueFlow.cpp | 12 +- .../frontend/translate/Translate.cpp | 6 +- .../ir/passes/ShaderInfoCollection.cpp | 45 +- src/graphics/shader/shader.cpp | 6 +- src/graphics/shader/shader.h | 6 + tests/ShaderRecompilerComputeTests.cpp | 17 +- tests/shaderCfgTests.cpp | 398 +++++++----------- 16 files changed, 278 insertions(+), 407 deletions(-) diff --git a/src/graphics/shader/recompiler/ShaderRecompiler.cpp b/src/graphics/shader/recompiler/ShaderRecompiler.cpp index f83b79f..ecac2ce 100644 --- a/src/graphics/shader/recompiler/ShaderRecompiler.cpp +++ b/src/graphics/shader/recompiler/ShaderRecompiler.cpp @@ -336,9 +336,6 @@ EmbeddedFetchData DetectEmbeddedVertexFetch(const Decoder::Program& decoded uint32_t user_data_base, uint32_t user_data_count, uint32_t wave_size) { EmbeddedFetchData data; - if (input_info == nullptr || !input_info->fetch_embedded) { - return data; - } data.loads.reserve(input_info->resources_num); int32_t offset_candidate = -1; bool offset_conflict = false; @@ -587,9 +584,6 @@ bool IsIrFetchPrologLoad(const IR::Instruction& inst) { int ResolveEmbeddedFetchResource(const ShaderVertexInputInfo* input_info, const EmbeddedFetchLoad& load) { - if (input_info == nullptr) { - return -1; - } if (load.attrib_id >= 0 && load.attrib_id < input_info->resources_num && input_info->resources_dst[load.attrib_id].attr_id == load.attrib_id) { return load.attrib_id; @@ -611,7 +605,7 @@ int ResolveEmbeddedFetchResource(const ShaderVertexInputInfo* input_info, uint32_t RewriteEmbeddedVertexFetches(IR::Program& ir, const ShaderVertexInputInfo* input_info, const std::vector& loads) { - if (input_info == nullptr || loads.empty()) { + if (loads.empty()) { return 0; } @@ -840,14 +834,20 @@ bool TryRecompile(std::span code, const CompileOptions& options, " elapsed_ms=%" PRIu64 "\n", GetDumpLabel(options), StageName(options.stage), options.shader_hash, static_cast(ir.blocks.size()), phase_ms()); + const ShaderVertexInputInfo* vertex = nullptr; + const ShaderPixelInputInfo* pixel = nullptr; + const ShaderComputeInputInfo* compute = nullptr; + switch (options.stage) { + case ShaderType::Vertex: vertex = options.input_info.vertex; break; + case ShaderType::Pixel: pixel = options.input_info.pixel; break; + case ShaderType::Compute: compute = options.input_info.compute; break; + default: break; + } EmbeddedFetchData embedded_fetch; - if (options.stage == ShaderType::Vertex && options.vertex_input_info != nullptr && - options.vertex_input_info->fetch_embedded) { - embedded_fetch = - DetectEmbeddedVertexFetch(decoded, options.vertex_input_info, ir.user_data_base, - ir.user_data_count, options.wave_size); - auto rewritten = - RewriteEmbeddedVertexFetches(ir, options.vertex_input_info, embedded_fetch.loads); + if (options.stage == ShaderType::Vertex && vertex->fetch_embedded) { + embedded_fetch = DetectEmbeddedVertexFetch(decoded, vertex, ir.user_data_base, + ir.user_data_count, options.wave_size); + auto rewritten = RewriteEmbeddedVertexFetches(ir, vertex, embedded_fetch.loads); if (rewritten > 0 || !embedded_fetch.loads.empty()) { LOGF("%s embedded vertex fetch rewrite: detected=%" PRIu64 " rewritten=%" PRIu32 "\n", GetDumpLabel(options), static_cast(embedded_fetch.loads.size()), @@ -859,15 +859,6 @@ bool TryRecompile(std::span code, const CompileOptions& options, ir.fallback_reason = dispatcher_reason; } - ShaderVertexInputInfo default_vertex {}; - ShaderPixelInputInfo default_pixel {}; - ShaderComputeInputInfo default_compute {}; - const auto* vertex = - options.vertex_input_info != nullptr ? options.vertex_input_info : &default_vertex; - const auto* pixel = - options.pixel_input_info != nullptr ? options.pixel_input_info : &default_pixel; - const auto* compute = - options.compute_input_info != nullptr ? options.compute_input_info : &default_compute; ir.values = std::make_shared(); if (!Frontend::TranslateProgram(ir, *ir.values, vertex, pixel, compute, error)) { return false; @@ -962,8 +953,8 @@ bool TryRecompile(std::span code, const CompileOptions& options, std::string emit_error; LOGF("%s phase begin: stage=%s hash=0x%016" PRIx64 " SPIR-V EmitProgram\n", GetDumpLabel(options), StageName(options.stage), options.shader_hash); - if (!Spirv::EmitProgram(ir, resources, options.vertex_input_info, options.pixel_input_info, - options.compute_input_info, spirv, &emit_error, options.dump_ir)) { + if (!Spirv::EmitProgram(ir, resources, options.input_info, spirv, &emit_error, + options.dump_ir)) { LOGF("%s typed SPIR-V emit failed: %s\n", GetDumpLabel(options), emit_error.c_str()); if (dispatcher_fallback && error != nullptr) { *error = fmt::format("dispatcher fallback failed after {}: {}", diff --git a/src/graphics/shader/recompiler/ShaderRecompiler.h b/src/graphics/shader/recompiler/ShaderRecompiler.h index a7b99bd..74c7d6c 100644 --- a/src/graphics/shader/recompiler/ShaderRecompiler.h +++ b/src/graphics/shader/recompiler/ShaderRecompiler.h @@ -13,27 +13,25 @@ namespace Libs::Graphics::ShaderRecompiler { struct CompileOptions { - ShaderType stage = ShaderType::Compute; - ShaderLaneMaskMode lane_mask_mode = ShaderLaneMaskMode::NativeWave; - uint32_t wave_size = 64; - uint32_t user_data_base = 0; - uint32_t user_data_count = 64; - uint64_t shader_hash = 0; - uint64_t shader_base = 0; - std::optional flat_memory_base; - uint32_t descriptor_set = 0; - uint32_t push_constant_offset = 0; - bool dump_ir = true; - bool early_dump = false; - const char* dump_label = nullptr; - const uint32_t* user_data = nullptr; - IR::SrtMemoryReader read_memory = nullptr; - IR::SrtMemoryReader read_specialization_memory = nullptr; - void* read_memory_data = nullptr; - const IR::ResourceSnapshot* resource_snapshot = nullptr; - const ShaderVertexInputInfo* vertex_input_info = nullptr; - const ShaderPixelInputInfo* pixel_input_info = nullptr; - const ShaderComputeInputInfo* compute_input_info = nullptr; + ShaderType stage = ShaderType::Compute; + ShaderLaneMaskMode lane_mask_mode = ShaderLaneMaskMode::NativeWave; + uint32_t wave_size = 64; + uint32_t user_data_base = 0; + uint32_t user_data_count = 64; + uint64_t shader_hash = 0; + uint64_t shader_base = 0; + std::optional flat_memory_base; + uint32_t descriptor_set = 0; + uint32_t push_constant_offset = 0; + bool dump_ir = true; + bool early_dump = false; + const char* dump_label = nullptr; + const uint32_t* user_data = nullptr; + IR::SrtMemoryReader read_memory = nullptr; + IR::SrtMemoryReader read_specialization_memory = nullptr; + void* read_memory_data = nullptr; + const IR::ResourceSnapshot* resource_snapshot = nullptr; + ShaderStageInputInfo input_info; }; struct CompileResult { diff --git a/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp b/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp index 03d2474..73b9a94 100644 --- a/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp @@ -316,10 +316,8 @@ bool ProgramRequiresExactSubgroupSize(const IR::Program& program) { } bool EmitProgram(const IR::Program& program, const IR::ResourceSnapshot& resources, - const ShaderVertexInputInfo* vertex_input_info, - const ShaderPixelInputInfo* pixel_input_info, - const ShaderComputeInputInfo* compute_input_info, std::vector& spirv, - std::string* error, bool preserve_debug_values) { + ShaderStageInputInfo input_info, std::vector& spirv, std::string* error, + bool preserve_debug_values) { using namespace Emitter; if (program.stage != ShaderType::Compute && program.stage != ShaderType::Vertex && @@ -345,21 +343,12 @@ bool EmitProgram(const IR::Program& program, const IR::ResourceSnapshot& resourc SetError(error, "SPIR-V emitter requires planned typed SSA"); return false; } - ShaderVertexInputInfo default_vertex {}; - ShaderPixelInputInfo default_pixel {}; - ShaderComputeInputInfo default_compute {}; - const auto* vertex = vertex_input_info != nullptr ? vertex_input_info : &default_vertex; - const auto* pixel = pixel_input_info != nullptr ? pixel_input_info : &default_pixel; - const auto* compute = compute_input_info != nullptr ? compute_input_info : &default_compute; (void)preserve_debug_values; const auto& value_program = *program.values; if (!IR::ValidateValueProgram(value_program, true, error)) { return false; } - EmitterState state(program, resources); - state.vertex_input_info = vertex; - state.pixel_input_info = pixel; - state.compute_input_info = compute; + EmitterState state(program, resources, input_info); state.stage = program.stage; state.wave_size = program.wave_size; state.per_invocation_masks = program.lane_mask_mode == ShaderLaneMaskMode::PerInvocation; diff --git a/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h b/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h index c7f20a9..8e478c9 100644 --- a/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h +++ b/src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.h @@ -12,10 +12,8 @@ namespace Libs::Graphics::ShaderRecompiler::Spirv { bool ProgramRequiresExactSubgroupSize(const IR::Program& program); bool EmitProgram(const IR::Program& program, const IR::ResourceSnapshot& resources, - const ShaderVertexInputInfo* vertex_input_info, - const ShaderPixelInputInfo* pixel_input_info, - const ShaderComputeInputInfo* compute_input_info, std::vector& spirv, - std::string* error, bool preserve_debug_values = false); + ShaderStageInputInfo input_info, std::vector& spirv, std::string* error, + bool preserve_debug_values = false); } // namespace Libs::Graphics::ShaderRecompiler::Spirv diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cpp index 091ae37..814abdc 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cpp @@ -7,11 +7,10 @@ namespace Libs::Graphics::ShaderRecompiler::Spirv::Emitter { uint32_t PixelParameterMappedLocation(const EmitterState& state, uint32_t attr) { - const auto* ps = state.pixel_input_info; - if (state.stage != ShaderType::Pixel || ps == nullptr) { + if (state.stage != ShaderType::Pixel) { return attr; } - return ShaderPixelParameterMappedLocation(*ps, attr); + return ShaderPixelParameterMappedLocation(*state.input_info.pixel, attr); } uint32_t PixelParameterLocation(const EmitterState& state, uint32_t attr) { @@ -22,16 +21,15 @@ uint32_t PixelParameterLocation(const EmitterState& state, uint32_t attr) { active_inputs[active_count++] = input.location; } } - return state.stage == ShaderType::Pixel && state.pixel_input_info != nullptr - ? ShaderPixelParameterLocation(*state.pixel_input_info, + return state.stage == ShaderType::Pixel + ? ShaderPixelParameterLocation(*state.input_info.pixel, {active_inputs.data(), active_count}, attr) : attr; } bool PixelParameterIsFlat(const EmitterState& state, uint32_t attr) { - const auto* ps = state.pixel_input_info; - return state.stage == ShaderType::Pixel && ps != nullptr && - ShaderPixelParameterIsFlat(*ps, attr); + return state.stage == ShaderType::Pixel && + ShaderPixelParameterIsFlat(*state.input_info.pixel, attr); } void SetError(std::string* error, const char* message) { diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterExport.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterExport.cpp index 87235fe..53a1271 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterExport.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterExport.cpp @@ -95,20 +95,19 @@ uint32_t EmitExportVec4U32(EmitterState& state, const IR::Instruction& inst) { } static bool MrtUsesUintOutput(const EmitterState& state, const IR::Instruction& inst) { - return inst.export_info.kind == IR::ExportTargetKind::Mrt && - state.pixel_input_info != nullptr && - inst.export_info.index < std::size(state.pixel_input_info->target_output_mode) && - state.pixel_input_info->target_output_mode[inst.export_info.index] == 7u; + return state.stage == ShaderType::Pixel && inst.export_info.kind == IR::ExportTargetKind::Mrt && + inst.export_info.index < std::size(state.input_info.pixel->target_output_mode) && + state.input_info.pixel->target_output_mode[inst.export_info.index] == 7u; } uint32_t ApplyMrtExportMapping(EmitterState& state, const IR::Instruction& inst, uint32_t value, uint32_t vector_type) { - if (inst.export_info.kind != IR::ExportTargetKind::Mrt || state.pixel_input_info == nullptr || - inst.export_info.index >= state.pixel_input_info->target_export_mapping.size()) { + if (state.stage != ShaderType::Pixel || inst.export_info.kind != IR::ExportTargetKind::Mrt || + inst.export_info.index >= state.input_info.pixel->target_export_mapping.size()) { return value; } - const auto mapping = state.pixel_input_info->target_export_mapping[inst.export_info.index]; + const auto mapping = state.input_info.pixel->target_export_mapping[inst.export_info.index]; if (mapping.IsIdentity()) { return value; } diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h index f9333b4..d9905e8 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h @@ -317,17 +317,16 @@ struct StorageImageDescriptors { }; struct EmitterState { - EmitterState(const IR::Program& program_, const IR::ResourceSnapshot& resources_) - : program(program_), resources(resources_) {} + EmitterState(const IR::Program& program_, const IR::ResourceSnapshot& resources_, + ShaderStageInputInfo input_info_) + : program(program_), resources(resources_), input_info(input_info_) {} Builder builder; const IR::Program& program; const IR::ResourceSnapshot& resources; - const ShaderVertexInputInfo* vertex_input_info = nullptr; - const ShaderPixelInputInfo* pixel_input_info = nullptr; - const ShaderComputeInputInfo* compute_input_info = nullptr; - ShaderType stage = ShaderType::Unknown; - uint32_t wave_size = 64; + ShaderStageInputInfo input_info; + ShaderType stage = ShaderType::Unknown; + uint32_t wave_size = 64; bool exact_subgroup_operations = false; bool per_invocation_masks = false; uint32_t void_type = 0; diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp index 6b240aa..7e69bee 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp @@ -496,7 +496,7 @@ uint32_t EmitLdsElementPointer(EmitterState& state, uint32_t index) { } uint32_t LdsDwordCount(const EmitterState& state) { - return state.needs_function_lds ? 8192u : state.compute_input_info->lds_size_dwords; + return state.stage == ShaderType::Compute ? state.input_info.compute->lds_size_dwords : 8192u; } uint32_t EmitLdsElementInBounds(EmitterState& state, uint32_t index) { diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp index b083623..de07e52 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp @@ -59,13 +59,12 @@ uint32_t ConstantF32Value(EmitterState& state, float value) { } VertexInputScalarKind VertexParameterScalarKind(const EmitterState& state, uint32_t location) { - if (state.stage != ShaderType::Vertex || state.vertex_input_info == nullptr || - location >= ShaderVertexInputInfo::RES_MAX || - location >= static_cast(state.vertex_input_info->resources_num)) { + if (state.stage != ShaderType::Vertex || location >= ShaderVertexInputInfo::RES_MAX || + location >= static_cast(state.input_info.vertex->resources_num)) { return VertexInputScalarKind::Float; } - switch (state.vertex_input_info->resources[location].Format()) { + switch (state.input_info.vertex->resources[location].Format()) { case Prospero::BufferFormat::k8UInt: case Prospero::BufferFormat::k16UInt: case Prospero::BufferFormat::k8_8UInt: @@ -92,12 +91,11 @@ VertexInputScalarKind VertexParameterScalarKind(const EmitterState& state, uint3 uint32_t VertexParameterComponentCount(const EmitterState& state, const InputBinding& input) { uint32_t count = input.component_count; - if (state.stage == ShaderType::Vertex && state.vertex_input_info != nullptr && - input.location < ShaderVertexInputInfo::RES_MAX && - input.location < static_cast(state.vertex_input_info->resources_num) && - state.vertex_input_info->resources_dst[input.location].registers_num > 0) { + if (state.stage == ShaderType::Vertex && input.location < ShaderVertexInputInfo::RES_MAX && + input.location < static_cast(state.input_info.vertex->resources_num) && + state.input_info.vertex->resources_dst[input.location].registers_num > 0) { count = static_cast( - state.vertex_input_info->resources_dst[input.location].registers_num); + state.input_info.vertex->resources_dst[input.location].registers_num); } return std::clamp(count, 1u, 4u); } @@ -177,9 +175,9 @@ uint32_t VertexParameterInputPointerType(const EmitterState& state, VertexInputS } static bool MrtUsesUintOutput(const EmitterState& state, uint32_t index) { - return state.stage == ShaderType::Pixel && state.pixel_input_info != nullptr && - index < std::size(state.pixel_input_info->target_output_mode) && - state.pixel_input_info->target_output_mode[index] == 7u; + return state.stage == ShaderType::Pixel && + index < std::size(state.input_info.pixel->target_output_mode) && + state.input_info.pixel->target_output_mode[index] == 7u; } void AllocateInputVariables(EmitterState& state) { @@ -260,8 +258,8 @@ void AddInputAnnotationsAndNames(EmitterState& state) { if (flat) { state.builder.AddAnnotation({OpDecorate, input.variable_id, DecorationFlat}); } - if (state.stage == ShaderType::Pixel && state.pixel_input_info != nullptr && - state.pixel_input_info->ps_no_perspective && !flat) { + if (state.stage == ShaderType::Pixel && state.input_info.pixel->ps_no_perspective && + !flat) { state.builder.AddAnnotation( {OpDecorate, input.variable_id, DecorationNoPerspective}); } @@ -521,15 +519,13 @@ void EmitHeaderAndTypes(EmitterState& state) { // contract prevents host compilers from treating synthesized IEEE values as finite. state.builder.AddExecutionMode({state.main_func, ExecutionModeSignedZeroInfNanPreserve, 32u}); if (state.stage == ShaderType::Compute) { - uint32_t local_x = state.needs_compute_derivatives ? 2u : 1u; - uint32_t local_y = state.needs_compute_derivatives ? 2u : 1u; - uint32_t local_z = 1u; - if (state.compute_input_info != nullptr) { - const auto* cs = state.compute_input_info; - local_x = cs->threads_num[0] != 0u ? cs->threads_num[0] : local_x; - local_y = cs->threads_num[1] != 0u ? cs->threads_num[1] : local_y; - local_z = cs->threads_num[2] != 0u ? cs->threads_num[2] : local_z; - } + uint32_t local_x = state.needs_compute_derivatives ? 2u : 1u; + uint32_t local_y = state.needs_compute_derivatives ? 2u : 1u; + uint32_t local_z = 1u; + const auto* cs = state.input_info.compute; + local_x = cs->threads_num[0] != 0u ? cs->threads_num[0] : local_x; + local_y = cs->threads_num[1] != 0u ? cs->threads_num[1] : local_y; + local_z = cs->threads_num[2] != 0u ? cs->threads_num[2] : local_z; state.builder.AddExecutionMode( {state.main_func, ExecutionModeLocalSize, local_x, local_y, local_z}); } @@ -538,10 +534,9 @@ void EmitHeaderAndTypes(EmitterState& state) { if (state.depth_variable != 0) { state.builder.AddExecutionMode({state.main_func, ExecutionModeDepthReplacing}); } - if (state.pixel_input_info != nullptr && state.pixel_input_info->ps_early_z && - !state.pixel_input_info->ps_pixel_kill_enable && - !state.pixel_input_info->ps_depth_export_enable && - !state.pixel_input_info->ps_sample_mask_export_enable) { + if (state.input_info.pixel->ps_early_z && !state.input_info.pixel->ps_pixel_kill_enable && + !state.input_info.pixel->ps_depth_export_enable && + !state.input_info.pixel->ps_sample_mask_export_enable) { state.builder.AddExecutionMode({state.main_func, ExecutionModeEarlyFragmentTests}); } } diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterValueFlow.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterValueFlow.cpp index cb383fa..3ce4e1f 100644 --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterValueFlow.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterValueFlow.cpp @@ -159,9 +159,9 @@ uint32_t EmitAttribute(ValueEmitContext& ctx, uint32_t attr, uint32_t chan) { } bool MrtUsesUint(const EmitterState& state, const IR::ExportInfo& exp) { - return exp.kind == IR::ExportTargetKind::Mrt && state.pixel_input_info != nullptr && - exp.index < std::size(state.pixel_input_info->target_output_mode) && - state.pixel_input_info->target_output_mode[exp.index] == 7u; + return state.stage == ShaderType::Pixel && exp.kind == IR::ExportTargetKind::Mrt && + exp.index < std::size(state.input_info.pixel->target_output_mode) && + state.input_info.pixel->target_output_mode[exp.index] == 7u; } uint32_t ExportRawComponent(ValueEmitContext& ctx, uint32_t vector, uint32_t component) { @@ -289,9 +289,9 @@ void EmitExport(ValueEmitContext& ctx, const IR::Inst& inst) { const bool uint_output = MrtUsesUint(state, exp); const auto vector_type = uint_output ? state.vec4_uint_type : state.vec4_float_type; auto value = ExportVector(ctx, data, exp, uint_output); - if (exp.kind == IR::ExportTargetKind::Mrt && state.pixel_input_info != nullptr && - exp.index < state.pixel_input_info->target_export_mapping.size()) { - const auto mapping = state.pixel_input_info->target_export_mapping[exp.index]; + if (state.stage == ShaderType::Pixel && exp.kind == IR::ExportTargetKind::Mrt && + exp.index < state.input_info.pixel->target_export_mapping.size()) { + const auto mapping = state.input_info.pixel->target_export_mapping[exp.index]; if (!mapping.IsIdentity()) { const auto mapped = state.builder.AllocateId(); state.builder.AddFunction({OpVectorShuffle, vector_type, mapped, value, value, diff --git a/src/graphics/shader/recompiler/frontend/translate/Translate.cpp b/src/graphics/shader/recompiler/frontend/translate/Translate.cpp index dc0f985..45188f4 100644 --- a/src/graphics/shader/recompiler/frontend/translate/Translate.cpp +++ b/src/graphics/shader/recompiler/frontend/translate/Translate.cpp @@ -863,7 +863,7 @@ bool TranslateProgram(const IR::Program& source, IR::ValueProgram& result, prologue.SetVccLo(IR::U32(IR::Value(0u))); prologue.SetVccHi(IR::U32(IR::Value(0u))); prologue.SetM0(IR::U32(IR::Value(0u))); - if (source.stage == ShaderType::Compute && compute_input_info != nullptr) { + if (source.stage == ShaderType::Compute) { const auto* cs = compute_input_info; const auto thread_ids = cs->thread_ids_num > 0 ? std::min(cs->thread_ids_num, 3u) : 0u; @@ -897,7 +897,7 @@ bool TranslateProgram(const IR::Program& source, IR::ValueProgram& result, prologue.BitwiseOr(prologue.BitwiseOr(wave_bits, IR::U32(IR::Value(waves))), first_bit)); } - } else if (source.stage == ShaderType::Pixel && pixel_input_info != nullptr) { + } else if (source.stage == ShaderType::Pixel) { const auto* ps = pixel_input_info; uint32_t reg = ps->ps_system_input_base; if (ps->ps_pos_x) { @@ -920,7 +920,7 @@ bool TranslateProgram(const IR::Program& source, IR::ValueProgram& result, prologue.SetVectorReg(static_cast(reg), builtin(IR::StageInputKind::FrontFacing)); } - } else if (source.stage == ShaderType::Vertex && vertex_input_info != nullptr) { + } else if (source.stage == ShaderType::Vertex) { prologue.SetVectorReg(static_cast(5), builtin(IR::StageInputKind::VertexIndex)); prologue.SetVectorReg(static_cast(8), diff --git a/src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp b/src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp index 51f7aaa..2afd810 100644 --- a/src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp +++ b/src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp @@ -42,24 +42,15 @@ bool ValidateOptions(const Program& program, const ShaderInfoOptions& options, s }; switch (program.stage) { case ShaderType::Vertex: - if (options.vertex == nullptr) { - return Fail("vertex shader info requires vertex metadata"); - } if (options.vertex->resources_num < 0 || options.vertex->resources_num > ShaderVertexInputInfo::RES_MAX) { return Fail("vertex resource count is out of range"); } return true; case ShaderType::Pixel: - if (options.pixel == nullptr) { - return Fail("pixel shader info requires pixel metadata"); - } return options.pixel->input_num <= std::size(options.pixel->interpolator_settings) || Fail("pixel input count is out of range"); case ShaderType::Compute: - if (options.compute == nullptr) { - return Fail("compute shader info requires compute metadata"); - } return (options.compute->thread_ids_num >= 0 && options.compute->thread_ids_num <= 3) || Fail("compute thread ID count is out of range"); default: return Fail("unsupported shader stage for info collection"); @@ -83,7 +74,7 @@ bool ValidateValueReferences(const Program& program, const ShaderInfoOptions& op return Fail("typed attribute reference is not constant"); } if (program.stage == ShaderType::Vertex && - (inst.Arg(1).U32() >= 4u || options.vertex == nullptr || + (inst.Arg(1).U32() >= 4u || inst.Arg(0).U32() >= static_cast(options.vertex->resources_num))) { return Fail("vertex input reference is out of range"); @@ -139,9 +130,6 @@ void CollectVertexInputs(const Program& program, const ShaderVertexInputInfo* ve ShaderInfo& info) { AddInput(info, StageInputKind::VertexIndex, 0, 1, "gl_VertexIndex"); AddInput(info, StageInputKind::InstanceIndex, 0, 1, "gl_InstanceIndex"); - if (vertex == nullptr) { - return; - } uint32_t used_components[ShaderVertexInputInfo::RES_MAX] = {}; for (const auto* block: program.values->blocks) { for (const auto& inst: *block) { @@ -163,9 +151,6 @@ void CollectVertexInputs(const Program& program, const ShaderVertexInputInfo* ve } void CollectPixelInputs(const ShaderPixelInputInfo* pixel, ShaderInfo& info) { - if (pixel == nullptr) { - return; - } if (pixel->HasPositionInput()) { AddInput(info, StageInputKind::FragCoord, 0, 4, "gl_FragCoord"); } @@ -178,19 +163,17 @@ void CollectPixelInputs(const ShaderPixelInputInfo* pixel, ShaderInfo& info) { } void CollectComputeInputs(const ShaderComputeInputInfo* compute, ShaderInfo& info) { - if (compute != nullptr) { - if (compute->group_id[0] || compute->group_id[1] || compute->group_id[2]) { - AddInput(info, StageInputKind::WorkgroupId, 0, 3, "gl_WorkGroupID"); - } - if (compute->thread_ids_num > 0) { - AddInput(info, StageInputKind::LocalInvocationId, 0, 3, "gl_LocalInvocationID"); - } - if (compute->thread_ids_num > 0 || compute->tg_size_en) { - AddInput(info, StageInputKind::LocalInvocationIndex, 0, 1, "gl_LocalInvocationIndex"); - } - if (compute->dispatch_thread_dimensions) { - AddInput(info, StageInputKind::GlobalInvocationId, 0, 3, "gl_GlobalInvocationID"); - } + if (compute->group_id[0] || compute->group_id[1] || compute->group_id[2]) { + AddInput(info, StageInputKind::WorkgroupId, 0, 3, "gl_WorkGroupID"); + } + if (compute->thread_ids_num > 0) { + AddInput(info, StageInputKind::LocalInvocationId, 0, 3, "gl_LocalInvocationID"); + } + if (compute->thread_ids_num > 0 || compute->tg_size_en) { + AddInput(info, StageInputKind::LocalInvocationIndex, 0, 1, "gl_LocalInvocationIndex"); + } + if (compute->dispatch_thread_dimensions) { + AddInput(info, StageInputKind::GlobalInvocationId, 0, 3, "gl_GlobalInvocationID"); } } @@ -238,11 +221,11 @@ void CollectOutputs(const Program& program, const ShaderPixelInputInfo* pixel, S } const auto& export_info = program.values->export_info[inst.Flags().index]; if (export_info.kind == ExportTargetKind::MrtZ) { - if (pixel != nullptr && (export_info.en & 0x1u) != 0 && + if (program.stage == ShaderType::Pixel && (export_info.en & 0x1u) != 0 && pixel->ps_depth_export_enable) { AddOutput(info, StageOutputKind::Depth, 0, 0, "gl_FragDepth"); } - if (pixel != nullptr && (export_info.en & 0x4u) != 0 && + if (program.stage == ShaderType::Pixel && (export_info.en & 0x4u) != 0 && pixel->ps_sample_mask_export_enable) { AddOutput(info, StageOutputKind::SampleMask, 0, 0, "gl_SampleMask"); } diff --git a/src/graphics/shader/shader.cpp b/src/graphics/shader/shader.cpp index 52cbe4a..a75877f 100644 --- a/src/graphics/shader/shader.cpp +++ b/src/graphics/shader/shader.cpp @@ -1455,7 +1455,7 @@ bool ShaderCompileSpirvVS(const HW::VertexShaderInfo& regs, const HW::ShaderRegi options.read_specialization_memory = ReadShaderGuestMemory; options.descriptor_set = 0; options.push_constant_offset = 0; - options.vertex_input_info = &input_info; + options.input_info.vertex = &input_info; options.dump_ir = ShaderRecompilerTextDumpEnabled(); options.early_dump = options.dump_ir; options.dump_label = "ShaderRecompiler VS"; @@ -1509,7 +1509,7 @@ bool ShaderCompileSpirvPS(const HW::PixelShaderInfo& regs, const HW::ShaderRegis options.read_specialization_memory = ReadShaderGuestMemory; options.descriptor_set = input_info.descriptor_set; options.push_constant_offset = input_info.push_constant_offset; - options.pixel_input_info = &input_info; + options.input_info.pixel = &input_info; options.dump_ir = ShaderRecompilerTextDumpEnabled(); options.early_dump = options.dump_ir; options.dump_label = "ShaderRecompiler PS"; @@ -1559,7 +1559,7 @@ bool ShaderCompileSpirvCS(const HW::ComputeShaderInfo& regs, const HW::ShaderReg options.read_specialization_memory = ReadShaderGuestMemory; options.descriptor_set = 0; options.push_constant_offset = 0; - options.compute_input_info = &input_info; + options.input_info.compute = &input_info; options.wave_size = input_info.wave_size; options.dump_ir = ShaderRecompilerTextDumpEnabled(); options.early_dump = options.dump_ir; diff --git a/src/graphics/shader/shader.h b/src/graphics/shader/shader.h index 7a0329c..224cf14 100644 --- a/src/graphics/shader/shader.h +++ b/src/graphics/shader/shader.h @@ -128,6 +128,12 @@ struct ShaderPixelInputInfo { bool HasPositionInput() const { return ps_pos_x || ps_pos_y || ps_pos_z || ps_pos_w; } }; +union ShaderStageInputInfo { + const ShaderVertexInputInfo* vertex; + const ShaderPixelInputInfo* pixel; + const ShaderComputeInputInfo* compute = nullptr; +}; + uint32_t ShaderPixelParameterMappedLocation(const ShaderPixelInputInfo& info, uint32_t input); uint32_t ShaderPixelParameterLocation(const ShaderPixelInputInfo& info, std::span active_inputs, uint32_t input); diff --git a/tests/ShaderRecompilerComputeTests.cpp b/tests/ShaderRecompilerComputeTests.cpp index feb1e80..a0c71f2 100644 --- a/tests/ShaderRecompilerComputeTests.cpp +++ b/tests/ShaderRecompilerComputeTests.cpp @@ -1065,7 +1065,7 @@ CompiledShader CompileCase(const TestCase &test) { ShaderRecompiler::CompileOptions options; options.stage = ShaderType::Compute; options.dump_ir = true; - options.compute_input_info = &test.compute_info; + options.input_info.compute = &test.compute_info; options.user_data = user_data.data(); options.read_memory = ReadTestMemory; options.read_memory_data = const_cast *>(&test.initial); @@ -1157,8 +1157,7 @@ CompiledShader CompileCase(const TestCase &test) { "offset-only shader data did not use its storage fallback"); std::vector storage_spirv; if (!ShaderRecompiler::Spirv::EmitProgram( - result.program, result.resources, nullptr, nullptr, - options.compute_input_info, storage_spirv, &error)) { + result.program, result.resources, options.input_info, storage_spirv, &error)) { Fail(test.name, "SPIR-V emit", error.c_str()); } result.spirv = std::move(storage_spirv); @@ -1231,7 +1230,7 @@ CompiledShader CompileFragmentCase(const GraphicsCase &test) { ShaderRecompiler::CompileOptions options; options.stage = ShaderType::Pixel; options.dump_ir = false; - options.pixel_input_info = &pixel_info; + options.input_info.pixel = &pixel_info; options.user_data = user_data.data(); ShaderRecompiler::CompileResult result; @@ -17149,8 +17148,8 @@ void CheckIndirectImageKeySwitch() { ShaderComputeInputInfo compute{}; std::vector spirv; Require(name, "SPIR-V emit", - ShaderRecompiler::Spirv::EmitProgram(program, snapshot, nullptr, - nullptr, &compute, spirv, &error), + ShaderRecompiler::Spirv::EmitProgram( + program, snapshot, {.compute = &compute}, spirv, &error), error.c_str()); ValidateSpirv(name, spirv); spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_2); @@ -18035,7 +18034,7 @@ void CheckPs5GameExampleImageClearRuntimeShape() { options.user_data_base = 0; options.user_data_count = static_cast(user_data.size()); options.user_data = user_data.data(); - options.compute_input_info = &compute; + options.input_info.compute = &compute; options.dump_ir = false; ShaderRecompiler::CompileResult result; std::string error; @@ -18136,7 +18135,7 @@ void CheckEmbeddedFetchVertexOffset() { options.user_data_base = 8; options.user_data_count = static_cast(user_data.size()); options.user_data = user_data.data(); - options.vertex_input_info = &vertex; + options.input_info.vertex = &vertex; ShaderRecompiler::CompileResult result; std::string error; @@ -20760,7 +20759,7 @@ void CheckEmbeddedFetchLaneSpill() { options.user_data_base = 8; options.user_data_count = static_cast(user_data.size()); options.user_data = user_data.data(); - options.vertex_input_info = &vertex; + options.input_info.vertex = &vertex; ShaderRecompiler::CompileResult result; std::string error; diff --git a/tests/shaderCfgTests.cpp b/tests/shaderCfgTests.cpp index f152ca9..96adf6c 100644 --- a/tests/shaderCfgTests.cpp +++ b/tests/shaderCfgTests.cpp @@ -51,6 +51,29 @@ void Check(bool value, const char *text) { } } +ShaderRecompiler::CompileOptions MakeCompileOptions(ShaderType stage) { + static const ShaderVertexInputInfo vertex{}; + static const ShaderPixelInputInfo pixel{}; + static const ShaderComputeInputInfo compute{}; + + ShaderRecompiler::CompileOptions options; + options.stage = stage; + switch (stage) { + case ShaderType::Vertex: + options.input_info.vertex = &vertex; + break; + case ShaderType::Pixel: + options.input_info.pixel = &pixel; + break; + case ShaderType::Compute: + options.input_info.compute = &compute; + break; + default: + std::abort(); + } + return options; +} + std::vector CfgInstructionCoverage(const ShaderRecompiler::CFG::Graph &graph, size_t instruction_count) { @@ -1018,8 +1041,7 @@ void TestNewShaderRecompilerSMovB32() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -1063,8 +1085,7 @@ void TestNewShaderRecompilerSoppMarkers() { EncodeSopp(0x01, 0), // s_endpgm }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -1113,8 +1134,7 @@ void TestNewShaderRecompilerSopkWaitcntMarkers() { EncodeSopp(0x01, 0), // s_endpgm }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -1146,8 +1166,7 @@ void TestNewShaderRecompilerRdna2ScalarOpcodes() { EncodeSopp(0x01, 0), // s_endpgm }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -1220,8 +1239,7 @@ void TestNewShaderRecompilerScalarVectorAlu() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -1326,8 +1344,7 @@ void TestNewShaderRecompilerVop3LaneReadDestinationEncoding() { EncodeSopp(0x01, 0), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -1605,8 +1622,7 @@ void TestNewShaderRecompilerMoreAluFamilies() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -2454,8 +2470,7 @@ void TestNewShaderRecompilerExpandedAluBatch() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -2540,8 +2555,7 @@ void TestNewShaderRecompilerVop3pPackedF16() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -2668,8 +2682,7 @@ void TestNewShaderRecompilerStagedShaderOps() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -2751,8 +2764,7 @@ void TestNewShaderRecompilerBootF16UnaryOpcodes() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -2825,10 +2837,9 @@ void TestNewShaderRecompilerCapturedVop1SdwaByteConvert() { ps_info.ps_system_input_base = 9; ps_info.ps_pos_x = true; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; + auto options = MakeCompileOptions(ShaderType::Pixel); options.dump_ir = true; - options.pixel_input_info = &ps_info; + options.input_info.pixel = &ps_info; ShaderRecompiler::CompileResult result; std::string error; @@ -2904,8 +2915,7 @@ void TestNewShaderRecompilerBootB16PackedAndSdwaOpcodes() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -3064,8 +3074,7 @@ void TestNewShaderRecompilerScalarB64Alu() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -3230,8 +3239,7 @@ void TestNewShaderRecompilerSignedCompareAlu() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -3290,8 +3298,7 @@ void TestNewShaderRecompilerSignedMinShiftAlu() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -3348,8 +3355,7 @@ void TestNewShaderRecompilerScalarBitfieldAlu() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -3428,8 +3434,7 @@ void CheckNewDecoderUnsupported(const uint32_t *shader, uint32_t words, Check(Common::ContainsStr(text, opcode_name), "decoder unsupported text did not include opcode name"); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; Check(!ShaderRecompiler::TryRecompile(code, options, result, &error), @@ -3630,8 +3635,7 @@ void TestNewShaderRecompilerMemoryFamilyLowering() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); options.read_memory = ReadZeroTestMemory; @@ -3732,8 +3736,7 @@ void TestNewShaderRecompilerScalarMemoryBindingDomains() { raw_user_data[0] = 2u; raw_user_data[8] = 0x1003u; - ShaderRecompiler::CompileOptions raw_options; - raw_options.stage = ShaderType::Pixel; + auto raw_options = MakeCompileOptions(ShaderType::Pixel); raw_options.user_data = raw_user_data.data(); raw_options.user_data_count = static_cast(raw_user_data.size()); @@ -3785,8 +3788,7 @@ void TestNewShaderRecompilerScalarMemoryBindingDomains() { buffer_user_data[8] = 0x2000u; buffer_user_data[10] = 4u; - ShaderRecompiler::CompileOptions buffer_options; - buffer_options.stage = ShaderType::Pixel; + auto buffer_options = MakeCompileOptions(ShaderType::Pixel); buffer_options.user_data = buffer_user_data.data(); buffer_options.user_data_count = static_cast(buffer_user_data.size()); @@ -3829,8 +3831,7 @@ void TestNewShaderRecompilerImageQueryLowering() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -3878,8 +3879,7 @@ void TestNewShaderRecompilerCubeSampleCoordinates() { }; auto user_data = ImageTestUserData(Prospero::ImageType::kCube); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.user_data = user_data.data(); ShaderRecompiler::CompileResult result; @@ -3927,8 +3927,7 @@ void TestNewShaderRecompilerImageSampleVariants() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4019,8 +4018,7 @@ void TestNewShaderRecompilerImageSampleA16SamplerCoords() { }; auto user_data = ImageTestUserData(Prospero::ImageType::kColor3D); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4066,8 +4064,7 @@ void TestNewShaderRecompilerImageSampleOpcodeAliases() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4104,8 +4101,7 @@ void TestNewShaderRecompilerImageSampleA16ExceptionComponents() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4227,8 +4223,7 @@ void TestNewShaderRecompilerImageLoadA16UintCoords() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4274,9 +4269,8 @@ void TestNewShaderRecompilerPixelImageSampleLodSelection() { auto ps_info = RegressionPixelInputInfo(); auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; - options.pixel_input_info = &ps_info; + auto options = MakeCompileOptions(ShaderType::Pixel); + options.input_info.pixel = &ps_info; options.dump_ir = true; options.user_data = user_data.data(); @@ -4382,9 +4376,8 @@ void TestNewShaderRecompilerImageViewDimensions() { SetImageTestType(&user_data, 9, Prospero::ImageType::kColor1D); SetImageTestFormat(&user_data, 9, Prospero::BufferFormat::k32UInt); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; - options.pixel_input_info = &ps_info; + auto options = MakeCompileOptions(ShaderType::Pixel); + options.input_info.pixel = &ps_info; options.dump_ir = true; options.user_data = user_data.data(); @@ -4465,8 +4458,7 @@ void TestNewShaderRecompilerStorageImage1DDescriptorVariants() { SetImageTestType(&user_data, 4, Prospero::ImageType::kColor1D); SetImageTestType(&user_data, 5, Prospero::ImageType::kColor1DArray); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4501,8 +4493,7 @@ void TestNewShaderRecompilerNullImageUsesCanonical2DView() { }; std::array user_data{}; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.user_data = user_data.data(); ShaderRecompiler::CompileResult result; @@ -4529,8 +4520,7 @@ void TestNewShaderRecompilerRejectsOneDimensionalGather() { 0xbf810000u, }; auto user_data = ImageTestUserData(type); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.user_data = user_data.data(); ShaderRecompiler::CompileResult result; @@ -4560,8 +4550,7 @@ void TestNewShaderRecompilerImageGatherVariants() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4650,8 +4639,7 @@ void TestNewShaderRecompilerImageLoadVariants() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4700,8 +4688,7 @@ void TestNewShaderRecompilerImageLoad2DMsaa() { user_data[5] |= 2u << 4u; user_data[6] |= 1u << 10u; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; + auto options = MakeCompileOptions(ShaderType::Pixel); options.dump_ir = true; options.user_data = user_data.data(); @@ -4745,8 +4732,7 @@ void TestNewShaderRecompilerImageStoreLowering() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4799,10 +4785,9 @@ void TestNewShaderRecompilerStorageImage3DDescriptorVariant() { user_data[22] = 255u | (255u << 14u); user_data[23] = ImageTypeColor3D << 28u; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; - options.compute_input_info = &input_info; + options.input_info.compute = &input_info; options.user_data = user_data.data(); ShaderRecompiler::CompileResult result; @@ -4853,10 +4838,9 @@ void TestNewShaderRecompilerStorageImage2DDescriptorOverridesMimg3D() { user_data[22] = 255u | (255u << 14u); user_data[23] = ImageTypeColor2D << 28u; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; - options.compute_input_info = &input_info; + options.input_info.compute = &input_info; options.user_data = user_data.data(); ShaderRecompiler::CompileResult result; @@ -4900,8 +4884,7 @@ void TestNewShaderRecompilerImageAtomicLowering() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -4968,9 +4951,8 @@ void TestNewShaderRecompilerVintrpLowering() { ps_info.input_num = 2; SetIdentityInterpolatorSettings(&ps_info); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; - options.pixel_input_info = &ps_info; + auto options = MakeCompileOptions(ShaderType::Pixel); + options.input_info.pixel = &ps_info; options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -5015,7 +4997,7 @@ void TestNewShaderRecompilerVintrpLowering() { SetIdentityInterpolatorSettings(&remapped_ps_info); remapped_ps_info.interpolator_settings[2] = 3; - options.pixel_input_info = &remapped_ps_info; + options.input_info.pixel = &remapped_ps_info; ShaderRecompiler::CompileResult remapped_result; Check(ShaderRecompiler::TryRecompile(remapped_shader, options, @@ -5041,7 +5023,7 @@ void TestNewShaderRecompilerVintrpLowering() { ShaderPixelInputInfo duplicate_ps_info{}; duplicate_ps_info.input_num = 2; - options.pixel_input_info = &duplicate_ps_info; + options.input_info.pixel = &duplicate_ps_info; ShaderRecompiler::CompileResult duplicate_result; Check(ShaderRecompiler::TryRecompile(duplicate_location_shader, options, @@ -5066,7 +5048,7 @@ void TestNewShaderRecompilerVintrpLowering() { SetIdentityInterpolatorSettings(&flat_ps_info); flat_ps_info.interpolator_settings[0] = 0x00000400u; - options.pixel_input_info = &flat_ps_info; + options.input_info.pixel = &flat_ps_info; ShaderRecompiler::CompileResult flat_result; Check( @@ -5085,7 +5067,7 @@ void TestNewShaderRecompilerVintrpLowering() { no_perspective_ps_info.ps_no_perspective = true; SetIdentityInterpolatorSettings(&no_perspective_ps_info); - options.pixel_input_info = &no_perspective_ps_info; + options.input_info.pixel = &no_perspective_ps_info; ShaderRecompiler::CompileResult no_perspective_result; Check(ShaderRecompiler::TryRecompile(flat_shader, options, @@ -5202,8 +5184,7 @@ void TestNewShaderRecompilerWideMemoryLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.flat_memory_base = 0; @@ -5290,8 +5271,7 @@ void TestNewShaderRecompilerBufferSignedLoadLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -5331,8 +5311,7 @@ void TestNewShaderRecompilerBufferSubDwordStoreLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -5387,8 +5366,7 @@ void TestNewShaderRecompilerMubufFormatLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -5437,8 +5415,7 @@ void TestNewShaderRecompilerFormattedStoreUsesRuntimeArrayLengthOnly() { user_data[2] = 5u; user_data[3] = static_cast(Prospero::BufferFormat::k32UInt) << 12u; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -5482,8 +5459,7 @@ void TestNewShaderRecompilerTypedBufferLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -5538,8 +5514,7 @@ void TestNewShaderRecompilerFlatOldBackedLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.flat_memory_base = 0; @@ -5573,8 +5548,7 @@ void TestNewShaderRecompilerUnbasedFlatRequiresTranslator() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); ShaderRecompiler::CompileResult result; std::string error; @@ -5595,8 +5569,7 @@ void TestNewShaderRecompilerFlatSignedLoadLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.flat_memory_base = 0; @@ -5651,8 +5624,7 @@ void TestNewShaderRecompilerFlatStoreLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.flat_memory_base = 0; @@ -5775,8 +5747,7 @@ void TestNewShaderRecompilerAtomicLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -5907,8 +5878,7 @@ void TestNewShaderRecompilerDsReadWrite2Lowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -5977,8 +5947,7 @@ void TestNewShaderRecompilerDsSubDwordLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6046,8 +6015,7 @@ void TestNewShaderRecompilerDsWideAndAtomicLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6112,8 +6080,7 @@ void TestNewShaderRecompilerDsSwizzleLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6165,10 +6132,9 @@ void TestNewShaderRecompilerDsAddtidLowering() { ShaderComputeInputInfo input_info = RegressionComputeInputInfo(); input_info.thread_ids_num = 1; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; - options.compute_input_info = &input_info; + options.input_info.compute = &input_info; ShaderRecompiler::CompileResult result; std::string error; @@ -6208,8 +6174,7 @@ void TestNewShaderRecompilerDsFloatMinMaxLowering() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6247,8 +6212,7 @@ void TestNewShaderRecompilerCfgStraightLine() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6274,8 +6238,7 @@ void TestNewShaderRecompilerCfgIfElse() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6298,8 +6261,7 @@ void TestNewShaderRecompilerCfgTerminalExitMergePS() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; + auto options = MakeCompileOptions(ShaderType::Pixel); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6325,8 +6287,7 @@ void TestNewShaderRecompilerCfgPostEndTargetMergePS() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; + auto options = MakeCompileOptions(ShaderType::Pixel); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6362,8 +6323,7 @@ void TestNewShaderRecompilerCfgLoopBreakContinue() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6395,8 +6355,7 @@ void TestNewShaderRecompilerCfgLoopHeaderDynamicScalarBufferLoadStructured() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6422,8 +6381,7 @@ void TestNewShaderRecompilerCfgLoopHeaderBufferLoadDispatcher() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6472,8 +6430,7 @@ void TestNewShaderRecompilerCfgLoopHeaderDsAppendConsumeStructured() { loop_header->inst_begin == loop_header->inst_end, "DS loop header still contains semantic instructions"); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6498,8 +6455,7 @@ void TestNewShaderRecompilerCfgLoopHeaderDsReadStructured() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6526,8 +6482,7 @@ void TestNewShaderRecompilerCfgSharedOuterAndLoopMerge() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6559,8 +6514,7 @@ void TestNewShaderRecompilerCfgLoopEarlyBreakNoSelection() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6594,8 +6548,7 @@ void TestNewShaderRecompilerCfgNestedLoopNonlocalExitDispatcher() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6622,8 +6575,7 @@ void TestNewShaderRecompilerCfgNestedLoopLocalExitNoSelection() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6709,8 +6661,7 @@ void TestNewShaderRecompilerCfgMixedContinueNonmergeExitDispatcher() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6733,8 +6684,7 @@ void TestNewShaderRecompilerCfgConditionalLatchNoSelection() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6760,8 +6710,7 @@ void TestNewShaderRecompilerCfgDirectConditionalLatchNoSelection() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6796,8 +6745,7 @@ void TestNewShaderRecompilerCfgLoopEarlyContinuesNoSelection() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -6845,8 +6793,7 @@ void TestNewShaderRecompilerCfgLoopGatewaySelection() { original_coverage, "loop gateway structurization duplicated semantic instructions"); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; Check(ShaderRecompiler::TryRecompile(shader, options, result, &error), @@ -6907,8 +6854,7 @@ void TestNewShaderRecompilerCfgConditionalLoopHeaderSelection() { Check(loop_headers == 1u && selection_headers == 1u, "guest conditional was not separated from the loop header"); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); ShaderRecompiler::CompileResult result; Check(ShaderRecompiler::TryRecompile(shader, options, result, &error), error.c_str()); @@ -6956,8 +6902,7 @@ void TestNewShaderRecompilerCfgMultipleLoopLatches() { continue_block->predecessors.size() == 2u, "canonical continue does not join both native latches"); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); ShaderRecompiler::CompileResult result; Check(ShaderRecompiler::TryRecompile(shader, options, result, &error), error.c_str()); @@ -6979,8 +6924,7 @@ void TestNewShaderRecompilerCfgDuplicateMergeStructuredSplit() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7074,8 +7018,7 @@ void TestNewShaderRecompilerCfgExecSccSharedArm() { for (const auto lane_mode : {ShaderLaneMaskMode::NativeWave, ShaderLaneMaskMode::PerInvocation}) { - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.lane_mask_mode = lane_mode; options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7149,8 +7092,7 @@ void TestNewShaderRecompilerCfgOverlappingEarlyExitLadder() { "structurization added a semantic block clone"); } - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; + auto options = MakeCompileOptions(ShaderType::Pixel); options.dump_ir = true; ShaderRecompiler::CompileResult result; Check(ShaderRecompiler::TryRecompile(shader, options, result, &error), @@ -7192,8 +7134,7 @@ void TestNewShaderRecompilerCfgExternallyEnteredSelectionDispatcher() { original_coverage, "externally-entered selection handling duplicated semantic code"); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; Check(ShaderRecompiler::TryRecompile(shader, options, result, &error), @@ -7216,8 +7157,7 @@ void TestNewShaderRecompilerCfgIrreducibleDispatcher() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7290,8 +7230,7 @@ void TestNewShaderRecompilerWave32MasksExecHighStores() { EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.wave_size = 32; @@ -7317,8 +7256,7 @@ void TestNewShaderRecompilerWave32VccHighScalarStores() { EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.wave_size = 32; @@ -7346,8 +7284,7 @@ void TestNewShaderRecompilerCompareMaskIsFullWaveBallot() { EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.wave_size = 32; @@ -7384,8 +7321,7 @@ void TestNewShaderRecompilerBufferLoadsGuardedByExec() { EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7426,8 +7362,7 @@ void TestNewShaderRecompilerBufferAtomicsGuardedByBounds() { EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7478,8 +7413,7 @@ void TestNewShaderRecompilerBranchConditionForms() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7507,8 +7441,7 @@ void TestNewShaderRecompilerSetpcBranch() { EncodeSMovB32(0, 129), 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7547,8 +7480,7 @@ void TestNewShaderRecompilerSetpcJumpTable() { 0x00000000u, // table: target case 1 relative to pc 0x28 }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7583,8 +7515,7 @@ void TestNewShaderRecompilerExpVertexOutputs() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Vertex; + auto options = MakeCompileOptions(ShaderType::Vertex); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7616,8 +7547,7 @@ void TestNewShaderRecompilerZeroInitialRegisterState() { EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Vertex; + auto options = MakeCompileOptions(ShaderType::Vertex); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7645,8 +7575,7 @@ void TestNewShaderRecompilerVertexSystemVgprs() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Vertex; + auto options = MakeCompileOptions(ShaderType::Vertex); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7682,8 +7611,7 @@ void TestNewShaderRecompilerVertexExportUsesLaneExecMask() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Vertex; + auto options = MakeCompileOptions(ShaderType::Vertex); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7727,8 +7655,7 @@ void TestNewShaderRecompilerPerInvocationMasks() { EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Vertex; + auto options = MakeCompileOptions(ShaderType::Vertex); options.lane_mask_mode = ShaderLaneMaskMode::PerInvocation; options.dump_ir = true; @@ -7795,8 +7722,7 @@ void TestNewShaderRecompilerPerInvocationU64Complement() { EncodeExp0(0x0c, 0xf), EncodeExp1(0, 1, 2, 3), EncodeSopp(0x01), }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Vertex; + auto options = MakeCompileOptions(ShaderType::Vertex); options.lane_mask_mode = ShaderLaneMaskMode::PerInvocation; options.dump_ir = true; @@ -7825,8 +7751,7 @@ void TestNewShaderRecompilerExpPixelOutputs() { 0xbf810000u, }; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; + auto options = MakeCompileOptions(ShaderType::Pixel); options.dump_ir = true; ShaderRecompiler::CompileResult result; @@ -7843,7 +7768,7 @@ void TestNewShaderRecompilerExpPixelOutputs() { ShaderPixelInputInfo uint16_info; uint16_info.target_output_mode[0] = 7; - options.pixel_input_info = &uint16_info; + options.input_info.pixel = &uint16_info; ShaderRecompiler::CompileResult uint16_result; Check(ShaderRecompiler::TryRecompile(shader, options, uint16_result, &error), error.c_str()); @@ -7865,7 +7790,8 @@ void TestNewShaderRecompilerExpPixelOutputs() { EncodeExp1(0, 1, 2, 3), 0xbf810000u, }; - options.pixel_input_info = nullptr; + ShaderPixelInputInfo default_info; + options.input_info.pixel = &default_info; ShaderRecompiler::CompileResult partial_result; Check(ShaderRecompiler::TryRecompile(partial_shader, options, partial_result, &error), @@ -7878,7 +7804,7 @@ void TestNewShaderRecompilerExpPixelOutputs() { ShaderPixelInputInfo uint_info; uint_info.target_output_mode[0] = 7; - options.pixel_input_info = &uint_info; + options.input_info.pixel = &uint_info; ShaderRecompiler::CompileResult partial_uint_result; Check(ShaderRecompiler::TryRecompile(partial_shader, options, partial_uint_result, &error), @@ -8045,9 +7971,8 @@ void TestRenderTargetReverseExportMapping() { ShaderPixelInputInfo reversed_info; reversed_info.target_export_mapping[0] = format.export_mapping; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; - options.pixel_input_info = &identity_info; + auto options = MakeCompileOptions(ShaderType::Pixel); + options.input_info.pixel = &identity_info; ShaderRecompiler::CompileResult identity_result; std::string error; Check( @@ -8056,7 +7981,7 @@ void TestRenderTargetReverseExportMapping() { Check(SpirvInstructionOpcodeCount(identity_result.spirv, 79u) == 0u, "identity MRT export unexpectedly added a component shuffle"); - options.pixel_input_info = &reversed_info; + options.input_info.pixel = &reversed_info; ShaderRecompiler::CompileResult reversed_result; Check( ShaderRecompiler::TryRecompile(shader, options, reversed_result, &error), @@ -8124,9 +8049,8 @@ void TestNewShaderRecompilerEarlyZDisabledWhenPixelKillEnabled() { ps_info.ps_early_z = true; ps_info.ps_pixel_kill_enable = true; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; - options.pixel_input_info = &ps_info; + auto options = MakeCompileOptions(ShaderType::Pixel); + options.input_info.pixel = &ps_info; ShaderRecompiler::CompileResult result; std::string error; @@ -8182,8 +8106,7 @@ void TestNewShaderRecompilerNativeBindingPlan() { }; auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.dump_ir = true; options.user_data = user_data.data(); @@ -8237,7 +8160,7 @@ void TestNewShaderRecompilerNativeBindingPlan() { const auto rejected_before = rejected_spirv; std::string rejected_error; Check(!ShaderRecompiler::Spirv::EmitProgram( - malformed, result.resources, nullptr, nullptr, nullptr, + malformed, result.resources, options.input_info, rejected_spirv, &rejected_error) && rejected_spirv == rejected_before && rejected_error.find("topology") != std::string::npos, @@ -8258,7 +8181,7 @@ void TestNewShaderRecompilerNativeBindingPlan() { rejected_spirv = rejected_before; rejected_error.clear(); Check(!ShaderRecompiler::Spirv::EmitProgram( - result.program, stale_resources, nullptr, nullptr, nullptr, + result.program, stale_resources, options.input_info, rejected_spirv, &rejected_error) && rejected_spirv == rejected_before && rejected_error.find("specialized format") != std::string::npos, @@ -8269,7 +8192,7 @@ void TestNewShaderRecompilerNativeBindingPlan() { rejected_spirv = rejected_before; rejected_error.clear(); Check(!ShaderRecompiler::Spirv::EmitProgram( - result.program, stale_dimension, nullptr, nullptr, nullptr, + result.program, stale_dimension, options.input_info, rejected_spirv, &rejected_error) && rejected_spirv == rejected_before && rejected_error.find("specialized dimension") != std::string::npos, @@ -8293,7 +8216,7 @@ void TestNewShaderRecompilerNativeBindingPlan() { rejected_spirv = rejected_before; rejected_error.clear(); const bool rejected = !ShaderRecompiler::Spirv::EmitProgram( - result.program, result.resources, nullptr, nullptr, nullptr, + result.program, result.resources, options.input_info, rejected_spirv, &rejected_error); buffer_handle->SetFlags(dense); Check(rejected && rejected_spirv == rejected_before && @@ -8607,8 +8530,7 @@ void TestTypedDescriptorRealCarryAndScalarLoads() { "incorrectly"); auto user_data = ImageTestUserData(); - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Pixel; + auto options = MakeCompileOptions(ShaderType::Pixel); options.user_data = user_data.data(); ShaderRecompiler::CompileResult result; error.clear(); @@ -8945,9 +8867,8 @@ void TestNewShaderRecompilerStageInputInfo() { cs_info.thread_ids_num = 3; cs_info.dispatch_thread_dimensions = true; - ShaderRecompiler::CompileOptions cs_options; - cs_options.stage = ShaderType::Compute; - cs_options.compute_input_info = &cs_info; + auto cs_options = MakeCompileOptions(ShaderType::Compute); + cs_options.input_info.compute = &cs_info; ShaderRecompiler::CompileResult cs_result; std::string error; @@ -8972,8 +8893,7 @@ void TestNewShaderRecompilerStageInputInfo() { "SPIR-V lacks LocalInvocationIndex BuiltIn decoration"); CheckSpirvBinaryValidates(cs_result.spirv); - ShaderRecompiler::CompileOptions vs_options; - vs_options.stage = ShaderType::Vertex; + auto vs_options = MakeCompileOptions(ShaderType::Vertex); ShaderRecompiler::CompileResult vs_result; Check(ShaderRecompiler::TryRecompile(shader, vs_options, vs_result, &error), @@ -8995,9 +8915,8 @@ void TestNewShaderRecompilerStageInputInfo() { ps_info.ps_pos_z = true; SetIdentityInterpolatorSettings(&ps_info); - ShaderRecompiler::CompileOptions ps_options; - ps_options.stage = ShaderType::Pixel; - ps_options.pixel_input_info = &ps_info; + auto ps_options = MakeCompileOptions(ShaderType::Pixel); + ps_options.input_info.pixel = &ps_info; ShaderRecompiler::CompileResult ps_result; Check(ShaderRecompiler::TryRecompile(shader, ps_options, ps_result, &error), @@ -9019,7 +8938,7 @@ void TestNewShaderRecompilerStageInputInfo() { ps_pos_y_info.ps_system_input_base = 2; ps_pos_y_info.ps_pos_y = true; SetIdentityInterpolatorSettings(&ps_pos_y_info); - ps_options.pixel_input_info = &ps_pos_y_info; + ps_options.input_info.pixel = &ps_pos_y_info; ShaderRecompiler::CompileResult ps_pos_y_result; Check(ShaderRecompiler::TryRecompile(shader, ps_options, ps_pos_y_result, @@ -9140,9 +9059,8 @@ void TestComputeLdsAllocationIdentity() { }; ShaderComputeInputInfo append_info = RegressionComputeInputInfo(); append_info.lds_size_dwords = 1152u; - ShaderRecompiler::CompileOptions append_options; - append_options.stage = ShaderType::Compute; - append_options.compute_input_info = &append_info; + auto append_options = MakeCompileOptions(ShaderType::Compute); + append_options.input_info.compute = &append_info; ShaderRecompiler::CompileResult append_result; std::string error; Check(ShaderRecompiler::TryRecompile(append_shader, append_options, @@ -9250,8 +9168,7 @@ void TestNewShaderRecompilerFlatUserPointerProvenance() { }; const uint32_t user_data[] = {0x34567000u, 0x00000012u}; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.user_data = user_data; options.user_data_count = static_cast(std::size(user_data)); options.flat_memory_base = 0; @@ -9288,8 +9205,7 @@ void TestNewShaderRecompilerFlatAddressProvenanceBoundaries() { }; const uint32_t user_data[] = {0x34567000u, 0u, 0x1000u}; - ShaderRecompiler::CompileOptions options; - options.stage = ShaderType::Compute; + auto options = MakeCompileOptions(ShaderType::Compute); options.user_data = user_data; options.user_data_count = static_cast(std::size(user_data)); options.flat_memory_base = 0;