Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems using DepthBuf inputs #44

Closed
drmateo opened this issue Dec 19, 2018 · 1 comment
Closed

Problems using DepthBuf inputs #44

drmateo opened this issue Dec 19, 2018 · 1 comment

Comments

@drmateo
Copy link
Contributor

drmateo commented Dec 19, 2018

Hi,

I'm trying to use DepthBuf as inputs for my use case. The code that I've written is similar to the gRenderKernel sample which actually is working correctly in my computer.

The host part looks like the following:

	int w = 1024, h = 768;

  	VolumeGVDB gvdb;

	int devid = -1;
	gvdb.SetCudaDevice ( devid );
	gvdb.Initialize ();
	gvdb.getScene()->SetVolumeRange ( 0.01f, 1.0f, 0.0f );

	Camera3D* cam = new Camera3D;						
	cam->setOrbit ( Vector3DF(20,30,0), Vector3DF(125,160,125), 800, 1.0f );		
	gvdb.getScene()->SetCamera( cam );	
	gvdb.getScene()->SetRes ( w, h );
	
	Light* lgt = new Light;	
	lgt->setOrbit ( Vector3DF(50,65,0), Vector3DF(125,140,125), 200, 1.0f );
	gvdb.getScene()->SetLight ( 0, lgt );		
	
	gvdb.AddDepthBuf ( 3, w, h );

       void* data;
       // do some stuff to get image in data pointer
     
       GLuint gl_depth_raw_tex;
       glGenBuffers(0, &gl_depth_raw_tex);
       glBindTexture(GL_TEXTURE_2D, gl_depth_raw_tex);
       glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_FLOAT, data);
        glBindTexture(GL_TEXTURE_2D, 0);

	cudaCheck ( cuModuleLoad ( &cuCustom, "custom.ptx" ), "cuModuleLoad (render_custom)" );
	cudaCheck ( cuModuleGetFunction ( &cuRaycastKernel, cuCustom, "kernel" ), "cuModuleGetFunction (kernel)" );	

	gvdb.SetModule ( cuCustom );

	gvdb.getScene()->SetSteps ( 0.25f, 16, 0.25f );
	gvdb.getScene()->SetVolumeRange ( 0.1f, 0.0, 1.0f );
	gvdb.RenderKernel ( cuRaycastKernel, 0, 3 );

       gvdb.WriteDepthTexGL(3, gl_depth_raw_tex);

And the kernel part is like this:

extern "C" __global__ void allocate_bricks (VDBInfo* gvdb, uchar chan, uchar4* outBuf )
{
	int u = blockIdx.x * blockDim.x + threadIdx.x;
	int v = blockIdx.y * blockDim.y + threadIdx.y;
	printf("%d %d\n", scn.width, scn.height);
	if ( u >= scn.width || v >= scn.height ) return;

       // do something
}

And the problem that I'm facing is that width and height values of scn (ScnInfo) (can be used through macros SCN_WIDTH and SCN_HEIGHT) are 0, so this kernel is doing nothing. I've been reading the gvdb core to find some clues but now I'm more confused because actually when RenderKernel is called, PrepareRender is executed setting up mScnInfo and then transferring the new ScnInfo to device.

Then, does anyone know where I'm losing?

@drmateo
Copy link
Contributor Author

drmateo commented Dec 19, 2018

Let me answer myself. I made a mistake, I forgot to add in host code part

gvdb.SetModule ( cuCustom ); 

This has made me realize how important is this member method to work with custom modules since actually this function synchronize global members in custom modules (.ptx).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant