Commit 0fdb4ed4a7be8cf86aa6f4dffbd412ccdb3e09e7
1 parent
32c433c7
fixed the issue with the improperly visualized textures as well as the cost func…
…tion. The cost and gl/cuda/gl ping-pong is fully functional
Showing
2 changed files
with
22 additions
and
10 deletions
Show diff stats
cuda/cost.h
@@ -46,7 +46,7 @@ float get_sum(float *diff) | @@ -46,7 +46,7 @@ float get_sum(float *diff) | ||
46 | 46 | ||
47 | __device__ float Template(int x) | 47 | __device__ float Template(int x) |
48 | { | 48 | { |
49 | - if(x < DIM_X/3 || x > DIM_X*2/3){ | 49 | + if(x < DIM_X/6 || x > DIM_X*5/6 || (x > DIM_X*2/6 && x < DIM_X*4/6)){ |
50 | return 1.0; | 50 | return 1.0; |
51 | }else{ | 51 | }else{ |
52 | return 0.0; | 52 | return 0.0; |
@@ -61,18 +61,20 @@ void get_diff (float *result) | @@ -61,18 +61,20 @@ void get_diff (float *result) | ||
61 | int x = threadIdx.x + blockIdx.x * blockDim.x; | 61 | int x = threadIdx.x + blockIdx.x * blockDim.x; |
62 | int y = threadIdx.y + blockIdx.y * blockDim.y; | 62 | int y = threadIdx.y + blockIdx.y * blockDim.y; |
63 | int idx = y*DIM_X+x; | 63 | int idx = y*DIM_X+x; |
64 | + //idx = x*DIM_Y+y; | ||
64 | //int idx = x*DIM_X+y; | 65 | //int idx = x*DIM_X+y; |
65 | 66 | ||
66 | //uchar4 color = tex2D(texIn, x, y); | 67 | //uchar4 color = tex2D(texIn, x, y); |
67 | //float3 tempcolor = make_float3(color.x, color.y, color.z); | 68 | //float3 tempcolor = make_float3(color.x, color.y, color.z); |
68 | //float valIn = tempcolor.x + tempcolor.y + tempcolor.z; | 69 | //float valIn = tempcolor.x + tempcolor.y + tempcolor.z; |
69 | - float valIn = tex2D(texIn, x, y); | 70 | + float valIn = tex2D(texIn, x, y)/255.0; |
70 | float valTemp = Template(x); | 71 | float valTemp = Template(x); |
71 | - result[idx] = valIn; | 72 | + result[idx] = abs(valIn-valTemp); |
73 | + //-valTemp; | ||
72 | // - valTemp; | 74 | // - valTemp; |
73 | - //#if __CUDA_ARCH__>=200 | ||
74 | - // printf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); | ||
75 | - //#endif | 75 | +// #if __CUDA_ARCH__>=200 |
76 | +// printf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); | ||
77 | +// #endif | ||
76 | //cuPrintf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); | 78 | //cuPrintf("Value is : %f\n and the result is : %f\n", valIn, result[idx]); |
77 | } | 79 | } |
78 | 80 |
gl/gl_spider.h
@@ -312,6 +312,8 @@ class gl_spider : public virtual gl_texture<T> | @@ -312,6 +312,8 @@ class gl_spider : public virtual gl_texture<T> | ||
312 | ); | 312 | ); |
313 | glVertex2f(1.0, 2.0); | 313 | glVertex2f(1.0, 2.0); |
314 | glEnd(); | 314 | glEnd(); |
315 | + //glClearColor(1,1,1,1); | ||
316 | + //glClear(GL_COLOR_BUFFER_BIT); | ||
315 | glBindTexture(GL_TEXTURE_3D, 0); | 317 | glBindTexture(GL_TEXTURE_3D, 0); |
316 | glDisable(GL_TEXTURE_3D); | 318 | glDisable(GL_TEXTURE_3D); |
317 | glBindFramebuffer(GL_FRAMEBUFFER,0); | 319 | glBindFramebuffer(GL_FRAMEBUFFER,0); |
@@ -336,6 +338,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -336,6 +338,7 @@ class gl_spider : public virtual gl_texture<T> | ||
336 | width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texels); | 338 | width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texels); |
337 | delete[] texels; | 339 | delete[] texels; |
338 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | 340 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
341 | + glBindTexture(GL_TEXTURE_2D, 0); | ||
339 | } | 342 | } |
340 | 343 | ||
341 | 344 | ||
@@ -353,7 +356,7 @@ class gl_spider : public virtual gl_texture<T> | @@ -353,7 +356,7 @@ class gl_spider : public virtual gl_texture<T> | ||
353 | printf(" device name: %s\n", prop.name); | 356 | printf(" device name: %s\n", prop.name); |
354 | printf(" device maxTexture3D: %d %d %d\n", prop.maxTexture3D[0] ,prop.maxTexture3D[0], prop.maxTexture3D[2]) ; | 357 | printf(" device maxTexture3D: %d %d %d\n", prop.maxTexture3D[0] ,prop.maxTexture3D[0], prop.maxTexture3D[2]) ; |
355 | HANDLE_ERROR( cudaGLSetGLDevice (device)); */ | 358 | HANDLE_ERROR( cudaGLSetGLDevice (device)); */ |
356 | - stim::cudaSetDevice(); | 359 | + //stim::cudaSetDevice(); |
357 | /* HANDLE_ERROR( | 360 | /* HANDLE_ERROR( |
358 | cudaGraphicsMapResources(1, &resource, 0) | 361 | cudaGraphicsMapResources(1, &resource, 0) |
359 | ); | 362 | ); |
@@ -384,10 +387,14 @@ class gl_spider : public virtual gl_texture<T> | @@ -384,10 +387,14 @@ class gl_spider : public virtual gl_texture<T> | ||
384 | HANDLE_ERROR( | 387 | HANDLE_ERROR( |
385 | cudaGraphicsGLRegisterImage( | 388 | cudaGraphicsGLRegisterImage( |
386 | &resource, | 389 | &resource, |
387 | - fboID, | 390 | + texbufferID, |
388 | GL_TEXTURE_2D, | 391 | GL_TEXTURE_2D, |
389 | - CU_GRAPHICS_REGISTER_FLAGS_NONE) | 392 | + //CU_GRAPHICS_REGISTER_FLAGS_NONE) |
393 | + cudaGraphicsMapFlagsReadOnly) | ||
390 | ); | 394 | ); |
395 | + //HANDLE_ERROR( | ||
396 | + // cudaGraphicsMapResources(1, &resource) | ||
397 | + //); | ||
391 | } | 398 | } |
392 | 399 | ||
393 | void | 400 | void |
@@ -396,11 +403,14 @@ class gl_spider : public virtual gl_texture<T> | @@ -396,11 +403,14 @@ class gl_spider : public virtual gl_texture<T> | ||
396 | HANDLE_ERROR( | 403 | HANDLE_ERROR( |
397 | cudaGraphicsUnregisterResource(resource) | 404 | cudaGraphicsUnregisterResource(resource) |
398 | ); | 405 | ); |
406 | + //HANDLE_ERROR( | ||
407 | + // cudaGraphicsUnmapResources(1,&resource) | ||
408 | + //); | ||
399 | } | 409 | } |
400 | 410 | ||
401 | float | 411 | float |
402 | getCost() | 412 | getCost() |
403 | - { | 413 | + { |
404 | createResource(); | 414 | createResource(); |
405 | float cost = get_cost(resource); | 415 | float cost = get_cost(resource); |
406 | destroyResource(); | 416 | destroyResource(); |