Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

HLSL转 MSL的一些疑问? #60

@breakerrorchen

Description

@breakerrorchen

比如这样一个HLSL文件

uniform float4 data = 0;

struct VS_OUT {
float4 pos: SV_POSITION;
float4 color:COLOR;

};

VS_OUT vs_main(float4 pos: POSITION) {
VS_OUT ret = (VS_OUT)0;
ret.pos = pos + data;
return ret;
}

转化成MSL的文件

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct type_Globals
{
float4 data;
};

struct vs_main_out
{
float4 out_var_COLOR [[user(locn0)]];
float4 gl_Position [[position]];
};

struct vs_main_in
{
float4 in_var_POSITION [[attribute(0)]];
};

vertex vs_main_out vs_main(vs_main_in in [[stage_in]], constant type_Globals& _Globals [[buffer(0)]])
{
vs_main_out out = {};
out.gl_Position = in.in_var_POSITION + _Globals.data;
out.out_var_COLOR = float4(0.0);
return out;
}

这个文件中 定义了type_Globals 并把data放在了里面,问题是我如何拿到这个data的index?如果有2个uniform的话应该如何处理?不可能通过源码的方式来约定吧。 Metal本身好像没有提供这个API

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions