Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
The Gay Bean
Apr 19, 2004
I recently switched my dev machine from a Retina Macbook pro 15 inch 2013 model to a 2015 model. The former has a GeForce GT 650M and the latter has a R9 M370X.

We have developed an OpenGL 3.3 core application, and it would run quite well on the 2013 model. The exact same task runs much, much slower on the 2015 - maybe 10x slower. The new machine has a faster processor, faster SSD, and in all of the benchmarks I've seen, the R9 M370X benchmarks consistently higher (1.5x) than the GeForce GT 650M.

I've turned off automatic graphics switching and OpenGL reports:

code:
Vendor: ATI Technologies Inc.
Renderer: AMD Radeon R9 M370X OpenGL Engine
Version: 4.1 ATI-1.42.11
GLSL: 4.10
Context Profile: Core
Does anybody have any idea what could be causing this, and what I could do to begin to address the issue?

Adbot
ADBOT LOVES YOU

Sex Bumbo
Aug 14, 2004
Yes, AMD drivers don't do nearly as much legwork as NVidia ones. NVidia optimizes the hell out of your poo poo and even sometimes hides errors and invalid calls. It makes a lot of strong assumptions about how your program works and is usually right.

For example once I looked at a bug where every UI element cleared the depth buffer before it rendered for no reason and nvidia just ignored it all and amd fell to its knees. It just didn't repro at all on nvidia.


E: I mean, probably. I don't really know. Maybe your resolution is just higher.

Sex Bumbo fucked around with this message at 19:06 on Jul 21, 2016

Doc Block
Apr 15, 2003
Fun Shoe
Have you profiled your code? Looked at it in Apple's OpenGL performance tools?

The Gay Bean
Apr 19, 2004
No, I'm relatively new to developing 3D stuff (not formally educated, put into the role because there's nobody better at our company to do so), and I am looking for the next steps to track down the problem. OpenGL isn't throwing any errors so I figure that the program is doing something inefficient that the nVidia drivers were handling differently.

So I guess the question becomes "what are the tools that I should look into to optimize my code with ATI drivers," and one answer is to use Apple's OpenGL Performance Tools. Any other things I should definitely research?

Doc Block
Apr 15, 2003
Fun Shoe
I didn't think that nVidia and AMD wrote the drivers for OS X. Like, my understanding was that Apple had access to all the hardware details and probably reference driver source code, but much/most of the driver was written by Apple. At the very minimum, Apple writes the shader compiler since that's based on LLVM.

Sex Bumbo
Aug 14, 2004
You're right I forgot it was a macbook. I'm still highly suspicious of GL drivers though.

The Gay Bean
Apr 19, 2004
After messing with it a bit, I think it has something to do with the CPU-side processing I'm not accounting for, sorry for the false alarm.

haveblue
Aug 15, 2005



Toilet Rascal
Dumb question- is this within a few hours of setting up the new Mac? You may be losing cycles to spotlight indexing or some other post-config background process.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
This might seem like a silly question, but do you have to use the noperspective qualifier for your vert shader output when doing orthographic projection, effectively meaning you can't use the same shader set for orthographic and perspective projections? I've never really played much with output qualifiers beyond using flat for ints and noperspective to get vertex coordinates in render target UVs.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm trying to do trilateralization with n > 4 spheres using least squares.

I expanded upon

pre:
(x - x_sphere_0)^2 + (y - y_sphere_0)^2 + (z - z_sphere_0)^2 = r_sphere_0^2
, multiplying out the left hand side into

pre:
x^2 -2xx_0 + x_0^2 + y^2 -2y_y0 +y_0^2 + z^2 -2zz_0 + z_0^2 = r_0^2
, then pulled out the terms I didn't have (x^2, x, y^2, y, z^2, z) into a separate matrix. That made, in theory, for a nice linear algebra solution Ax=R, where x is the location.

