Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve coloring of thread ids.

This change adds a new 1D texture (theColors) to specify the possible
thread colors.  The texture is initialized to a low discrepancy sequence on
hue to give good coverage of the color space regardless of the number of
threads.
  • Loading branch information...
commit ae07f5fbe12a1bf3dfc2090cdc73009fec9c789c 1 parent 7ee09f7
@ajclinto authored
Showing with 74 additions and 47 deletions.
  1. +9 −24 Color.h
  2. +59 −2 Window.C
  3. +1 −0  Window.h
  4. +5 −21 shader.frag
View
33 Color.h
@@ -42,9 +42,9 @@ class Color {
uint32 toInt32() const
{
return 0xFF000000 |
- (ftoc(myB)) |
+ (ftoc(myB) << 16) |
(ftoc(myG) << 8) |
- (ftoc(myR) << 16);
+ (ftoc(myR));
}
float luminance() const
@@ -65,26 +65,6 @@ class Color {
}
Color lerp(const Color &rhs, float bias) const
{
-#if 0
- return Color(
- SYSlerp(myR, rhs.myR, bias),
- SYSlerp(myG, rhs.myG, bias),
- SYSlerp(myB, rhs.myB, bias));
-#else
-#if 0
- QColor c1(QColor(toInt32()).toHsl());
- QColor c2(QColor(rhs.toInt32()).toHsl());
-
- // Lerp in HSL space
- float h = lerpHue((float)c1.hslHueF(),
- (float)c2.hslHueF(), bias);
- float s = SYSlerp((float)c1.hslSaturationF(),
- (float)c2.hslSaturationF(), bias);
- float l = SYSlerp((float)c1.lightnessF(),
- (float)c2.lightnessF(), bias);
-
- QColor c3(QColor::fromHslF(h, s, l));
-#else
QColor c1(QColor(toInt32()).toHsv());
QColor c2(QColor(rhs.toInt32()).toHsv());
@@ -97,10 +77,15 @@ class Color {
(float)c2.lightnessF(), bias);
QColor c3(QColor::fromHsvF(h, s, l));
-#endif
return Color(c3.redF(), c3.greenF(), c3.blueF());
-#endif
+ }
+
+ void fromHSV(float h, float s, float v)
+ {
+ QColor c(QColor::fromHsvF(h, s, v));
+
+ *this = Color(c.redF(), c.greenF(), c.blueF());
}
private:
View
61 Window.C
@@ -138,6 +138,7 @@ MemViewWidget::MemViewWidget(int argc, char *argv[],
, myHScrollBar(hscrollbar)
, myStatusBar(status)
, myTexture(0)
+ , myColorTexture(0)
, myPixelBuffer(0)
, myPrevEvents(0)
, myZoom(0)
@@ -262,6 +263,42 @@ loadTextFile(const char *filename)
return buffer;
}
+// 512 size texture to accomodate the 500 possible threads supported by
+// valgrind.
+static const int theColorBits = 9;
+static const int theColorSize = (1 << theColorBits);
+
+static int
+rinverse(int val)
+{
+ // Radical inverse specialized for 16 bits
+ int tmp = val;
+ tmp = ((tmp & 0xAAAA) >> 1) | ((tmp & 0x5555) << 1);
+ tmp = ((tmp & 0xCCCC) >> 2) | ((tmp & 0x3333) << 2);
+ tmp = ((tmp & 0xF0F0) >> 4) | ((tmp & 0x0F0F) << 4);
+ tmp = ((tmp & 0xFF00) >> 8) | ((tmp & 0x00FF) << 8);
+ return tmp >> (16-theColorBits);
+}
+
+static void
+fillThreadColors(GLImage<uint32> &colors)
+{
+ const int width = theColorSize;
+ const float s = 0.7;
+ const float v = 1;
+
+ Color clr;
+ colors.resize(width, 1);
+ for (int i = 0; i < width; i++)
+ {
+ int idx = rinverse(i);
+ float h = idx / (float)(width-1);
+
+ clr.fromHSV(h, s, v);
+ colors.setPixel(i, 0, clr.toInt32());
+ }
+}
+
void
MemViewWidget::initializeGL()
{
@@ -269,13 +306,29 @@ MemViewWidget::initializeGL()
// seem to produce any dithering.
glDisable(GL_DITHER);
- glActiveTexture(GL_TEXTURE0);
+ const GLuint type = GL_NEAREST;
+
+ // Build a texture to store colors used by the shader
+ glActiveTexture(GL_TEXTURE1);
+ glGenTextures(1, &myColorTexture);
+ glBindTexture(GL_TEXTURE_1D, myColorTexture);
+
+ glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, type);
+ glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, type);
+
+ GLImage<uint32> colors;
+ fillThreadColors(colors);
+ glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA,
+ colors.width(), 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, colors.data());
+
+ // Create the memory state texture
glGenBuffers(1, &myPixelBuffer);
+ glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &myTexture);
glBindTexture(GL_TEXTURE_RECTANGLE, myTexture);
- const GLuint type = GL_NEAREST;
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, type);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, type);
@@ -369,6 +422,8 @@ MemViewWidget::paintGL()
myHScrollBar->value(),
myVScrollBar->value());
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_RECTANGLE, myTexture);
#ifdef USE_PBUFFER
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
@@ -384,6 +439,8 @@ MemViewWidget::paintGL()
myProgram->bind();
myProgram->setUniformValue("theState", 0);
+ myProgram->setUniformValue("theColors", 1);
+
myProgram->setUniformValue("theStale", MemoryState::theStale);
myProgram->setUniformValue("theHalfLife", MemoryState::theHalfLife);
myProgram->setUniformValue("theDisplayMode", myDisplayMode);
View
1  Window.h
@@ -136,6 +136,7 @@ private slots:
QGLShaderProgram *myProgram;
GLuint myTexture;
+ GLuint myColorTexture;
GLuint myPixelBuffer;
DisplayLayout myDisplay;
View
26 shader.frag
@@ -5,6 +5,7 @@ in mediump vec2 texc;
out vec4 frag_color;
uniform usampler2DRect theState;
+uniform sampler1D theColors;
uniform int theTime;
uniform int theStale;
@@ -69,27 +70,10 @@ void main(void)
if (theDisplayMode == 1)
{
- vec3 clr[16];
- clr[0] = lum1(vec3(0.7, 0.2, 1.0));
- clr[1] = lum1(vec3(0.3, 1.0, 0.4));
- clr[2] = lum1(vec3(0.3, 0.4, 1.0));
- clr[3] = lum1(vec3(1.0, 0.7, 0.4));
- clr[4] = lum1(vec3(0.8, 0.4, 0.2));
- clr[5] = lum1(vec3(0.5, 1.0, 0.7));
- clr[6] = lum1(vec3(0.6, 0.2, 1.0));
- clr[7] = lum1(vec3(1.0, 0.4, 0.4));
-
- clr[8] = lum1(vec3(0.5, 0.4, 1.0));
- clr[9] = lum1(vec3(0.4, 1.0, 0.1));
- clr[10] = lum1(vec3(0.8, 0.5, 1.0));
- clr[11] = lum1(vec3(1.0, 1.0, 0.4));
- clr[12] = lum1(vec3(1.0, 0.1, 0.3));
- clr[13] = lum1(vec3(0.3, 1.0, 0.9));
- clr[14] = lum1(vec3(0.7, 0.3, 1.0));
- clr[15] = lum1(vec3(1.0, 0.4, 1.0));
-
- tid &= 15u;
- frag_color = vec4(ramp_color(clr[tid], clr[tid], interp), 1);
+ int size = textureSize(theColors, 0);
+
+ vec3 clr = lum1(vec3(texture(theColors, (float(tid)+0.5)/size)));
+ frag_color = vec4(ramp_color(clr, clr, interp), 1);
}
else
{
Please sign in to comment.
Something went wrong with that request. Please try again.