ispc icon indicating copy to clipboard operation
ispc copied to clipboard

Short vectors are not generated in C++ header

Open floeffler opened this issue 4 years ago • 1 comments

In a very special case the short vectors are not generated in the C++ header file. If you use short vectors in a function prototype and this function proto is used in an exported struct, the generated header does not contain a definition for used short vectors. This leads to compile issues in the host code. Here is a minimal example to reproduce the issue:

struct MyStruct;

typedef void (*MyFunc)(varying float<2>&a, uniform int<2>& b);

struct MyStruct {
	uniform MyFunc func;
	int data;
};

export void my_struct_init(uniform MyStruct& my_struct) { 
	my_struct.func = NULL;
}

The function prototype generated in the C++ header is partially wrong.

#ifndef __ISPC_STRUCT_MyStruct__
#define __ISPC_STRUCT_MyStruct__
struct MyStruct {
    void ( * func)(float2   &a, int32_t2   &b);
    int32_t data;
};
#endif 

a is a varying type and hence should be (with regard to the documentation) a pointer to float2. Further Ispc does not generate a definition for float2 which leads to compiler error: syntax error: identifier 'float2'

I use ISPC 1.5.0. I do not tested it with other versions.

floeffler avatar Feb 12 '21 16:02 floeffler

The problem is that lEmitVectorTypedefs() is not designed to emit varying short vector definitions: https://github.com/ispc/ispc/blob/f390931d5dc5f2c62efaa42441c117430d414bc3/src/module.cpp#L1546

Seems that proper fix would need to:

  • fix lEmitVectorTypedefs() to emit proper definition of varying short vector
  • make sure that a warning is issued if the target is compiled for multiple targets with different width (i.e. inconsistent varying type defintions).

dbabokin avatar Jan 13 '22 20:01 dbabokin