code:
In [25]: def known_points_to_position(point_tuples, distance):
   ....:     a = numpy.zeros(shape=[len(point_tuples), 9], dtype=numpy.float)
   ....:     r = numpy.zeros(shape=[len(point_tuples)], dtype=numpy.float)
   ....:     for index,p in enumerate(point_tuples):
   ....:         a[index,0] = 1
   ....:         a[index,1] = -2*p[0]
   ....:         a[index,2] = p[0]*p[0]
   ....:         a[index,3] = 1
   ....:         a[index,4] = -2*p[1]
   ....:         a[index,5] = p[1]*p[1]
   ....:         a[index,6] = 1
   ....:         a[index,7] = -2*p[2]
   ....:         a[index,8] = p[2]*p[2]
   ....:         r[index] = distance[index]*distance[index]
   ....:     return numpy.linalg.lstsq(a, r)[0]
Easy peasy, right?

Problem is, when I run it for something that _should_ be trivial, i.e., point at the origin, all orthogonal, no noise, I get something wrong:

code:
In [26]: p = [
   ....: [1, 0, 0],
   ....: [0, 10, 0],
   ....: [0, 0, -10],
   ....: [2, 0, 0],
   ....: [10, 0, 0],
   ....: [-1, 0, 0]
   ....: ]

In [27]: r = [
   ....: 1,
   ....: 10,
   ....: 10,
   ....: 2,
   ....: 10,
   ....: 1
   ....: ]

In [28]: known_points_to_position(p, r)
Out[28]:
array([ -3.88578059e-16,  -1.11022302e-15,   1.00000000e+00,
        -3.33066907e-16,  -1.92307692e-01,   9.61538462e-01,
        -3.88578059e-16,   1.92307692e-01,   9.61538462e-01])
So x^2 = 0, x = 0, x_norm = 1 (?), y^2 = 0, y = -0.19, y_norm = 0.96, z^2 = 0, z = -0.19, z_norm = 0.961.

In general, it's not super bad, but I'm curious about how I'd deal with those _norm values (which I'd like to be able to force to 1 when setting up the equation, but I'm not sure how. Could I formulate my Ax=b differently to ensure that x adheres to the constraint [x^2 x 1 y^2 y 1 z^2 z 1]?

Xerophyte
Mar 17, 2008

This space intentionally left blank
I don't think that trilateration can be formulated as a linear problem, you're going to need a non-linear solver. Extending the point wont make it obey the "x[0] == x[1]*x[1]"-type constraints, and even if it did you're now minimizing the squared error of something other than the (x, y, z) coordinates.

You can send in a function computing the summed squared error for (x, y, z) with respect to your spheres as the objective function for scipy.minimize to get the least squares solution. Your linear sorta-solution might be useful as an initial guess if it's significantly faster to compute, otherwise just taking the input point with smallest radius as an initial guess might be a good idea.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Xerophyte posted:

I don't think that trilateration can be formulated as a linear problem, you're going to need a non-linear solver. Extending the point wont make it obey the "x[0] == x[1]*x[1]"-type constraints, and even if it did you're now minimizing the squared error of something other than the (x, y, z) coordinates.

You can send in a function computing the summed squared error for (x, y, z) with respect to your spheres as the objective function for scipy.minimize to get the least squares solution. Your linear sorta-solution might be useful as an initial guess if it's significantly faster to compute, otherwise just taking the input point with smallest radius as an initial guess might be a good idea.

Thanks. I was worried I'd have to do something iterative. :( I can't use scipy minimize because I'm only prototyping in Python. Are there any terms I should be googling? Trilinearization tends to yield the same result, so some more general term for finding solutions of this sort. Multilinear least squares? Nonlinear least squares?

Xerophyte
Mar 17, 2008

This space intentionally left blank

Jo posted:

Thanks. I was worried I'd have to do something iterative. :( I can't use scipy minimize because I'm only prototyping in Python. Are there any terms I should be googling? Trilinearization tends to yield the same result, so some more general term for finding solutions of this sort. Multilinear least squares? Nonlinear least squares?

It's generally called nonlinear least squares. I'm not very up-to-date on the actual algorithms, I just use scipy to try to find expressions that fit to datasets using their solvers on occasion and allow myself to be blissfully unaware of what said solver actually does. You can look at the scipy.optimize.minimize docs for a list of algorithms they use (scroll down to notes). Note that you can use one of the approaches that require the gradient, since the gradient at point p in this case is a sum of normalized direction vectors to or from p to the circle centers.

