But I found in this way, there is always an error :
Invalid value (Details: Function “RTresult _rtContextCompile(RTcontext)” caught exception: Initalization of non-primitive type buffer: Buffer object, [1769653])
So I attach this Buffer with an OptiX Variable “buffer_a” and no more such error again. I wonder why I never succeed without doing this. Did I miss something in the manual?
My recollection is that the c++ API overload for Context::operator will check if the buffer has been created, and if not, will create it, so you can go ahead and use it without first creating it yourself. However, the C API requires that you manually create and init your buffer before using it. This may explain the error you’re seeing. Are you calling
You try to use the buffer in the cuda-file using the name “random_buffer”.
But you do not tell the OptiX context what buffer corresponds to this name.
This is the reason for the exception.
On the host side, you must tell the OptiX context which buffer is “connected” to the name “random_buffer” which is then accessed on the device side. You can do this using the C or the C++ API.
So this is the very first question I asked at beginning : I wonder why the buffer never works without attaching it to an OptiX Variable. Because in the manual when it introduces host access to buffer, it doesn’t mention that it’s necessary to combine the buffer with a context.
Here is the code example for host-side from manual :
So I had to double check the manual to see if you’re right, and you are. The Programming Guide in the buffer chapter doesn’t explicitly say the buffer needs to be set with a name. Like m_sch said, this is something you need to do (and it looks like you’ve figured that out). Something like:
Exactly!
Actually I work with the SDK and just curious about why such non-introduced declaration should be used. I thought I missed something important in the manual.
Thanks a lot for your advice, over0219.