mirror of
				https://git.suyu.dev/suyu/suyu
				synced 2025-11-04 00:49:02 -06:00 
			
		
		
		
	shader: Fix VertexA Shaders.
This commit is contained in:
		@@ -171,20 +171,29 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b
 | 
			
		||||
    IR::Program result{};
 | 
			
		||||
    Optimization::VertexATransformPass(vertex_a);
 | 
			
		||||
    Optimization::VertexBTransformPass(vertex_b);
 | 
			
		||||
    std::swap(result.blocks, vertex_a.blocks);
 | 
			
		||||
    result.blocks.insert(result.blocks.end(), vertex_b.blocks.begin(), vertex_b.blocks.end());
 | 
			
		||||
    for (const auto& term : vertex_a.syntax_list) {
 | 
			
		||||
        if (term.type == IR::AbstractSyntaxNode::Type::Return) {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        result.syntax_list.push_back(term);
 | 
			
		||||
    }
 | 
			
		||||
    for (const auto& term : vertex_b.syntax_list) {
 | 
			
		||||
        result.syntax_list.push_back(term);
 | 
			
		||||
    }
 | 
			
		||||
    result.blocks = GenerateBlocks(result.syntax_list);
 | 
			
		||||
    result.post_order_blocks = vertex_b.post_order_blocks;
 | 
			
		||||
    for (const auto& block : vertex_a.post_order_blocks) {
 | 
			
		||||
        result.post_order_blocks.push_back(block);
 | 
			
		||||
    }
 | 
			
		||||
    result.stage = Stage::VertexB;
 | 
			
		||||
    result.info = vertex_a.info;
 | 
			
		||||
    result.local_memory_size = std::max(vertex_a.local_memory_size, vertex_b.local_memory_size);
 | 
			
		||||
 | 
			
		||||
    for (size_t index = 0; index < 32; ++index) {
 | 
			
		||||
        result.info.input_generics[index].used |= vertex_b.info.input_generics[index].used;
 | 
			
		||||
        result.info.stores_generics[index] |= vertex_b.info.stores_generics[index];
 | 
			
		||||
    }
 | 
			
		||||
    Optimization::JoinTextureInfo(result.info, vertex_b.info);
 | 
			
		||||
    Optimization::JoinStorageInfo(result.info, vertex_b.info);
 | 
			
		||||
    Optimization::DualVertexJoinPass(result);
 | 
			
		||||
    result.post_order_blocks = PostOrder(result.syntax_list.front());
 | 
			
		||||
    Optimization::DeadCodeEliminationPass(result);
 | 
			
		||||
    Optimization::VerificationPass(result);
 | 
			
		||||
    Optimization::CollectShaderInfoPass(env_vertex_b, result);
 | 
			
		||||
 
 | 
			
		||||
@@ -13,16 +13,24 @@
 | 
			
		||||
 | 
			
		||||
namespace Shader::Optimization {
 | 
			
		||||
 | 
			
		||||
void VertexATransformPass(IR::Program&) {
 | 
			
		||||
    throw NotImplementedException("VertexA pass");
 | 
			
		||||
void VertexATransformPass(IR::Program& program) {
 | 
			
		||||
  for (IR::Block* const block : program.blocks) {
 | 
			
		||||
      for (IR::Inst& inst : block->Instructions()) {
 | 
			
		||||
          if (inst.GetOpcode() == IR::Opcode::Epilogue) {
 | 
			
		||||
              return inst.Invalidate();
 | 
			
		||||
          }
 | 
			
		||||
      }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void VertexBTransformPass(IR::Program&) {
 | 
			
		||||
    throw NotImplementedException("VertexA pass");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DualVertexJoinPass(IR::Program&) {
 | 
			
		||||
    throw NotImplementedException("VertexA pass");
 | 
			
		||||
void VertexBTransformPass(IR::Program& program) {
 | 
			
		||||
  for (IR::Block* const block : program.blocks) {
 | 
			
		||||
      for (IR::Inst& inst : block->Instructions()) {
 | 
			
		||||
          if (inst.GetOpcode() == IR::Opcode::Prologue) {
 | 
			
		||||
              return inst.Invalidate();
 | 
			
		||||
          }
 | 
			
		||||
      }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Shader::Optimization
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,6 @@ void VerificationPass(const IR::Program& program);
 | 
			
		||||
// Dual Vertex
 | 
			
		||||
void VertexATransformPass(IR::Program& program);
 | 
			
		||||
void VertexBTransformPass(IR::Program& program);
 | 
			
		||||
void DualVertexJoinPass(IR::Program& program);
 | 
			
		||||
void JoinTextureInfo(Info& base, Info& source);
 | 
			
		||||
void JoinStorageInfo(Info& base, Info& source);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,7 @@ namespace OpenGL {
 | 
			
		||||
namespace {
 | 
			
		||||
using Shader::Backend::GLASM::EmitGLASM;
 | 
			
		||||
using Shader::Backend::SPIRV::EmitSPIRV;
 | 
			
		||||
using Shader::Maxwell::MergeDualVertexPrograms;
 | 
			
		||||
using Shader::Maxwell::TranslateProgram;
 | 
			
		||||
using VideoCommon::ComputeEnvironment;
 | 
			
		||||
using VideoCommon::FileEnvironment;
 | 
			
		||||
@@ -446,6 +447,8 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline(
 | 
			
		||||
    size_t env_index{};
 | 
			
		||||
    u32 total_storage_buffers{};
 | 
			
		||||
    std::array<Shader::IR::Program, Maxwell::MaxShaderProgram> programs;
 | 
			
		||||
    const bool uses_vertex_a{key.unique_hashes[0] != 0};
 | 
			
		||||
    const bool uses_vertex_b{key.unique_hashes[1] != 0};
 | 
			
		||||
    for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) {
 | 
			
		||||
        if (key.unique_hashes[index] == 0) {
 | 
			
		||||
            continue;
 | 
			
		||||
@@ -454,11 +457,22 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline(
 | 
			
		||||
        ++env_index;
 | 
			
		||||
 | 
			
		||||
        const u32 cfg_offset{static_cast<u32>(env.StartAddress() + sizeof(Shader::ProgramHeader))};
 | 
			
		||||
        Shader::Maxwell::Flow::CFG cfg(env, pools.flow_block, cfg_offset);
 | 
			
		||||
        programs[index] = TranslateProgram(pools.inst, pools.block, env, cfg);
 | 
			
		||||
        Shader::Maxwell::Flow::CFG cfg(env, pools.flow_block, cfg_offset, index == 0);
 | 
			
		||||
        if (!uses_vertex_a || index != 1) {
 | 
			
		||||
            // Normal path
 | 
			
		||||
            programs[index] = TranslateProgram(pools.inst, pools.block, env, cfg);
 | 
			
		||||
 | 
			
		||||
        for (const auto& desc : programs[index].info.storage_buffers_descriptors) {
 | 
			
		||||
            total_storage_buffers += desc.count;
 | 
			
		||||
            for (const auto& desc : programs[index].info.storage_buffers_descriptors) {
 | 
			
		||||
                total_storage_buffers += desc.count;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            // VertexB path when VertexA is present.
 | 
			
		||||
            Shader::IR::Program& program_va{programs[0]};
 | 
			
		||||
            Shader::IR::Program program_vb{TranslateProgram(pools.inst, pools.block, env, cfg)};
 | 
			
		||||
            for (const auto& desc : program_vb.info.storage_buffers_descriptors) {
 | 
			
		||||
                total_storage_buffers += desc.count;
 | 
			
		||||
            }
 | 
			
		||||
            programs[index] = MergeDualVertexPrograms(program_va, program_vb, env);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    const u32 glasm_storage_buffer_limit{device.GetMaxGLASMStorageBufferBlocks()};
 | 
			
		||||
@@ -472,7 +486,9 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline(
 | 
			
		||||
    if (!device.UseAssemblyShaders()) {
 | 
			
		||||
        source_program.handle = glCreateProgram();
 | 
			
		||||
    }
 | 
			
		||||
    for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) {
 | 
			
		||||
 | 
			
		||||
    for (size_t index = uses_vertex_a && uses_vertex_b ? 1 : 0; index < Maxwell::MaxShaderProgram;
 | 
			
		||||
         ++index) {
 | 
			
		||||
        if (key.unique_hashes[index] == 0) {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user