I also found this github repo of someone implementing the Levenberg-Marquart algorithm, which is a nonlinear least squares solver, for trilateration in Java.

E: And that github repo has a pdf that includes a derivation for a linear version of the problem, so apparently that works too. :doh:

Xerophyte fucked around with this message at 00:55 on Jul 31, 2016

Jo
Jan 24, 2005

:allears:
Soiled Meat

Xerophyte posted:

It's generally called nonlinear least squares. I'm not very up-to-date on the actual algorithms, I just use scipy to try to find expressions that fit to datasets using their solvers on occasion and allow myself to be blissfully unaware of what said solver actually does. You can look at the scipy.optimize.minimize docs for a list of algorithms they use (scroll down to notes). Note that you can use one of the approaches that require the gradient, since the gradient at point p in this case is a sum of normalized direction vectors to or from p to the circle centers.

I also found this github repo of someone implementing the Levenberg-Marquart algorithm, which is a nonlinear least squares solver, for trilateration in Java.

loving awesome! Thanks so much!

Luigi Thirty
Apr 30, 2006

Emergency confection port.

And here I am stuck on linear interpolation of u in affine texture mapping :saddowns:

v was easy because it's constant but I'm not so sure about u.

code:
    int scanlines = 0;

    int v_top    = triangle.getTexturePoint(0).y * 256; //256x256 texture
    int v_bottom = triangle.getTexturePoint(2).y * 256; //256x256 texture

    for(int y = screenPoints[1].y; y <= screenPoints[2].y; y++){
        int v = (int)lerp(v_top, v_bottom, ((float)scanlines / (float)screenPoints[2].y));
[etc...]

Luigi Thirty fucked around with this message at 01:57 on Jul 31, 2016

netcat
Apr 29, 2008
So uuh what is going on here:



Apart from all the other things that are broken here, I'm using immediate mode (because I'm lazy) to draw textured quads in little batches, and the first one in each batch always get skewed like this. I've never seen anything like this so I'm a bit stumped. I'm doing a regular ol' glBegin/glEnd with GL_QUADS:

code:
    glBegin(GL_QUADS);
      glVertex2f(x0, y0);
      glTexCoord2f(0, 1);

      glVertex2f(x0, y1);
      glTexCoord2f(1, 1);

      glVertex2f(x1, y1);
      glTexCoord2f(1, 0);

      glVertex2f(x1, y0);
      glTexCoord2f(0, 0);
    glEnd();
The texture coordinates are a bit weird since the pic get flipped sideways if I put them as you might expect and I'm not sure why (I thought only the y-axis would get flipped) but still, only the first texture gets weird so ???

Polio Vax Scene
Apr 5, 2009



Try not using GL_QUADS

Kobata
Oct 11, 2012

netcat posted:

code:
    glBegin(GL_QUADS);
      glVertex2f(x0, y0);
      glTexCoord2f(0, 1);

      glVertex2f(x0, y1);
      glTexCoord2f(1, 1);

      glVertex2f(x1, y1);
      glTexCoord2f(1, 0);

      glVertex2f(x1, y0);
      glTexCoord2f(0, 0);
    glEnd();

I haven't really done much immediate mode OpenGL, but don't the texture coordinates need to be set before the vertex call? Presumably it's working on later ones because GL remembers the last one set and uses it for the first vertex of later draws.

haveblue
Aug 15, 2005



Toilet Rascal

Kobata posted:

I haven't really done much immediate mode OpenGL, but don't the texture coordinates need to be set before the vertex call? Presumably it's working on later ones because GL remembers the last one set and uses it for the first vertex of later draws.

Yeah, that's exactly what's happening.

netcat
Apr 29, 2008

Kobata posted:

I haven't really done much immediate mode OpenGL, but don't the texture coordinates need to be set before the vertex call? Presumably it's working on later ones because GL remembers the last one set and uses it for the first vertex of later draws.

Yikes, that worked, thanks. I haven't done immediate OpenGL in a long while either so yeah

Jewel
May 2, 2009

