returning struct by value from ispc-exported function?

163 views Asked by At

I can not get at c++-side a struct by value from exported ispc-function (ispc v1.12 and msvc 2017 are used). Program compiles and runs smoothly (32bit, debug mode), except i have empty fields where i expect non-zero values. In 32bit release mode i have slightly different values. In 64bit i always have zeros at c++-side. 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:

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):

#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:

#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 %(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):

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

output (32bit release mode):

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

1

There are 1 answers

0
pbrubaker On

This should work correctly. I would file an issue on Github or contact them on the listserv.