[Mesa-dev] [PATCH 2/2] glsl/gsraytrace: Use EXT_transform_feedback instead of, NV.

Fabian Bieler fabianbieler at fastmail.fm
Wed Jun 12 08:34:11 PDT 2013


NV_transform_feedback is currently not supported by mesa (and I'm
somewhat doubtful it will be implemented in the foreseeable future).

Note that with this patch the demo doesn't work anymore with the nvidia
binary driver.
---
 src/glsl/gsraytrace.cpp | 71 +++++++++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 41 deletions(-)

diff --git a/src/glsl/gsraytrace.cpp b/src/glsl/gsraytrace.cpp
index f34a3da..2f8f681 100644
--- a/src/glsl/gsraytrace.cpp
+++ b/src/glsl/gsraytrace.cpp
@@ -34,7 +34,6 @@
 #include <math.h>
 #include <stddef.h> // offsetof
 
-// TODO: use GL_EXT_transform_feedback or GL3 equivalent
 // TODO: port to piglit too
 
 static const float INF=9999.9F;
@@ -600,33 +599,12 @@ Draw(void)
    dir_idxAttribLoc = glGetAttribLocation(program, "dir_idx");
    uv_stateAttribLoc = glGetAttribLocation(program, "uv_state");
 
-   posVaryingLoc = glGetVaryingLocationNV(program, "gl_Position");
-   orig_tVaryingLoc = glGetVaryingLocationNV(program, "orig_t2");
-   dir_idxVaryingLoc = glGetVaryingLocationNV(program, "dir_idx2");
-   uv_stateVaryingLoc = glGetVaryingLocationNV(program, "uv_state2");
-   //gs.gs->getVaryingLocation("gl_Position", gs.posVaryingLoc);
-   //gs.gs->getVaryingLocation("orig_t2", gs.orig_tVaryingLoc);
-   //gs.gs->getVaryingLocation("dir_idx2", gs.dir_idxVaryingLoc);
-   //gs.gs->getVaryingLocation("uv_state2", gs.uv_stateVaryingLoc);
-
-
-   glBindBufferOffsetNV(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0, dst, 0);
-   GLint varyings[4]= {
-      posVaryingLoc,
-      orig_tVaryingLoc,
-      dir_idxVaryingLoc,
-      uv_stateVaryingLoc
-   };
-   // I think it will be a performance win to use multiple buffer objects to write to
-   // instead of using the interleaved mode.
-   glTransformFeedbackVaryingsNV(program, 4, varyings, GL_INTERLEAVED_ATTRIBS_NV);
-
    ////printf("%d\n", i);
    //gs.fpwQuery->beginQuery();
    //gs.pgQuery->beginQuery();
-   glBindBufferBaseNV(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0, dst);
-   glBeginQuery(GL_PRIMITIVES_GENERATED_NV, pgQuery);
-   glBeginTransformFeedbackNV(GL_POINTS);
+   glBindBufferBaseEXT(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, dst);
+   glBeginQuery(GL_PRIMITIVES_GENERATED_EXT, pgQuery);
+   glBeginTransformFeedbackEXT(GL_POINTS);
    //gs.eyeRaysAsPoints->bindAs(ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, eyeRaysAsPoints);
    {
@@ -649,9 +627,9 @@ Draw(void)
       //gs.gs->set_uniform("emitNoMore", 1, 0);
       glUniform1i(glGetUniformLocation(program, "emitNoMore"), 0);
 
-      //glEnable(GL_RASTERIZER_DISCARD_NV);
+      //glEnable(GL_RASTERIZER_DISCARD_EXT);
       glDrawArrays(GL_POINTS, 0, WinWidth*WinHeight);
-      //glDisable(GL_RASTERIZER_DISCARD_NV);
+      //glDisable(GL_RASTERIZER_DISCARD_EXT);
 
       glDisableVertexAttribArray(uv_stateAttribLoc);
 
@@ -663,16 +641,16 @@ Draw(void)
    }
    //gs.eyeRaysAsPoints->unbindAs(ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
-   glEndTransformFeedbackNV();
+   glEndTransformFeedbackEXT();
    //gs.pgQuery->endQuery();
-   glEndQuery(GL_PRIMITIVES_GENERATED_NV);
+   glEndQuery(GL_PRIMITIVES_GENERATED_EXT);
    //gs.fpwQuery->endQuery();
 
    ////psoLog(LOG_RAW) << "1st: " << gs.fpwQuery->getQueryResult() << ", " << gs.pgQuery->getQueryResult() << "\n";
 
 
    ////swap(src, dst);
-   glBindBufferBaseNV(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0, 0);
+   glBindBufferBaseEXT(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, 0);
 
    ////clear();
 
@@ -774,15 +752,15 @@ Reshape(int width, int height)
    {
       size_t nElem = WinWidth*WinHeight*nRayGens;
       glGenBuffers(1, &dst);
-      glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_NV, dst);
-      glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_NV, nElem*sizeof(GSRay), 0, GL_STREAM_DRAW);
-      GSRay* d = (GSRay*)glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_NV, GL_READ_WRITE);
+      glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, dst);
+      glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, nElem*sizeof(GSRay), 0, GL_STREAM_DRAW);
+      GSRay* d = (GSRay*)glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, GL_READ_WRITE);
       for (size_t i = 0; i < nElem; i++)
       {
          d[i].dir_idx = vec4(0.0F, 0.0F, 0.0F, -1.0F);
       }
-      glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_NV);
-      glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0);
+      glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT);
+      glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0);
       //printf("Ping-pong VBO size 2x%d Kbytes.\n", (int)nElem*sizeof(GSRay)/1024);
    }
 
@@ -864,12 +842,29 @@ Init(void)
       exit(-1);
    }
 
+   if (!GLEW_EXT_transform_feedback)
+   {
+      fprintf(stderr, "EXT transform feedback not supported!\n");
+      exit(-1);
+   }
+
    vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource);
    geomShader = CompileShaderText(GL_GEOMETRY_SHADER_ARB, gsSource);
    fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fsSource);
    program = LinkShaders3WithGeometryInfo(vertShader, geomShader, fragShader,
                                           3, GL_POINTS, GL_POINTS);
 
+   const char *varyings[] = {
+      "gl_Position",
+      "orig_t2",
+      "dir_idx2",
+      "uv_state2"
+   };
+   // I think it will be a performance win to use multiple buffer objects to write to
+   // instead of using the interleaved mode.
+   glTransformFeedbackVaryingsEXT(program, 4, varyings, GL_INTERLEAVED_ATTRIBS_EXT);
+   glLinkProgram(program);
+
    if (glGetError() != 0)
    {
       fprintf(stderr, "Shaders were not loaded!\n");
@@ -909,12 +904,6 @@ Init(void)
 
    printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
 
-   if (!GLEW_NV_transform_feedback)
-   {
-      fprintf(stderr, "NV transform feedback not supported!\n");
-      exit(-1);
-   }
-
    glGenQueries(1, &pgQuery);
 
    printf("\nESC                 = exit demo\nleft mouse + drag   = rotate camera\n\n");
-- 
1.8.1.2




More information about the mesa-dev mailing list