Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Raycaster不使用OpenCL_Java_Debugging_Opencl_Lwjgl - Fatal编程技术网

Java Raycaster不使用OpenCL

Java Raycaster不使用OpenCL,java,debugging,opencl,lwjgl,Java,Debugging,Opencl,Lwjgl,我正在尝试用OpenCL和Java(LWJGL)编写一个raycaster引擎 但是,在运行内核时,我无法打印f,也无法写入调试变量。我有一种感觉,内核突然被切断了,这也是因为《时代周刊》(opencl之外)显示了非常快的结果(60fps),比mandelbrot示例更快 我正在研究gDEBugger,但我认为它不支持Java 由于我是初学者,所以对我的代码构成的任何评论都是非常受欢迎的。也欢迎对我的raycast数学的评论 #ifdef USE_TEXTURE #define OUTP

我正在尝试用OpenCL和Java(LWJGL)编写一个raycaster引擎

但是,在运行内核时,我无法打印f,也无法写入调试变量。我有一种感觉,内核突然被切断了,这也是因为《时代周刊》(opencl之外)显示了非常快的结果(60fps),比mandelbrot示例更快

我正在研究gDEBugger,但我认为它不支持Java

由于我是初学者,所以对我的代码构成的任何评论都是非常受欢迎的。也欢迎对我的raycast数学的评论

#ifdef USE_TEXTURE
    #define OUTPUT_TYPE __write_only image2d_t
#else
    #define OUTPUT_TYPE global uint *
#endif

#define MAX_RAY_LENGTH 1024


bool isSolid(int x, int y, int z, global uchar *objectIsSolidStorage, int width, int height, int depth) {
    uint placex = x / 8;
    uint placey = y / 8;
    uint placez = z / 8;

    uint widthbychar = (width/8);
    uint heightbychar = (height/8);
    int calcbychar = placex + placey * widthbychar + placez * widthbychar * heightbychar;

    int leftover = x % 8;
    uchar solidchar = objectIsSolidStorage[calcbychar];

    if (x > width || y > height || z >> depth ||
        x < 0 || y < 0 || z < 0) return 1;

    if ((solidchar & ( 1 << leftover )) >> leftover) {
        return 1;
    }
    return 0;
}

int getColor(int x, int y, int z)
{
        return 0xFFFFFFFF;
}

kernel void raycast(
        const int width,
        const int height,
        const float positionX,
        const float positionY,
        const float positionZ,
        const float directionX,
        const float directionY,
        const float directionZ,
        OUTPUT_TYPE output,
        global uchar *objectIsSolidStorage,
        const int objectStorageWidth,
        const int objectStorageHeight,
        const int objectStorageDepth,
        global uint *objectColorStorage,
        global uint *smallObjectsMap,
        global uint *hangableObjectsMap,
        global uint *largeObjectsMap,
        const int objectMapWidth,
        const int objectMapHeight,
        const float frustrumAngleX,
        const float frustrumAngleY,
        global char debug
) {

    unsigned int rayx = get_global_id(0);
    unsigned int rayy = get_global_id(1);

    bool hit = false;
    int itr = 0;
    float x = positionX;
    float y = positionY;
    float z = positionZ;

    printf("work");
    int addX = (rayx - width / 2) * frustrumAngleX;
    int addY = (rayy - height / 2) * frustrumAngleY;
    int color = 0xFFAAFF;
    while(!hit) {
        x += addX;
        y += addY;
        z += itr;
        if (MAX_RAY_LENGTH < itr) {
            hit = true;
            color = 0xFFFFFFFF;
            break;
        } else if (isSolid(x,y,z,objectIsSolidStorage,objectStorageWidth,objectStorageHeight,objectStorageDepth)) {
            hit = true;
            color = 0xAAAAAAAA;
            break;
        }
        itr++;
    }

    #ifdef USE_TEXTURE
        float4 oc = (float4)(
            (c & 0xFF) >> 0,
            (c & 0xFF00) >> 8,
            (c & 0xFF0000) >> 16,
            255.0f
        );
        write_imagef(output, (int2)(rayx, rayy), color / 255.0f);
    #else
        output[rayy * width + rayx] = color;
    #endif
}
\ifdef使用纹理
#定义输出类型只写图像2D
#否则
#定义输出类型全局uint*
#恩迪夫
#定义最大光线长度1024
布尔isSolid(整数x、整数y、整数z、全局uchar*对象滑动存储、整数宽度、整数高度、整数深度){
uint placex=x/8;
uint placey=y/8;
uint placez=z/8;
uint widthbychar=(宽度/8);
uint heightbychar=(高度/8);
int calcbychar=placex+placey*widthbychar+placez*widthbychar*heightbychar;
整数剩余=x%8;
uchar solidchar=objectssolidstorage[calcbychar];
如果(x>宽度| | y>高度| | z>>深度||
x<0 | | y<0 | | z<0)返回1;
如果((solidchar&(1>剩余){
返回1;
}
返回0;
}
intgetColor(intx,inty,intz)
{
返回0xFFFFFF;
}
核空穴光线投射(
常量整数宽度,
const int height,
常量浮点位置X,
const浮动位置,
常量浮点位置Z,
常量浮点方向X,
常量浮点方向,
常量浮点方向z,
输出类型输出,
全球uchar*目标滑动存储,
常量int objectStorageWidth,
常量int对象存储高度,
常量int objectStorageDepth,
全局uint*对象颜色存储,
全局uint*小对象SMAP,
全球uint*hangableObjectsMap,
全局uint*大对象映射,
常量int objectMapWidth,
const int objectMapHeight,
常量浮点frustrumAngleX,
康斯特·曼格利,
全局字符调试
) {
unsigned int rayx=获取全局id(0);
unsigned int rayy=get_global_id(1);
bool-hit=false;
int-itr=0;
浮动x=位置x;
浮动y=位置y;
浮动z=位置z;
printf(“工作”);
int addX=(rayx-宽度/2)*frustrumAngleX;
int addY=(光线-高度/2)*弗罗斯特鲁曼格利;
int color=0xFFAAFF;
而(!击中){
x+=addX;
y+=addY;
z+=itr;
if(最大射线长度>0,
(c&0xFF00)>>8,
(c&0xFF0000)>>16,
255.0f
);
写入图像f(输出,(int2)(光线,光线),颜色/255.0f);
#否则
输出[光线*宽度+光线]=颜色;
#恩迪夫
}

您可以在CPU上运行它进行调试(amd扩展)


#pragma OPENCL EXTENSION cl_amd_printf:enable

它应该适用于您的OPENCL+java开发:使用简单的


构建日志::9:26:警告:忽略“#pragma OPENCL”中的预期标识符我正在使用#pragma OPENCL EXTENSION cl#u intel#printf:启用,因为我使用的是英特尔CPU,您在英特尔x86-64上使用的是什么OPENCL实现?OPENCL 1.1。它基于JOCL(Java OPENCL)在LWJGL中,抱歉,但这是不正确的。LWJGL与CL的java绑定不是基于JOCL的。