dont use immediate opengl, dont use gl_quads. immediate mode has literally been out of date for ten years now.

netcat
Apr 29, 2008

Jewel posted:

dont use immediate opengl, dont use gl_quads. immediate mode has literally been out of date for ten years now.

I know, I'm just refactoring a bunch of stuff and immediate mode was the fastest way to move from what I had before to GL.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
I have never worked in immediate mode, since my intro to graphics course went straigt to shaders and VAOS, but is it really less work? As long as you have some boilerplate VAO and shader creation code, it doesn't really take any time to get started.

Sex Bumbo
Aug 14, 2004
It's less setup and more intuitive if you're not used to how modern hardware works, but less work is debatable. Fixing things that drivers don't bother implementing well isn't fun.

If you're texturing quads and need a few effects you can probably use html.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Joda posted:

I have never worked in immediate mode, since my intro to graphics course went straigt to shaders and VAOS, but is it really less work? As long as you have some boilerplate VAO and shader creation code, it doesn't really take any time to get started.

It is if you have an existing immediate mode renderer that uses GDI -- you don't have to concern yourself with buffer allocation in places like that.

Modern OpenGL, without DSA, is an extremely bizarre mix of both immediate mode state machine behavior, and modern buffer semantics. It's easier to grasp immediate early on.

netcat
Apr 29, 2008
I had some code to update the vertex positions in a vbo:

code:
    glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
    glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(float), nullptr, GL_DYNAMIC_DRAW); // crash
    glBufferSubData(GL_ARRAY_BUFFER, 0, m_vertices.size() * sizeof(float), m_vertices.data()); // or crash if above line is removed
this only works the first time it is called and when running in a debugger like gdebugger or renderdoc it actually crashes the program. Anyone have any idea why? I don't actually need this but I'm very puzzled why it just refuses to work. It works fine when updating texcoords.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
I assume you genned your buffer elsewhere?

If you're allocating new space for your buffer (glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(float), nullptr, GL_DYNAMIC_DRAW); ) don't you have to delete the old data and generate a new buffer? I'm not sure how much of that the driver can be trusted to handle for you, but based on general C standards, you'd free the old memory before reallocating for your new data.

Have you tried just allocating space for a million vertices or whatever when you first generate your buffer, so you can use subdata to upload your new data without reallocating. This should also be more effective than reallocating every time you want to change the data.

netcat
Apr 29, 2008

Joda posted:

I assume you genned your buffer elsewhere?

If you're allocating new space for your buffer (glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(float), nullptr, GL_DYNAMIC_DRAW); ) don't you have to delete the old data and generate a new buffer? I'm not sure how much of that the driver can be trusted to handle for you, but based on general C standards, you'd free the old memory before reallocating for your new data.

Have you tried just allocating space for a million vertices or whatever when you first generate your buffer, so you can use subdata to upload your new data without reallocating. This should also be more effective than reallocating every time you want to change the data.

Yeah the buffer is created earlier. Reading this page they talk about "orphaning" the buffer by setting the data ptr to 0 and this should apparently be efficient so that's why I'm doing it, though maybe I don't need to. If we disregard that part, it still doesn't work by only calling glBufferSubData. In my test I don't add new vertices, I just change the positions of a triangle

baldurk
Jun 21, 2005

If you won't try to find coherence in the world, have the courtesy of becoming apathetic.

netcat posted:

this only works the first time it is called and when running in a debugger like gdebugger or renderdoc it actually crashes the program.

If you can give a complete repro case I can at least tell you why it's crashing renderdoc, which might clue in what the real problem is (if it's not just my bug).

netcat
Apr 29, 2008

baldurk posted:

If you can give a complete repro case I can at least tell you why it's crashing renderdoc, which might clue in what the real problem is (if it's not just my bug).

I might try to do that later. When I ran from the command line I saw that renderdoc threw a bad_alloc exception if that gives any clues.

pseudorandom name
May 6, 2007

What's m_vertices.size() * sizeof(float)?

Sex Bumbo
Aug 14, 2004
Not totally sure this belong in the graphics thread.

