kvark's picture

Help with EXT_transform_feedback

Whatever I pass to GL.TransformFeedbackVaryings it crashes with exception:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at OpenTK.Graphics.GL.Delegates.TransformFeedbackVaryings.Invoke(UInt32 program, Int32 count, String varyings, TransformFeedbackMode bufferMode)
at OpenTK.Graphics.GL.TransformFeedbackVaryings(UInt32 program, Int32 count, String varyings, TransformFeedbackMode bufferMode)
at kri.TransFeedback.setup(ShaderProg prog, String[] vars) in E:\pr\boo\engine\Shader.boo:line 90
at demo.MyAni..ctor() in E:\pr\boo\demo\demo.boo:line 22
at demo.DemoModule.Main(String[] argv) in E:\pr\boo\demo\demo.boo:line 80

The only way to make it work is to pass 0 as count and "" as varyings. I'd be very happy to see any example of using it with 1-2 varyings...
These are examples I tried (all with 1 varying) without luck:
"out_pos "
"out_pos\0\0\0\0"
"out_pos\n\n\n\n"

Thanks in advance.


Comments

Comment viewing options

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

The singature for GL.TransformFeedbackVaryings looks wrong, I think it should take a string[] instead of string. Let me verify that and make a fix.

Other than that, what video card & drivers are you using? I've seen reports of transform feedback crashing on Ati cards (but this might have been fixed in the meanwhile).

kvark's picture

Yes, it seems that GL.TransformFeedbackVaryings should accept a list of strings (as it does in C). However, I haven't succeeded getting it to work under unmanaged C++ code (It didn't throw exception on this step, but did't work anyway).

I have Catalyst 9.5 on Radeon HD 4670 (mobility).

the Fiddler's picture

I am working on a fix for the string array issue.

An option is to test with Mesa3d to see whether it is a driver bug. If you haven't already done this, you can also compile against the debug OpenTK dll, which checks for OpenGL errors automatically.

kvark's picture

Thanks! The feedback was really fast.

Haven't tried with Mesa still...
Linking with debug OpenTK dll by default.

Will patiently wait for the fix.

the Fiddler's picture

Issue with string[] fixed in rev. 1926 and 1927 for 0.9.8 and 0.9.9 respectively.

If you wish you can download the code from svn or wait for the next refresh this weekend.

kvark's picture

Thanks! I've built the project from fresh SVN sources.
Just wondering: why is there a 'count' param of GL.TransformFeedbackVaryings?
It seems to me that you may just use varyings.Length instead...

the Fiddler's picture

This is a legacy of the C api that cannot be fixed by the binding generator automatically. We tend to add 'convenience' functions by hand to handle these kinds of parameters for you (see for example ShaderSource). The quickest way to get something like that fixed is to post a feature request or even a patch (these additions are typically just a couple lines of code to 'Source/OpenTK/GraphicsGLHelper.cs').

That said, you might wish to have a large array of strings and pass subsets of it around - the 'count' param can help here.

kvark's picture

I can use slicing in the case of large string array.
I got it about the GraphicsHelper. It's not difficult to pass Length on my side anyway.

Now the GL.TransformFeedbackVaryings finished without error.
The next operation I do is binding output buffer:
GL.BindBufferBase(BufferTarget.TransformFeedbackBuffer, 0, bufferId)

It produces error Invalid Operation.
According to the spec (http://www.opengl.org/registry/specs/EXT/transform_feedback.txt):
BindBuffer* instruction can produce this error only in case of Transform Feedback being already active at the time of call. In my case it's not active, I even tried to call GL.EndTransformFeedback to ensure that (it produced error, obviously).

'bufferId' in my case is a valid VertexBufferObject containing 6 Vector2h values. I tried to render it into 2 triangles with success.

Any ideas what's wrong with BindBufferBase?

kvark's picture

Trying BindBufferRange:

c_ind as uint = 0
buffId as uint //assigned during VBO creation, filled with 4 Vector2h data
GL.BindBufferRange(BufferTarget.TransformFeedbackBuffer, c_ind, buffId,	IntPtr.Zero, IntPtr( 1 ))


System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at OpenTK.Graphics.GL.Delegates.BindBufferRange.Invoke(BufferTarget target, UInt32 index, UInt32 buffer, IntPtr offset, IntPtr size)
at OpenTK.Graphics.GL.BindBufferRange(BufferTarget target, UInt32 index, UInt32 buffer, IntPtr offset, IntPtr size) in c:\svn\opentk\Source\OpenTK\Graphics\GL\GL.cs:line 24894
at demo.MyAni..ctor() in C:\pr\boo\demo\demo.boo:line 41
at demo.DemoModule.Main(String[] argv) in C:\pr\boo\demo\demo.boo:line 88

It crashes regardless of the last parameter (maximum size of data to be written in machine units).
A driver bug? Or another OpenTK issue?

I have a parallel discussion on OpenGL.org about that:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Numb...

the Fiddler's picture

I just checked and the function signature matches the spec. This either points to a driver bug or some unsupported state (Ati drivers sometimes crash instead of generating an error). I haven't used transform feedback before, so can't tell which it is.

The best solution is to check what happens on nvidia. If you don't have nvidia hardware next best solution is to find someone who has. Third best is to check with Mesa3d (it comes with a visual studio solution, so just download a zip, compile & copy all dlls to your project folder).

Edit: you should also try using a GL 2.1 context. Ati's 3.0 codepath still suffers from some strange errors (e.g. no vsync on Linux and other issues).