sgsrules's picture

Bindless graphics

I'm trying to play around with nvidias bindless graphics but can't find any of the tokens or functions in openk. here's a sample taken from nvidia's presentation:

for (i = 0; i < N; ++i) {
BindBuffer(ARRAY_BUFFER, vboNames[i]);
BufferData(ARRAY_BUFFER, size, ptr, STATIC_DRAW);
GetBufferParameterui64vNV(ARRAY_BUFFER, BUFFER_GPU_ADDRESS_NV, &vboAddrs[i]); //where's this function?
MakeBufferResidentNV(ARRAY_BUFFER, READ_ONLY);  //where's this function?
ColorFormatNV(4, UNSIGNED_BYTE, 20);
VertexFormatNV(4, FLOAT, 20);
EnableClientState(VERTEX_ATTRIB_ARRAY_UNIFIED_NV);  //where's this token?
for (i = 0; i < N; ++i) {
// point at buffer i
BufferAddressRangeNV(COLOR_ARRAY_ADDRESS_NV, 0, vboAddrs[i], size);  //where's this function?
BufferAddressRangeNV(VERTEX_ARRAY_ADDRESS_NV, 0, vboAddrs[i]+4, size-4);  //where's this function?
DrawArrays(POINTS, 0, size/20);


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

EnableClientState(VERTEX_ATTRIB_ARRAY_UNIFIED_NV);  //where's this token?

OpenTK doesn't add extension tokens to core enums for various reasons. You will need to cast from the "All" enum.

BufferAddressRangeNV(COLOR_ARRAY_ADDRESS_NV, 0, vboAddrs[i], size)

Nvidia-specific extensions are available under GL.NV.*.

sgsrules's picture

Maybe i'm missing something but i triple checked GL.NV.* and didn't see BufferAddressRangeNV or MakeBufferResidentNV. I also checked the all enums and didn't see them. I even did a search through the opentk source (svn and came up empty so i'm pretty sure they're not in there.

the Fiddler's picture

Thanks. OpenTK is not yet synced to the latest OpenGL specs so it is missing some functions. You can use the following commands to fetch, update and build the gl4 branch:

(Install TortoiseSVN and open a Visual Studio command prompt)

svn co gl4
cd gl4
msbuild OpenTK.sln /p:Configuration=Release
cd Binaries/OpenTK/Release
Convert.exe -p:gl -t:spec -o:../../../Source/Bind/Specifications/GL2/signatures.xml
cd ..\..\..
msbuild OpenTK.sln /p:Configuration=Release

If all goes well, the new OpenTK.dll will contain those functions.

sgsrules's picture

Thanks for all the help. But It failed to build the second time. I received 110 errors here's the last few:

  Graphics\OpenGL\GL.cs(161494,62): error CS0246: The type or namespace name 'v
dpauSurfaceNV' could not be found (are you missing a using directive or an asse
mbly reference?) [C:\GL4\Source\OpenTK\OpenTK.csproj]
  Graphics\OpenGL\GL.cs(161509,41): error CS0246: The type or namespace name 'v
dpauSurfaceNV' could not be found (are you missing a using directive or an asse
mbly reference?) [C:\GL4\Source\OpenTK\OpenTK.csproj]
  Graphics\OpenGL\GLHelper.cs(819,68): error CS0246: The type or namespace name
 'DrawElementsType' could not be found (are you missing a using directive or an
 assembly reference?) [C:\GL4\Source\OpenTK\OpenTK.csproj]
  Graphics\OpenGL\GL.cs(82530,34): error CS0246: The type or namespace name 'St
encilFace' could not be found (are you missing a using directive or an assembly
 reference?) [C:\GL4\Source\OpenTK\OpenTK.csproj]
  Graphics\OpenGL\GL.cs(82559,34): error CS0246: The type or namespace name 'St
encilFace' could not be found (are you missing a using directive or an assembly
 reference?) [C:\GL4\Source\OpenTK\OpenTK.csproj]
  Graphics\OpenGL\GL.cs(82630,32): error CS0246: The type or namespace name 'St
encilFace' could not be found (are you missing a using directive or an assembly
 reference?) [C:\GL4\Source\OpenTK\OpenTK.csproj]
    7 Warning(s)
    110 Error(s)
Time Elapsed 00:00:01.71
the Fiddler's picture

Ah, yes, these types are new to GL4 and I haven't committed the relevant code yet. Sorry about that.

Try adding the following lines to Source/Bind/Specifications/ as a workaround:

_cl_context, IntPtr
_cl_event, IntPtr
GLvdpauSurfaceNV, IntPtr
StencilFace, int

