直接在 C# 中引用 HLSL 函数

问题描述 投票:0回答:0

我使用Unity中的Compute Shader在GPU上进行计算。我实现了很多功能。但在某些情况下,我想在 CPU 上使用该函数,因为我只需要一个值,而在 GPU 上计算该值的效率非常低。

问题是我因此必须实现每个功能两次。一次在计算着色器中,一次在 C# 中。这使得代码库更难维护。

我的问题

在计算着色器 (HLSL) 中定义函数时,是否可以直接在 C# 中引用函数?

例子

计算着色器:

float Function(float3 p)
{
    return length(p);
}

在 C# 中我有这样的东西:

public static float Function(Vector3 p)
{
    return Vector3.Magnitude(p); 
}

但我想要这样的东西:

using computeShaderCode;
public static float Function(Vector3 p)
{
    return computeShaderCode.Function(p); 
}
c# unity3d hlsl compute-shader
© www.soinside.com 2019 - 2024. All rights reserved.