I have written .cpp as follows:
float* A;
float* res;
A = new float[4];
A[0] = 0.1f;
A[1] = 0.2f;
A[2] = 0.3f;
A[3] = 0.4f;
// Initialize CAL, a CALdevice and a CALcontext.
CALdevice device = 0;
CALcontext ctx = 0;
if (!Initialize(&device, &ctx, 0))
{
return 0;
}
// Compile, Link and load the shader into a CALmodule.
CALmodule module;
if (!SetupKernel(ILKernel, &module, &ctx))
{
return 0;
}
CALmem iMem;
CALmem oMem;
CALresource iRes;
CALresource oRes;
Data Inputs;
Data Outputs;
//Allocate memory
Inputs.DataSize = sizeof(CALfloat);
Inputs.Width = 2;
Inputs.Height = 2;
Inputs.ComponentSize = 1;
int num = 2 * 2 * Inputs.DataSize ;
Inputs.c_data = new CALchar
kernel is :
kernel
void test(float a<>, out float res<>{
res = a;
}
I get the result :
1 0.1
2 0
3 0.3
4 0
Data , and some functions are from sample.h
Can somebody help me?
I changed CAL_FORMAT_FLOAT_2 to CAL_FORMAT_FLOAT_1
got the result
1 0.1
2 0.2
3 -2.87352e-16
4 -2.87352e-16
Please post the IL code that is producing the wrong results.
const CALchar ILKernel[] =
"il_ps_2_0\n"
"dcl_literal l0,0x00000000,0x00000000,0x00000000,0x00000000\n"
"dcl_literal l1,0x00000001,0x00000001,0x00000001,0x00000001\n"
"dcl_literal l2,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF\n"
"dcl_literal l3,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF\n"
"dcl_literal l4,0x7F800000,0x7F800000,0x7F800000,0x7F800000\n"
"dcl_literal l5,0x80000000,0x80000000,0x80000000,0x80000000\n"
"dcl_literal l6,0x3E9A209B,0x3E9A209B,0x3E9A209B,0x3E9A209B\n"
"dcl_literal l7,0x3F317218,0x3F317218,0x3F317218,0x3F317218\n"
"dcl_literal l8,0x40490FDB,0x40490FDB,0x40490FDB,0x40490FDB\n"
"dcl_literal l9,0x3FC90FDB,0x3FC90FDB,0x3FC90FDB,0x3FC90FDB\n"
"dcl_literal l10,0x00000003,0x00000003,0x00000003,0x00000003\n"
"dcl_literal l11,0x00000002,0x00000002,0x00000002,0x00000002\n"
"dcl_output_usage(generic) o0.xyzw\n"
"dcl_resource_id(0)_type(2d,unnorm)_fmtx(float)_fmty(float)_fmtz(float)_fmtw(float)\n"
"dcl_input_position_interp(linear_noperspective) v0.xy__\n"
"mov r272.xy__,v0.xyzw\n"
"call 38 \n"
"call 0 \n"
"endmain\n"
"\n"
"func 0\n"
"mov o0.xyzw,r271.xyzw\n"
"ret\n"
"\n"
"func 2\n"
"ieq r0.x___,r17.x000,l0.x000\n"
"if_logicalnz r0.x000\n"
"sample_resource(0)_sampler(0) r19.xyzw,r18.xy00\n"
"endif\n"
"mov r16.x___,r19.x000\n"
"ret_dyn\n"
"ret\n"
"\n"
"func 37\n"
"mov r270.x___,r269.x000\n"
"ret\n"
"\n"
"func 38\n"
"mov r276.xy__,r272.xy00\n"
"mov r17.x___,l0.x000\n"
"mov r18.xy__,r276.xy00\n"
"call 2 \n"
"mov r279.x___,r16.x000\n"
"mov r274.x___,r279.x000\n"
"mov r269.x___,r274.x000\n"
"call 37 \n"
"mov r275.x___,r270.x000\n"
"mov r277.x___,r275.x000\n"
"mov r277._y__,l0.0x00\n"
"mov r277.__z_,l0.00x0\n"
"mov r277.___w,l0.000x\n"
"mov r273.xyzw,r277.xyzw\n"
"mov r271.xyzw,r273.xyzw\n"
"ret_dyn\n"
"ret\n"
"\n"
"end\n";
that is
const char __test_cal_desc_tech0_pass0[]
in the created file .
What do you expect the results to be? The code CAL/IL is correct and it might be more a misunderstanding of what you think is going on to what is actually going on.