简体   繁体   English

从 ispc 导出的 function 按值返回结构?

[英]returning struct by value from ispc-exported function?

I can not get at c++-side a struct by value from exported ispc-function (ispc v1.12 and msvc 2017 are used).我无法从导出的 ispc 函数(使用 ispc v1.12 和 msvc 2017)中按值在 c++ 端获取结构。 Program compiles and runs smoothly (32bit, debug mode), except i have empty fields where i expect non-zero values.程序编译和运行顺利(32 位,调试模式),除了我有空字段,我期望非零值。 In 32bit release mode i have slightly different values.在 32 位发布模式下,我的值略有不同。 In 64bit i always have zeros at c++-side.在 64 位中,我在 c++ 端总是有零。 I have not found any direct mention or example of such snippet around.我还没有找到任何直接提及或此类片段的示例。 Bundled samples contain only void or primitive types returning exported functions.. My code:捆绑样本仅包含返回导出函数的 void 或原始类型。我的代码:

kernel.ispc: kernel.ispc:

struct fp32_2 { float v0, v1; };

export uniform fp32_2 loopback( uniform float arg0, uniform float arg1 ){
    uniform fp32_2 result;
    result.v0 = arg0;
    result.v1 = arg1;
    print( "ispc side: v0 = %\n", result.v0 );
    print( "ispc side: v1 = %\n", result.v1 );
    return result;
    }

kernel.h (generated by ispc, related parts): kernel.h(ispc生成,相关部分):

#ifndef __ISPC_STRUCT_fp32_2__
#define __ISPC_STRUCT_fp32_2__
struct fp32_2 {
    float v0;
    float v1;
};
#endif
...
extern "C"{
    extern struct fp32_2 loopback(float arg0, float arg1);
}

main.cpp:主.cpp:

#include "kernel.h"
#include <iostream>

int main(){
    auto res = ispc::loopback( 10.0f, 11.0f );
    std::cout << "c++ side: v0 = " << res.v0 << "\n";
    std::cout << "c++ side: v1 = " << res.v1 << "\n";
    }

command line parameters for ispc file compiling (for 32bit debug mode): ispc 文件编译的命令行参数(用于 32 位调试模式):

ispc %(FullPath) --arch=x86 --target-os=windows --target=sse4-i32x4
-O1 --opt=disable-loop-unroll --emit-obj --outfile=$(IntDir)%(FileName).obj
--header-outfile=%(RootDir)%(Directory)%(Filename).h --werror -g

output (32 bit debug mode or 64bit both modes): output(32位调试模式或64位两种模式):

ispc side: v0 = 10.000000
ispc side: v1 = 11.000000
c++ side: v0 = 0
c++ side: v1 = 0

output (32bit release mode): output(32bit发布模式):

ispc side: v0 = 10.000000
ispc side: v1 = 11.000000
c++ side: v0 = 0
c++ side: v1 = 5.39308e+33

Each run i got same values.每次运行我都得到相同的值。 What am i missing or doing wrong?我错过了什么或做错了什么?

Thanks in advance提前致谢

This should work correctly.这应该可以正常工作。 I would file an issue on Github or contact them on the listserv.我会在 Github 上提出问题或在 listserv 上与他们联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM