[osg-users] Bindless Textures

David Heitbrink david-heitbrink at uiowa.edu
Fri Jul 15 07:21:51 PDT 2016


Has any one implemented bindless textures? I am trying to add this to my app to improve batching. I have a large scene, with lots of unique draw calls. We do use texture atlas's, the number of small objects is limited. I would like to further improve batching without having to redo textures. I do have LODs and occluder nodes as well.

Conveniently most of my objects use triangle list, so merging those worked out pretty well. I am using a shader storage buffer object to upload the texture handles to the shader. I have confirmed the value for the handles that I have set are getting into the shader. 

Here is the segment of my shader where I get the texture:

Code:


layout (binding = 0, std140) coherent buffer TEXTURE_BLOCK   
{ 
    uint64_t      tex[512];
}; 
uniform int textureIndex;
void doTexture(inout vec4 color) { 
       sampler2D s = sampler2D(tex[textureIndex]);
       vec4 texel = texture2D(s,TexCoord[0]);
	   color.rgb = texel.rgb*color.rgb;
}




I have a draw call back that grabs the extensions:
glGetTextureHandleARB
glMakeTextureHandleResidentARB

Also it grabs the texture handles, I have visitor go and grab references to all the relevant textures (when the scene is loaded and the objects are merged), and I do:

Code:

    osg::UIntArray* array = static_cast<osg::UIntArray*>(m_ssbo->getBufferData(0));
    vector<GLuint> &rawData = array->asVector();
    GLuint64* raw64ptr = (GLuint64*)(rawData.data());
   

    if (!bindings)
        return false;
    for (auto itr = m_textureIdMap.begin(); itr != m_textureIdMap.end(); ++itr){
        osg::Texture* text=   m_textureMap[itr->first];
        int id = itr->second;
        auto textObject  = text->getTextureObject(rinfo.getContextID());
         if (!textObject){
               text->apply(*rinfo.getState());
               textObject  = text->getTextureObject(rinfo.getContextID());
               if (!textObject) return false;
         }
         uint64 textId = glGetTextureHandleARB(textObject->_id);
         if (glIsTextureHandleResidentARB(textId)==GL_FALSE)
            glMakeTextureHandleResidentARB(textObject->_id);
         raw64ptr[id] = textId;
    } 
 


Right now I am getting black for my texture, I cycle through textureIndex from my first texture to my last, I plan on replacing this with an attribute later, but there is not much point right now if I cannot get any textures to show up. If I do get this to work I do plan on building an example app and submitting it. 

#version 430 compatibility                         
#extension GL_NV_bindless_texture : require        
#extension GL_NV_shader_buffer_load : require      
#extension GL_NV_gpu_shader5 : require // uint64_t  

I am not sure doing a apply() to the texture and grabbing the id is the best idea. 

I am using OSG 3.4.0, I did make some modifications to support unsigned 64 bit uniforms, and to built OSG built-ins to after the last #extension. I have not checked to see if some has added this to the most recent development branch, if not I would gladly

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68142#68142








More information about the osg-users mailing list