Skip to content

Commit

Permalink
Bug 1347: Resolve Merged EGL/Desktop Profile Mapping
Browse files Browse the repository at this point in the history
GLProfile.computeProfileImpl(..) as of Bug 1084 is not the culprit here and its hardware criteria filter works.

The issue is commit 99a0643 of Bug 1203,
in particular the change in GLProfile re:
"Merge computed EGL-Profile-Map (1) and Desktop-Profile-Map (2)
 per device, instead of just using the last computation,
 preserving and favoratizing the Desktop-Profile-Map."

Here the Desktop-Profile-Map overwrites the EGL-Profile-Map and hence
the software mapping gets used.

Indeed, this is a regression cause by the work of Bug 1203.

+++

Resolution is to revert the explicit 'union mapping'
and rely on an enhanced 'GLContextImpl.remapAvailableGLVersions(fromDevice, toDevice)' function.
Here the EGLDrawableFactory _already_ maps the EGL device's GL Versions to the 'host' device (e.g. X11).
This has to be refined so that the remap will not overwrite the 'host' device's already detected GL Versions.

That alone is enough, so that GLProfile can simply use the 'mappedEGLProfiles' of the 'host' device if detected, which already is a merged mapping of X11 host- and EGL sub-device.

In case no 'mappedEGLProfiles' are available, we simply use the 'mappedDesktopProfiles'.
  • Loading branch information
