How to speed up texture() calls?

Hi,

I’ve stumbled upon a weird issue on Windows I’m trying to get a workaround going.

Here’s a basic sketch to replicate the issue:

PImage texture;

void setup(){
  size(1280,720,P3D);
  
  texture = createImage(3840,2166,RGB);
  for(int i = 0 ; i < texture.pixels.length; i++){
    texture.pixels[i] = color(random(255),random(255),random(255),255);
  }
  texture.updatePixels();
}

void draw(){
  background(0);
  //image(texture,0,0);
  
  int x1 = 0;
  int y1 = 0;
  int x2 = width;
  int y2 = height;
  
  int u1 = 0;
  int v1 = 0;
  int u2 = width;
  int v2 = height;
  
  beginShape(QUADS);
  texture(texture);
  vertex(x1, y1, u1, v1);
  vertex(x1, y2, u1, v2);
  vertex(x2, y2, u2, v2);
  vertex(x2, y1, u2, v1);
  endShape();
  
  println(frameCount,millis());
  surface.setTitle((int)frameRate+"fps");
}

The output starts printing:

1 1558
2 17342

In short, using texture() is slow the first time it’s called for large textures.

I’ve profiled the sketch and it points to JOGL’s dispatch_glTexSubImage2D1() when called by PGraphicsOpenGL’s initCache()/addTexture() cycle.

I google a bit and it seems to be a JOGL issue related to temp folder permissions ?

Relevant threads:
http://forum.jogamp.org/Java-3D-initialization-is-super-slow-td4037070.html
https://jogamp.org/bugzilla/show_bug.cgi?id=1301



I’ve tried temporarily disabling Windows Defender and allowing C:\Windows\Temp more permissions, but it didn’t seem to fix anything. I’ve also attempted to pass -Djogamp.gluegen.UseTempJarCache=false to processing-java in the hope the flag would make it’s way to JVM, but this didn’t seem to work.

Has anyone else experienced this issue ? Is there a quick workaround for the Processing IDE
(before drilling down to running an exported jar from command line or using eclipse ?) ?

1 Like

Update
I’ve noticed the jogamp temp folder (in my case ) is still readonly.
Tried to remove the readonly attribute (using these superuser answers), but it didn’t work.
I’ve installed eclipse and tested the suggestions from what I thought were relevant posts, however it also didn’t work :confused:

The sample looks like this:

import processing.core.PApplet;
import processing.core.PImage;

public class TextureTest extends PApplet {
	
	PImage texture;
	
	public void settings() {
	  size(1280, 720, P3D);
	  println("jogamp.gluegen.UseTempJarCache =",System.getProperty("jogamp.gluegen.UseTempJarCache"));
	}
	
	public void setup(){
	  
	  texture = createImage(4096,2166,RGB);
	  for(int i = 0 ; i < texture.pixels.length; i++){
	    texture.pixels[i] = color(random(255),random(255),random(255),255);
	  }
	  texture.updatePixels();
	  
	}

	public void draw(){
	  background(0);
	  //image(texture,0,0);
	  
	  int x1 = 0;
	  int y1 = 0;
	  int x2 = width;
	  int y2 = height;
	  
	  int u1 = 0;
	  int v1 = 0;
	  int u2 = width;
	  int v2 = height;
	  
	  beginShape(QUADS);
	  texture(texture);
	  vertex(x1, y1, u1, v1);
	  vertex(x1, y2, u1, v2);
	  vertex(x2, y2, u2, v2);
	  vertex(x2, y1, u2, v1);
	  endShape();
	  
	  println(frameCount,millis());
	  surface.setTitle((int)frameRate+"fps");
	}
	
	public static void main(String[] args) {
		PApplet.main(TextureTest.class.getCanonicalName());
	}

}

The output is still about the same (~17.5 seconds delay before texture caching completes):

jogamp.gluegen.UseTempJarCache = false
1 1375
2 18952

The caveat being the windows dll’s would now be unzipped in the natives folder relative to the project (instead of being unzipped in a temp folder).
I’ve uploaded the eclipse project here

@Andres Have you ever ran into this issue ? Woulld you be able to advise what else I could try / point me in the right direction ? Many thanks

I haven’t found the specific issue, but it is definitely GPU related and I have a fix/workaround !

On my machine I have two GPUs and Intel GPU and an nVidia GPU.

The issue occours on the Intel GPU. To explicitly tell Windows to use the nVidia GPU has a gotcha:

  1. Go to Settings > Graphics Settings and use the Classic app > Browse button
  2. Instead of browsing for the editor (processing.exe), browse for the java version the editor ships with (e.g. processing-3.5.3\java\bin\java.exe)
  3. Press Options and select High Performance

The screenshot is confusing I know. (Sometimes it actually displays the correct information :wink: )
You can check from the sketch using PGraphicsOpenGL:

PGraphicsOpenGL pg = (PGraphicsOpenGL)g;
  println(PGraphicsOpenGL.OPENGL_VENDOR);
  println(PGraphicsOpenGL.OPENGL_RENDERER);
  println(PGraphicsOpenGL.OPENGL_VERSION);

(Thanks to @Andres and his Topics > Demos > Tests > SpecsTest example)

Now the texture cache time is much shorter:

NVIDIA Corporation
GeForce RTX 2060/PCIe/SSE2
4.6.0 NVIDIA 442.19
1 3856
2 4091
1 Like