I am trying to display with directX on the screen some results I calculated with CUDA.
I have these CUDA functions:
void
CopyResultToDisplay (int2 A_PatternSize, float4 * A_Color, float4 * A_Result, IDirect3DVertexBuffer9 * A_VB)
{
if (A_VB==NULL)
return;
CUDA_SAFE_CALL(cudaD3D9RegisterVertexBuffer(A_VB));
ColorVertex * MapVB;
CUDA_SAFE_CALL(cudaD3D9MapVertexBuffer((void**)&MapVB, A_VB));
GridDim g = CalculateGridDim (A_PatternSize);
CopyIntoDirectX<<< g.grid, g.threads >>>(A_PatternSize, A_Color, A_Result, MapVB);
CUDA_SAFE_CALL(cudaD3D9UnmapVertexBuffer(A_VB));
CUDA_SAFE_CALL(cudaD3D9UnregisterVertexBuffer(A_VB));
}
extern "C" void
InitDevice (IDirect3D9 * A_D3DObject, IDirect3DDevice9 * A_Device)
{
D3DADAPTER_IDENTIFIER9 AdapterId;
A_D3DObject->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &AdapterId);
int Device;
if (cudaSuccess == cudaD3D9GetDevice(&Device, AdapterId.DeviceName))
CUDA_SAFE_CALL(cudaSetDevice(Device));
CUDA_SAFE_CALL(cudaD3D9Begin(A_Device));
}
extern "C" void
CleanupD3D9 ()
{
CUDA_SAFE_CALL(cudaD3D9End());
}
__global__ void
CopyIntoDirectX (int2 A_Size, float4 * A_Color, float4 * A_Result, ColorVertex * A_VB)
{
long tx = threadIdx.x+blockIdx.x*20;
long ty = threadIdx.y+blockIdx.y*20;
// A_VB[tx+ty*A_Size.x].Color = 100;
A_VB[0].Color = 100;
}
If I put “A_VB[0].Color” in a remark, then everything works as usual.
I get to see the vertex buffer displayed into the window, but without the values from the kernel of CUDA.
If I put A_VB[0].Color then it seems that the GPGPU function I calculated in CUDA(not CopyIntoDirectX), is not being called. I can tell this because the FPA becomes a lot higher.
However, when I exit the program I get a memory exception of some sort.
I don’t know why it doesnt work.
Also, when I try to run simpleD3D program in release it gets stuck(in Emu it works).
Release of simpleD3D worked for me before(I think), but now it doesnt.
I will check again, maybe it never works in release mode.
How can I tell what I am doing wrong? Are there no errors that tell me when I did something wrong?
Thank you.