Afterwards, rerun Bind.exe and try to recompile.

sgsrules's picture

ok i got it working but honestly i'm not to sure if what i'm doing is correct, here's what i did:

added to

GLvdpauSurfaceNV, IntPtr
vdpauSurfaceNV, IntPtr

added the following enums to GLEnums.cs:

public enum StencilFace : int
        Front = ((int)0x0404),
        Back = ((int)0x0405),
        FrontAndBack = ((int)0x0408),
  public enum DrawElementsType : int
        UnsignedByte = ((int)0x1401),
        UnsignedShort = ((int)0x1403),
        UnsignedInt = ((int)0x1405),

For DrawElements and DrawElementsInstanced i changed the type from version11 and version31 to DrawElementsType

added the following to PixelInternalFormat Enum:

  Alpha = ((int)0x1906),
  Rgb = ((int)0x1907),
  Rgba = ((int)0x1908),

I still havent tested the bindless stuff yet, hopefully i'll get the 7x performance boost nvidia claims ( i really doubt it) Anyhow once again Fiddler thanks for all the help!


sgsrules's picture

I'm having problems with some of the parameters inf these functions:

 long vertexAdd; //holds the gpu address of the buffer
 uint[] vertexVbo = new uint[1];
public void Init()
   GL.GenBuffers(1, vertexVbo);
   GL.BindBuffer(BufferTarget.ArrayBuffer, vertexVbo[0]);
   GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertex.Length * sizeof(float)), Vertex, BufferUsageHint.StaticDraw);
   GL.NV.GetBufferParameterui64((NvShaderBufferLoad)BufferTarget.ArrayBuffer, NvShaderBufferLoad.BufferGpuAddressNv,out vertexAdd); // the last parameter stores the buffers address in a long?
   GL.NV.MakeBufferResident((NvShaderBufferLoad)BufferTarget.ArrayBuffer, (NvShaderBufferLoad)All.ReadOnly);  // is it ok to cast enumerators?
   GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
public void Render()
  GL.EnableClientState((EnableCap)NvVertexBufferUnifiedMemory.VertexAttribArrayUnifiedNv);  // is it ok to cast enumerators?
  GL.NV.BufferAddressRange(NvVertexBufferUnifiedMemory.VertexArrayAddressNv, 0, vertexAdd, (IntPtr)(Vertex.Length * sizeof(float))); // am i using the gpu address correctly?
  GL.DrawArrays(BeginMode.Points, 0, count);

This is a simplified test case and crashes really badly, i suspect it's because of how i'm storing and using the gpu address. I don't receive any opengl errors until i call GL.DrawArrays then it flickers and dies :(

the Fiddler's picture

Try compiling and using a debug OpenTK.dll, which will inform you about any gl-related errors automatically.

About your questions:

  • Casting enums is safe as long as the relevant extension is supported (debug version of OpenTK will catch such errors).
  • GetBufferParameterui64 is defined to take a long as address (that's what the '64' suffix means).
  • Your BufferAddressRange call looks correct.

I've never used bindless graphics myself, so I can't tell if you are using them correctly. Maybe someone can help here?

pigu66's picture

Hi Fidder,
I’m trying to do the same procedure to implement bindless graphics, as suggested by NVIDIA.
The reason is that using OpenGL 2.x drawing method without shader programming and extensive use of buffer object for vertex, normals and texturing, my application has dramatic lack of performance with adapter based on Fermi architecture (from GT8600M to GT555M the paint time increases 4 times). The BindBuffer operation is suspected to be the bottleneck.
Then I downloaded g4 branch and tried to follow the procedure you suggested. Running Convert.exe with just downloaded enum.spec (from, it throws an exception on row 130: Convert seems not able to parse the syntax of enum.spec.
Do you have any suggestion to solve that problem ?
Many Thanks

This is the stack trace of COnvert error:
in CHeaderToXML.GLParser.d__0.MoveNext() in I:\paolo\test\OpenTK\g4\Source\Converter\GLParser.cs:riga 94
in System.Linq.Enumerable.d__14`2.MoveNext()
in System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
in CHeaderToXML.EntryPoint.MergeDuplicates(IEnumerable`1 sigs) in I:\paolo\test\OpenTK\g4\Source\Converter\Main.cs:riga 182
in CHeaderToXML.EntryPoint.Main(String[] args) in I:\paolo\test\OpenTK\g4\Source\Converter\Main.cs:riga 121
in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart()

the Fiddler's picture

The gl4 branch is obsolete. It has been folded into trunk, so just checkout that and you are good to go (bindless graphics are available out of the box, no need to run the generator).