【问题标题】:Unsupported architecture - Shared Enum between Metal and Swift不受支持的架构 - Metal 和 Swift 之间的共享枚举
【发布时间】:2020-02-16 17:06:19
【问题描述】:

我尝试在 metal 和我的 swift 项目之间共享我在头文件中定义的枚举:

#ifndef SharedIndizes_h
#define SharedIndizes_h
#import <Foundation/Foundation.h>

#endif /* SharedIndizes_h */

typedef NS_ENUM(NSInteger, VertexAttribute)
{
    VertexAttributePosition = 0,
    VertexAttributeNormal  = 1,
};
#include <metal_stdlib>
#import "ExchangeTypes/SharedIndizes.h"
using namespace metal;

struct VertexIn {
    float3 position [[ attribute(VertexAttributePosition) ]];
    float3 normal [[ attribute(VertexAttributeNormal) ]];
};
vertexDescriptor.attributes[VertexAttribute.position.rawValue]
vertexDescriptor.attributes[VertexAttribute.normal.rawValue]

但我得到的只是一些意想不到的错误:

  • 不支持的架构

  • 未知类型名称'_int64_t'

  • 未知类型名称'_int32_t'

  • ...

从我的金属文件中删除 #import "ExchangeTypes/SharedIndizes.h" 也会删除错误。

【问题讨论】:

    标签: swift metal


    【解决方案1】:

    替换这个:

    #ifndef SharedIndizes_h
    #define SharedIndizes_h
    #import <Foundation/Foundation.h>
    
    #endif /* SharedIndizes_h */
    
    typedef NS_ENUM(NSInteger, VertexAttribute)
    {
        VertexAttributePosition = 0,
        VertexAttributeNormal  = 1,
    };
    

    用这个:

    #ifndef SharedIndizes_h
    #define SharedIndizes_h
    
    #ifdef __METAL_VERSION__
    #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
    #define NSInteger metal::int32_t
    #else
    
    #import <Foundation/Foundation.h>
    
    #endif /* __METAL_VERSION__ */
    #endif /* SharedIndizes_h */
    
    typedef NS_ENUM(NSInteger, VertexAttribute)
    {
        VertexAttributePosition = 0,
        VertexAttributeNormal  = 1,
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-20
      • 2012-01-10
      • 2017-10-22
      • 2014-05-21
      • 2021-06-01
      • 2012-03-19
      • 1970-01-01
      • 2013-10-27
      相关资源
      最近更新 更多