I'm trying to display the frequencies of a sound sample. I don't really know a lot about this. I'm taking 2048 samples, applying a hann window, doing a fft, and taking the log of the fft magnitude squared. Here's the first half of the resultant fft in green (1024 values):


I'm scaling the values between -20 and 20 which seems weird first of all, and also the values at the end seem really low and peculiar? I don't recognize them in other visualizers. Any obvious thing I'm doing wrong?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Try testing with a simple one-frequency sine wave. That should help you debug it.

netcat
Apr 29, 2008

baldurk posted:

If you can give a complete repro case I can at least tell you why it's crashing renderdoc, which might clue in what the real problem is (if it's not just my bug).

If you feel like testing I've put together a little binary here with source: https://dl.dropboxusercontent.com/u/7456592/temp/simple.rar

It tries to draw a vbo 10 times updating the vertex positions each time, crashes in renderdoc. I've prooobably done something wrong but I just can't see it.

baldurk
Jun 21, 2005

If you won't try to find coherence in the world, have the courtesy of becoming apathetic.

netcat posted:

If you feel like testing I've put together a little binary here with source: https://dl.dropboxusercontent.com/u/7456592/temp/simple.rar

It tries to draw a vbo 10 times updating the vertex positions each time, crashes in renderdoc. I've prooobably done something wrong but I just can't see it.

You're not resetting the right variable :):

code:
  if (m_texcoord_update)
  {
    glBindBuffer(GL_ARRAY_BUFFER, m_texcoord_buffer);
    glBufferData(GL_ARRAY_BUFFER, m_texcoords.size() * sizeof(float), nullptr, GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER, 0, m_texcoords.size() * sizeof(float), m_texcoords.data());
  }

  // FIXME: Doesn't work.
  if (m_vertex_update)
  {
    glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
    glBufferData(GL_ARRAY_BUFFER, m_vertices.size() * sizeof(float), nullptr, GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER, 0, m_vertices.size() * sizeof(float), m_vertices.data());
  }

  m_texcoord_update = false;
  m_vertex_buffer = false; // <---- whoops!
You should definitely be using ARB_debug_output. It would have pointed to the problem straight away even without debuggers running:

code:
Got a Debug message from GL_DEBUG_SOURCE_API, type GL_DEBUG_TYPE_ERROR, ID 1282, severity GL_DEBUG_SEVERITY_HIGH:
'GL_INVALID_OPERATION error generated. Target buffer must be bound.'

netcat
Apr 29, 2008

baldurk posted:

You're not resetting the right variable :):

Oh gently caress lol how did I miss that. Sometimes I wish C++ was java... Thanks for solving my really stupid problem!

And I didn't know about ARB_debug_output, though I did put put glGetError in a few places but that didn't show anything for some reason?? :sweatdrop:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
glGetError isn't sticky -- it's strictly whether an error happened on the *last* call you made.

baldurk, is it possible when you record the trace, to also enable and store any ARB_debug_output? I know apitrace can do that.

Sex Bumbo
Aug 14, 2004

Suspicious Dish posted:

Try testing with a simple one-frequency sine wave. That should help you debug it.

Thanks, it did help, also cheating helped a lot https://github.com/adobe/webkit/blob/master/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp

baldurk
Jun 21, 2005

If you won't try to find coherence in the world, have the courtesy of becoming apathetic.

Suspicious Dish posted:

glGetError isn't sticky -- it's strictly whether an error happened on the *last* call you made.

baldurk, is it possible when you record the trace, to also enable and store any ARB_debug_output? I know apitrace can do that.

Yep, you can just tick 'Enable API Validation' when capturing, it'll record any output and store it so you can see which draw it comes from. In this case though it hits a NULL dereference and crashes since there's no buffer bound at the time of that call.

Adbot
ADBOT LOVES YOU

netcat
Apr 29, 2008
So I'm drawing a bunch of quads, and I want to do an outline effect like if I was rendering the wireframe, but only for the actual quad and not the triangles that make up the quad (so using a line mode doesn't work):



Is there any good way to achieve this effect? e: I also want it to be filled or textured, or else just drawing the lines would be fine

netcat fucked around with this message at 10:02 on Sep 14, 2016

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply