mirror of
				https://git.zaroz.cloud/nintendo-back-up/yuzu/yuzu-mainline.git
				synced 2025-03-21 01:53:15 +00:00 
			
		
		
		
	gl_shader_decompiler: replace std::get<> with std::get_if<> for macOS compatibility
This commit is contained in:
		
							parent
							
								
									51de4e00a6
								
							
						
					
					
						commit
						1e40a4b343
					
				@ -112,20 +112,20 @@ static std::string GetTopologyName(Tegra::Shader::OutputTopology topology) {
 | 
				
			|||||||
static bool IsPrecise(Operation operand) {
 | 
					static bool IsPrecise(Operation operand) {
 | 
				
			||||||
    const auto& meta = operand.GetMeta();
 | 
					    const auto& meta = operand.GetMeta();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (std::holds_alternative<MetaArithmetic>(meta)) {
 | 
					    if (const auto arithmetic = std::get_if<MetaArithmetic>(&meta)) {
 | 
				
			||||||
        return std::get<MetaArithmetic>(meta).precise;
 | 
					        return arithmetic->precise;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (std::holds_alternative<MetaHalfArithmetic>(meta)) {
 | 
					    if (const auto half_arithmetic = std::get_if<MetaHalfArithmetic>(&meta)) {
 | 
				
			||||||
        return std::get<MetaHalfArithmetic>(meta).precise;
 | 
					        return half_arithmetic->precise;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool IsPrecise(Node node) {
 | 
					static bool IsPrecise(Node node) {
 | 
				
			||||||
    if (!std::holds_alternative<OperationNode>(*node)) {
 | 
					    if (const auto operation = std::get_if<OperationNode>(node)) {
 | 
				
			||||||
        return false;
 | 
					        return IsPrecise(*operation);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return IsPrecise(std::get<OperationNode>(*node));
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GLSLDecompiler final {
 | 
					class GLSLDecompiler final {
 | 
				
			||||||
@ -601,12 +601,12 @@ private:
 | 
				
			|||||||
        case Type::Uint:
 | 
					        case Type::Uint:
 | 
				
			||||||
            return "ftou(" + value + ')';
 | 
					            return "ftou(" + value + ')';
 | 
				
			||||||
        case Type::HalfFloat:
 | 
					        case Type::HalfFloat:
 | 
				
			||||||
            if (!std::holds_alternative<MetaHalfArithmetic>(operation.GetMeta())) {
 | 
					            const auto half_meta = std::get_if<MetaHalfArithmetic>(&operation.GetMeta());
 | 
				
			||||||
 | 
					            if (!half_meta) {
 | 
				
			||||||
                value = "toHalf2(" + value + ')';
 | 
					                value = "toHalf2(" + value + ')';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const auto& half_meta = std::get<MetaHalfArithmetic>(operation.GetMeta());
 | 
					            switch (half_meta->types.at(operand_index)) {
 | 
				
			||||||
            switch (half_meta.types.at(operand_index)) {
 | 
					 | 
				
			||||||
            case Tegra::Shader::HalfType::H0_H1:
 | 
					            case Tegra::Shader::HalfType::H0_H1:
 | 
				
			||||||
                return "toHalf2(" + value + ')';
 | 
					                return "toHalf2(" + value + ')';
 | 
				
			||||||
            case Tegra::Shader::HalfType::F32:
 | 
					            case Tegra::Shader::HalfType::F32:
 | 
				
			||||||
@ -692,19 +692,20 @@ private:
 | 
				
			|||||||
                                bool is_extra_int = false) {
 | 
					                                bool is_extra_int = false) {
 | 
				
			||||||
        constexpr std::array<const char*, 4> coord_constructors = {"float", "vec2", "vec3", "vec4"};
 | 
					        constexpr std::array<const char*, 4> coord_constructors = {"float", "vec2", "vec3", "vec4"};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const auto& meta = std::get<MetaTexture>(operation.GetMeta());
 | 
					        const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
 | 
				
			||||||
        const auto count = static_cast<u32>(operation.GetOperandsCount());
 | 
					        const auto count = static_cast<u32>(operation.GetOperandsCount());
 | 
				
			||||||
 | 
					        ASSERT(meta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::string expr = func;
 | 
					        std::string expr = func;
 | 
				
			||||||
        expr += '(';
 | 
					        expr += '(';
 | 
				
			||||||
        expr += GetSampler(meta.sampler);
 | 
					        expr += GetSampler(meta->sampler);
 | 
				
			||||||
        expr += ", ";
 | 
					        expr += ", ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        expr += coord_constructors[meta.coords_count - 1];
 | 
					        expr += coord_constructors[meta->coords_count - 1];
 | 
				
			||||||
        expr += '(';
 | 
					        expr += '(';
 | 
				
			||||||
        for (u32 i = 0; i < count; ++i) {
 | 
					        for (u32 i = 0; i < count; ++i) {
 | 
				
			||||||
            const bool is_extra = i >= meta.coords_count;
 | 
					            const bool is_extra = i >= meta->coords_count;
 | 
				
			||||||
            const bool is_array = i == meta.array_index;
 | 
					            const bool is_array = i == meta->array_index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            std::string operand = [&]() {
 | 
					            std::string operand = [&]() {
 | 
				
			||||||
                if (is_extra && is_extra_int) {
 | 
					                if (is_extra && is_extra_int) {
 | 
				
			||||||
@ -724,7 +725,7 @@ private:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            expr += operand;
 | 
					            expr += operand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (i + 1 == meta.coords_count) {
 | 
					            if (i + 1 == meta->coords_count) {
 | 
				
			||||||
                expr += ')';
 | 
					                expr += ')';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (i + 1 < count) {
 | 
					            if (i + 1 < count) {
 | 
				
			||||||
@ -1108,38 +1109,46 @@ private:
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string F4Texture(Operation operation) {
 | 
					    std::string F4Texture(Operation operation) {
 | 
				
			||||||
        const auto meta = std::get<MetaTexture>(operation.GetMeta());
 | 
					        const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
 | 
				
			||||||
 | 
					        ASSERT(meta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::string expr = GenerateTexture(operation, "texture");
 | 
					        std::string expr = GenerateTexture(operation, "texture");
 | 
				
			||||||
        if (meta.sampler.IsShadow()) {
 | 
					        if (meta->sampler.IsShadow()) {
 | 
				
			||||||
            expr = "vec4(" + expr + ')';
 | 
					            expr = "vec4(" + expr + ')';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return expr + GetSwizzle(meta.element);
 | 
					        return expr + GetSwizzle(meta->element);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string F4TextureLod(Operation operation) {
 | 
					    std::string F4TextureLod(Operation operation) {
 | 
				
			||||||
        const auto meta = std::get<MetaTexture>(operation.GetMeta());
 | 
					        const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
 | 
				
			||||||
 | 
					        ASSERT(meta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::string expr = GenerateTexture(operation, "textureLod");
 | 
					        std::string expr = GenerateTexture(operation, "textureLod");
 | 
				
			||||||
        if (meta.sampler.IsShadow()) {
 | 
					        if (meta->sampler.IsShadow()) {
 | 
				
			||||||
            expr = "vec4(" + expr + ')';
 | 
					            expr = "vec4(" + expr + ')';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return expr + GetSwizzle(meta.element);
 | 
					        return expr + GetSwizzle(meta->element);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string F4TextureGather(Operation operation) {
 | 
					    std::string F4TextureGather(Operation operation) {
 | 
				
			||||||
        const auto meta = std::get<MetaTexture>(operation.GetMeta());
 | 
					        const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
 | 
				
			||||||
        return GenerateTexture(operation, "textureGather", !meta.sampler.IsShadow()) +
 | 
					        ASSERT(meta);
 | 
				
			||||||
               GetSwizzle(meta.element);
 | 
					
 | 
				
			||||||
 | 
					        return GenerateTexture(operation, "textureGather", !meta->sampler.IsShadow()) +
 | 
				
			||||||
 | 
					               GetSwizzle(meta->element);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string F4TextureQueryDimensions(Operation operation) {
 | 
					    std::string F4TextureQueryDimensions(Operation operation) {
 | 
				
			||||||
        const auto& meta = std::get<MetaTexture>(operation.GetMeta());
 | 
					        const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
 | 
				
			||||||
        const std::string sampler = GetSampler(meta.sampler);
 | 
					        ASSERT(meta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const std::string sampler = GetSampler(meta->sampler);
 | 
				
			||||||
        const std::string lod = VisitOperand(operation, 0, Type::Int);
 | 
					        const std::string lod = VisitOperand(operation, 0, Type::Int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        switch (meta.element) {
 | 
					        switch (meta->element) {
 | 
				
			||||||
        case 0:
 | 
					        case 0:
 | 
				
			||||||
        case 1:
 | 
					        case 1:
 | 
				
			||||||
            return "textureSize(" + sampler + ", " + lod + ')' + GetSwizzle(meta.element);
 | 
					            return "textureSize(" + sampler + ", " + lod + ')' + GetSwizzle(meta->element);
 | 
				
			||||||
        case 2:
 | 
					        case 2:
 | 
				
			||||||
            return "0";
 | 
					            return "0";
 | 
				
			||||||
        case 3:
 | 
					        case 3:
 | 
				
			||||||
@ -1150,29 +1159,32 @@ private:
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string F4TextureQueryLod(Operation operation) {
 | 
					    std::string F4TextureQueryLod(Operation operation) {
 | 
				
			||||||
        const auto& meta = std::get<MetaTexture>(operation.GetMeta());
 | 
					        const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
 | 
				
			||||||
        if (meta.element < 2) {
 | 
					        ASSERT(meta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (meta->element < 2) {
 | 
				
			||||||
            return "itof(int((" + GenerateTexture(operation, "textureQueryLod") + " * vec2(256))" +
 | 
					            return "itof(int((" + GenerateTexture(operation, "textureQueryLod") + " * vec2(256))" +
 | 
				
			||||||
                   GetSwizzle(meta.element) + "))";
 | 
					                   GetSwizzle(meta->element) + "))";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return "0";
 | 
					        return "0";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string F4TexelFetch(Operation operation) {
 | 
					    std::string F4TexelFetch(Operation operation) {
 | 
				
			||||||
        constexpr std::array<const char*, 4> constructors = {"int", "ivec2", "ivec3", "ivec4"};
 | 
					        constexpr std::array<const char*, 4> constructors = {"int", "ivec2", "ivec3", "ivec4"};
 | 
				
			||||||
        const auto& meta = std::get<MetaTexture>(operation.GetMeta());
 | 
					        const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
 | 
				
			||||||
        const auto count = static_cast<u32>(operation.GetOperandsCount());
 | 
					        const auto count = static_cast<u32>(operation.GetOperandsCount());
 | 
				
			||||||
 | 
					        ASSERT(meta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::string expr = "texelFetch(";
 | 
					        std::string expr = "texelFetch(";
 | 
				
			||||||
        expr += GetSampler(meta.sampler);
 | 
					        expr += GetSampler(meta->sampler);
 | 
				
			||||||
        expr += ", ";
 | 
					        expr += ", ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        expr += constructors[meta.coords_count - 1];
 | 
					        expr += constructors[meta->coords_count - 1];
 | 
				
			||||||
        expr += '(';
 | 
					        expr += '(';
 | 
				
			||||||
        for (u32 i = 0; i < count; ++i) {
 | 
					        for (u32 i = 0; i < count; ++i) {
 | 
				
			||||||
            expr += VisitOperand(operation, i, Type::Int);
 | 
					            expr += VisitOperand(operation, i, Type::Int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (i + 1 == meta.coords_count) {
 | 
					            if (i + 1 == meta->coords_count) {
 | 
				
			||||||
                expr += ')';
 | 
					                expr += ')';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (i + 1 < count) {
 | 
					            if (i + 1 < count) {
 | 
				
			||||||
@ -1180,26 +1192,28 @@ private:
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        expr += ')';
 | 
					        expr += ')';
 | 
				
			||||||
        return expr + GetSwizzle(meta.element);
 | 
					        return expr + GetSwizzle(meta->element);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string Branch(Operation operation) {
 | 
					    std::string Branch(Operation operation) {
 | 
				
			||||||
        const auto target = std::get<ImmediateNode>(*operation[0]);
 | 
					        const auto target = std::get_if<ImmediateNode>(operation[0]);
 | 
				
			||||||
        code.AddLine(fmt::format("jmp_to = 0x{:x}u;", target.GetValue()));
 | 
					        UNIMPLEMENTED_IF(!target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        code.AddLine(fmt::format("jmp_to = 0x{:x}u;", target->GetValue()));
 | 
				
			||||||
        code.AddLine("break;");
 | 
					        code.AddLine("break;");
 | 
				
			||||||
        return {};
 | 
					        return {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string PushFlowStack(Operation operation) {
 | 
					    std::string PushFlowStack(Operation operation) {
 | 
				
			||||||
        const auto target = std::get<ImmediateNode>(*operation[0]);
 | 
					        const auto target = std::get_if<ImmediateNode>(operation[0]);
 | 
				
			||||||
        code.AddLine(fmt::format("flow_stack[flow_stack_top] = 0x{:x}u;", target.GetValue()));
 | 
					        UNIMPLEMENTED_IF(!target);
 | 
				
			||||||
        code.AddLine("flow_stack_top++;");
 | 
					
 | 
				
			||||||
 | 
					        code.AddLine(fmt::format("flow_stack[flow_stack_top++] = 0x{:x}u;", target->GetValue()));
 | 
				
			||||||
        return {};
 | 
					        return {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::string PopFlowStack(Operation operation) {
 | 
					    std::string PopFlowStack(Operation operation) {
 | 
				
			||||||
        code.AddLine("flow_stack_top--;");
 | 
					        code.AddLine("jmp_to = flow_stack[--flow_stack_top];");
 | 
				
			||||||
        code.AddLine("jmp_to = flow_stack[flow_stack_top];");
 | 
					 | 
				
			||||||
        code.AddLine("break;");
 | 
					        code.AddLine("break;");
 | 
				
			||||||
        return {};
 | 
					        return {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user