sgothel committed Dec 28, 2019
1 parent 50f9c9e commit e222310
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 22 deletions.
6 changes: 3 additions & 3 deletions make/scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function jrun() {
#X_ARGS="-Dsun.awt.disableMixing=true"
#X_ARGS="--illegal-access=warn"

#D_ARGS="-Djogl.debug.GLProfile -Djogl.debug.GLContext"
D_ARGS="-Djogl.debug.GLProfile -Djogl.debug.GLContext"
#D_ARGS="-Djogl.debug.GLProfile"
#D_ARGS="-Djogl.debug.DebugGL"
#D_ARGS="-Djogl.debug.TraceGL"
Expand Down Expand Up @@ -461,7 +461,7 @@ function testawtswt() {
#testnoawt com.jogamp.newt.NewtVersion $*
#testnoawt com.jogamp.oculusvr.OVRVersion $*

#testnoawt com.jogamp.newt.opengl.GLWindow $*
testnoawt com.jogamp.newt.opengl.GLWindow $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLVersionParsing00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLWindowNEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLCanvasAWT $*
Expand All @@ -482,7 +482,7 @@ function testawtswt() {
#
# HiDPI
#
testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2SimpleNEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
Expand Down
3 changes: 3 additions & 0 deletions src/jogl/classes/com/jogamp/opengl/GLContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,9 @@ protected static VersionNumber decomposeBits(final int bits32, final int[] ctp)
ctp[0] = ( bits32 & 0x0000FFFF ) ;
return new VersionNumber(major, minor, 0);
}
protected static int getCTPFromBits(final int bits32) {
return ( bits32 & 0x0000FFFF );
}

protected static void validateProfileBits(final int bits, final String argName) {
int num = 0;
Expand Down
22 changes: 11 additions & 11 deletions src/jogl/classes/com/jogamp/opengl/GLProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1982,8 +1982,16 @@ private static boolean initProfilesForDeviceCritical(final AbstractGraphicsDevic
}
}

if( !addedDesktopProfile && !addedMobileProfile ) {
setProfileMap(device, new HashMap<String /*GLProfile_name*/, GLProfile>()); // empty
final HashMap<String, GLProfile> mappedAllProfiles;
if( addedMobileProfile ) {
// If run on actual desktop device, e.g. '.x11_:0_0',
// GLContextImpl.remapAvailableGLVersion('.egl_:0_0' -> '.x11_:0_0')
// ensures EGL profiles being mapped to upstream desktop device '.x11_:0_0'.
mappedAllProfiles = mappedEGLProfiles;
} else if( addedDesktopProfile ) {
mappedAllProfiles = mappedDesktopProfiles;
} else {
mappedAllProfiles = new HashMap<String /*GLProfile_name*/, GLProfile>(); // empty
if(DEBUG) {
System.err.println("GLProfile: device could not be initialized: "+device);
System.err.println("GLProfile: compatible w/ desktop: "+deviceIsDesktopCompatible+
Expand All @@ -1993,16 +2001,8 @@ private static boolean initProfilesForDeviceCritical(final AbstractGraphicsDevic
System.err.println("GLProfile: hasGLES1Impl "+hasGLES1Impl);
System.err.println("GLProfile: hasGLES3Impl "+hasGLES3Impl);
}
} else {
final HashMap<String, GLProfile> mappedAllProfiles = new HashMap<String, GLProfile>();
if( addedMobileProfile ) {
mappedAllProfiles.putAll(mappedEGLProfiles);
}
if( addedDesktopProfile ) {
mappedAllProfiles.putAll(mappedDesktopProfiles);
}
setProfileMap(device, mappedAllProfiles); // union
}
setProfileMap(device, mappedAllProfiles); // merged mappedEGLProfiles if available, otherwise mappedDesktopProfiles

GLContext.setAvailableGLVersionsSet(device, true);

Expand Down
39 changes: 34 additions & 5 deletions src/jogl/classes/jogamp/opengl/GLContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver;
import com.jogamp.opengl.GLExtensions;
import com.jogamp.opengl.GLRendererQuirks;

import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
import com.jogamp.nativewindow.AbstractGraphicsDevice;
import com.jogamp.nativewindow.NativeSurface;
Expand Down Expand Up @@ -1098,13 +1099,24 @@ private static Integer mapAvailableGLVersion(final AbstractGraphicsDevice device
}


protected static void remapAvailableGLVersions(final AbstractGraphicsDevice fromDevice, final AbstractGraphicsDevice toDevice) {
/**
* Remaps all available GL Version from {@code fromDevice} to {@code toDevice}.
*
* @param fromDevice the required matching device key to be mapped
* @param toDevice mapped GL version target
* @param overwrite if {@code true} overwrites previous mapping, otherwise leaves it untouched
* @param ctpCriteria the given GL Version context profile required to map a {@code fromDevice} GL Version.
* To map all GL Versions, just pass {@link GLContext#CTX_PROFILE_ES} | {@link GLContext#CTX_PROFILE_CORE} | {@link GLContext#CTX_PROFILE_COMPAT}
*/
protected static void remapAvailableGLVersions(final AbstractGraphicsDevice fromDevice, final AbstractGraphicsDevice toDevice,
final boolean overwrite, final int ctpCriteria) {
if( fromDevice == toDevice || fromDevice.getUniqueID() == toDevice.getUniqueID() ) {
return; // NOP
}
synchronized(deviceVersionAvailable) {
if(DEBUG) {
System.err.println(getThreadName() + ": createContextARB-MapGLVersions REMAP "+fromDevice+" -> "+toDevice);
System.err.println(getThreadName() + ": createContextARB-MapGLVersions REMAP "+fromDevice+" -> "+toDevice+
", overwrite "+overwrite+", ctpCriteria "+getGLProfile(new StringBuilder(), ctpCriteria).toString());
}
final IdentityHashMap<String, Integer> newDeviceVersionAvailable = new IdentityHashMap<String, Integer>();
final Set<String> keys = deviceVersionAvailable.keySet();
Expand All @@ -1115,7 +1127,7 @@ protected static void remapAvailableGLVersions(final AbstractGraphicsDevice from
if(DEBUG) {
final int[] ctp = { 0 };
final VersionNumber version = decomposeBits(valI.intValue(), ctp);
System.err.println(" MapGLVersions REMAP OLD "+origKey+" -> "+GLContext.getGLVersion(new StringBuilder(), version, ctp[0], null).toString());
System.err.println(" MapGLVersions REMAP VAL0 "+origKey+" == "+GLContext.getGLVersion(new StringBuilder(), version, ctp[0], null).toString());
}
newDeviceVersionAvailable.put(origKey, valI);
final int devSepIdx = origKey.lastIndexOf('-');
Expand All @@ -1124,12 +1136,29 @@ protected static void remapAvailableGLVersions(final AbstractGraphicsDevice from
}
final String devUniqueID = origKey.substring(0, devSepIdx);
if( fromDevice.getUniqueID().equals(devUniqueID) ) {
// key/val pair from 'fromDevice' to be mapped to 'toDevice'
final String profileReq = origKey.substring(devSepIdx);
final String newKey = (toDevice.getUniqueID()+profileReq).intern();
final Integer preI = deviceVersionAvailable.get(newKey);
final int valCTP = getCTPFromBits(valI.intValue());
final boolean write = ( overwrite || null == preI ) && 0 != ( ctpCriteria & valCTP );
if( write ) {
newDeviceVersionAvailable.put(newKey, valI);
}
if(DEBUG) {
System.err.println(" MapGLVersions REMAP NEW "+newKey+" -> (ditto)");
if( write ) {
System.err.println(" MapGLVersions REMAP NEW0 "+newKey+" -> (ditto)");
} else {
System.err.println(" MapGLVersions REMAP NEW0 "+newKey+" (unchanged)");
}
if( null != preI ) {
final int[] ctp = { 0 };
final VersionNumber version = decomposeBits(preI.intValue(), ctp);
System.err.println(" MapGLVersions REMAP OLD1 "+newKey+" :: "+GLContext.getGLVersion(new StringBuilder(), version, ctp[0], null).toString());
} else {
System.err.println(" MapGLVersions REMAP OLD1 "+newKey+" :: (nil)");
}
}
newDeviceVersionAvailable.put(newKey, valI);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/jogl/classes/jogamp/opengl/egl/EGLContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,12 @@ protected static StringBuilder getGLProfile(final StringBuilder sb, final int ct
return GLContext.getGLProfile(sb, ctp);
}
/* pp */ int getContextOptions() { return ctxOptions; }
protected static void remapAvailableGLVersions(final AbstractGraphicsDevice fromDevice, final AbstractGraphicsDevice toDevice) {
GLContextImpl.remapAvailableGLVersions(fromDevice, toDevice);
/**
* Delegates to {@link GLContextImpl#remapAvailableGLVersions(AbstractGraphicsDevice, AbstractGraphicsDevice, boolean, int)}
*/
protected static void remapAvailableGLVersions(final AbstractGraphicsDevice fromDevice, final AbstractGraphicsDevice toDevice,
final boolean overwrite, final int ctpCriteria) {
GLContextImpl.remapAvailableGLVersions(fromDevice, toDevice, overwrite, ctpCriteria);
}
protected static synchronized void setMappedGLVersionListener(final MappedGLVersionListener mvl) {
GLContextImpl.setMappedGLVersionListener(mvl);
Expand Down
4 changes: 3 additions & 1 deletion src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,9 @@ public void glVersionMapped(final MappedGLVersion e) {
}

if( mappedToDefaultDevice[0] ) {
EGLContext.remapAvailableGLVersions(defaultDevice, adevice);
// map all GL versions (ES, CORE or COMPAT) to 'adevice' if not existing (no overwrite)
EGLContext.remapAvailableGLVersions(defaultDevice, adevice, false /* overwrite */,
EGLContext.CTX_PROFILE_ES | EGLContext.CTX_PROFILE_CORE | EGLContext.CTX_PROFILE_COMPAT );
sr = defaultSharedResource;
} else {
if( hasX11 ) {
Expand Down

0 comments on commit e222310

Please sign in to comment.