5

So what I want to do is:

  1. Load a file encrypted with any algorithm (in my case AES-256) into GPU memory (with CUDA).

  2. Decrypt the file with all the GPU parallel awesomeness we have right now and let it stay in GPU memory.

  3. Now tell OpenGL (4.3) that there is a texture in memory that needs to be read and decompressed from DDS DXT5.

Point 3 is where I have my doubts. Since to load a compressed DDS DXT5 in OpenGL one has to call openGL::glCompressedTexImage[+ 2D|3D|2DARB...] with the compression type (GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) and a pointer to the image data buffer.

So, to make it short -> is there a way to pass a texture buffer address already in GPU memory to OpenGL (in DDS format)? Without this option, I would need to transfer the AES decrypted file back to the CPU and tell OpenGL to load it again into the GPU....

Many thanks for any help or short examples ;)

James Takarashy
  • 299
  • 2
  • 14
  • This doesn't seem like a good idea. First, you need to be sure that the file is encrypted in a block chaining mode that supports decryption in parallel (doing things in parallel is the entire point of a GPU). Then the texture has to be large enough for the overhead of setting up everything on the GPU to be worth the time savings. Additionally, CPUs have dedicated hardware for AES; GPUs don't. – Colonel Thirty Two Aug 31 '16 at 14:00
  • 1
    @ColonelThirtyTwo: None of those are what he's asking about. The AES decrpytion and so forth are irrelevant noise. The question is, given a GPU operation that generates compressed texture data (the AES stuff being how it gets generated, which again is not the point), can you store that in an OpenGL texture without copying it back to the CPU? The question is well-focused; just noisy. – Nicol Bolas Aug 31 '16 at 14:05
  • AES encrypts in blocks of 128bit already and solutions like gKrypt (http://gkrypt.com/) have a huge decompression boost already! The textures I'm using will be of size between 2k to 4k (or even 8k end of this year). But thx for your concerns :)! – James Takarashy Aug 31 '16 at 14:11
  • @Nicol Bolas Thx you are right I over-noised it a bit ;) – James Takarashy Aug 31 '16 at 14:14
  • @NicolBolas I noticed after I posted my comment. I've retracted my close vote, though my concerns about the approach still stand (though I don't mind being proven wrong). – Colonel Thirty Two Aug 31 '16 at 14:16
  • You can't "load into shared memory" on NVIDIA GPUs, so none of this is going to work. – talonmies Aug 31 '16 at 15:01
  • @talonmies [What Every CUDA Programmer Should Know About OpenGL](http://www.nvidia.com/content/gtc/documents/1055_gtc09.pdf) – James Takarashy Aug 31 '16 at 20:50
  • @JamesTakarashy: Your point being? Shared memory is a high speed local scope scratch space which can't be accessed from any host side API, be that GL, CUDA, OpenCL or Direct3D. Nowhere is it mentioned in that slide deck you linked to – talonmies Aug 31 '16 at 20:54

2 Answers2

3

You need to do two things.

First, you must ensure synchronization and visibility for the operation that generates this data. If you're using a compute shader to generate the data into an SSBO, buffer texture, or whatever, then you'll need to use glMemoryBarrier, with the GL_PIXEL_BUFFER_BARRIER_BIT set. If you're generating this data via a rendering operation to a buffer texture, then you won't need an explicit barrier. But if the FS is writing to an SSBO or via image load/store, you'll still need the explicit barrier as described above.

If you're using OpenCL, then you'll have to employ OpenCL's OpenGL interop functionality to make the result of the CL operation visible to GL.

Once that's done, you just use the buffer as a pixel unpack buffer, just as you would for any asynchronous pixel transfer operation. Compressed textures work with GL_PIXEL_UNPACK_BUFFER just like uncompressed ones.

Remember: in OpenGL, all buffer objects are the same. OpenGL doesn't care if you use a buffer as an SSBO one minute, then use it for pixel transfers the next. As long as you synchronize it, everything is fine.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
1

Bind your buffer to GL_PIXEL_UNPACK_BUFFER and call glCompressedTexSubImage2D with data being an offset into the buffer.

Read more about PBO here.

pleluron
  • 733
  • 4
  • 12
  • Thx a lot! I'm relatively new to CG and after I read about PBOs tonight I will mark your answer according to the outcome of my research ;) – James Takarashy Aug 31 '16 at 14:17