Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenGL] Replay issue with glUniformHandleui64ARB #911

Open
baozholu opened this issue Mar 28, 2024 · 6 comments
Open

[OpenGL] Replay issue with glUniformHandleui64ARB #911

baozholu opened this issue Mar 28, 2024 · 6 comments

Comments

@baozholu
Copy link

baozholu commented Mar 28, 2024

The return handle of glGetTextureHandleARB will differ between different vender/ASIC GPUs, current apitrace uses a _textureHandle_map and _imageHandle_map to store the original handle (Obtained during trace) and the new handle (Obtained during replay), but apitrace still uses the original handle when replaying the glUniformHandleui64ARB call, it should find the new handle through the _textureHandle_map and _imageHandle_map, then use it in glUniformHandleui64ARB.

Extension: GL_ARB_bindless_texture

All of the following APIs have this issue.
glUniformHandle*
glProgramUniformHandle*

For other APIs in the GL_ARB_bindless_texture extension, they used the _textureHandle_map/_imageHandle_map to store/get the real handle during replay
glGetTextureHandle*
glGetTextureSamplerHandle*
glGetImageHandle*
glMakeTextureHandle*
glMakeImageHandle*

So we should find the new handle through the _textureHandle_map/_imageHandle_map and use it in glUniformHandle and glProgramUniformHandle, just like glMakeTextureHandle and glMakeImageHandle does

@baozholu
Copy link
Author

baozholu commented Mar 28, 2024

Example of how to reproduce this issue:
(1) run an app/test that use the GL_ARB_bindless_texture extension
(2) trace this app on AMD GPU
(3) replay the trace on NV GPU

I directly modified glretrace_gl.cpp file, which can solve this issue, but the glretrace_gl.cpp file was automatically generated and seems to be related to the retrace.py file.
image

@baozholu baozholu changed the title Replay issue with glUniformHandleui64ARB [OpenGL] Replay issue with glUniformHandleui64ARB Mar 28, 2024
@baozholu
Copy link
Author

I captured a trace using AMD Radeon RX 7900, if using current apitrace to replay this trace on NV GPU or old ASIC AMD GPU, will observe a black window. if modify the apitrace with above patch, then replay, will observe a blue square inside the black window.
ARB_bindless_texture.zip

@baozholu
Copy link
Author

@jrfonseca do you know which "part of code"/"functions" in which file shoud I modify to add some special handling code to the glUniformHandleui64ARB function in glretrace_gl.cpp file? I have no idea where to insert the patch code because the glretrace_gl.cpp file is automatically generated, I would like to quickly push a PR to fix this issue by myself if someone can give me some hints.

@jrfonseca
Copy link
Member

Hi @baozholu ,

Apologies for the silence.

This should help in theory, but doesn't seem to make much difference in practice:

diff --git a/specs/glapi.py b/specs/glapi.py
index 6db0933f..69aa3b68 100644
--- a/specs/glapi.py
+++ b/specs/glapi.py
@@ -1021,10 +1021,10 @@ glapi.addFunctions([
     GlFunction(GLimageHandle, "glGetImageHandleARB", [(GLtexture, "texture"), (GLint, "level"), (GLboolean, "layered"), (GLint, "layer"), (GLenum, "format")]),
     GlFunction(Void, "glMakeImageHandleResidentARB", [(GLimageHandle, "handle"), (GLenum, "access")]),
     GlFunction(Void, "glMakeImageHandleNonResidentARB", [(GLimageHandle, "handle")]),
-    GlFunction(Void, "glUniformHandleui64ARB", [(GLlocation, "location"), (GLuint64, "value")]),
+    GlFunction(Void, "glUniformHandleui64ARB", [(GLlocation, "location"), (GLtextureHandle, "value")]),
     GlFunction(Void, "glUniformHandleui64vARB", [(GLlocation, "location"), (GLsizei, "count"), (Array(Const(GLuint64), "count"), "value")]),
-    GlFunction(Void, "glProgramUniformHandleui64ARB", [(GLprogram, "program"), (GLlocation, "location"), (GLuint64, "value")]),
-    GlFunction(Void, "glProgramUniformHandleui64vARB", [(GLprogram, "program"), (GLlocation, "location"), (GLsizei, "count"), (Array(Const(GLuint64), "count"), "values")]),
+    GlFunction(Void, "glProgramUniformHandleui64ARB", [(GLprogram, "program"), (GLlocation, "location"), (GLtextureHandle, "value")]),
+    GlFunction(Void, "glProgramUniformHandleui64vARB", [(GLprogram, "program"), (GLlocation, "location"), (GLsizei, "count"), (Array(Const(GLtextureHandle), "count"), "values")]),
     GlFunction(GLboolean, "glIsTextureHandleResidentARB", [(GLtextureHandle, "handle")], sideeffects=False),
     GlFunction(GLboolean, "glIsImageHandleResidentARB", [(GLimageHandle, "handle")], sideeffects=False),
     GlFunction(Void, "glVertexAttribL1ui64ARB", [(GLuint, "index"), (GLuint64, "x")]),
```

Not sure why.

You can debug this running `./glretrace -v -v -v ARB_bindless_texture.trace  |& grep -C 10 Handle` you can see glretrace attempting to swizzle the texture handles.



Full bindless support will be extremely difficult with apitrace, if not outright impossible.

The problem is that the `glGetTextureHandleARB` result values are not just used by `glUniformHandleui64ARB` can be written as plain data vertex attributes, or any texture/resource.  Even if glretrace scavenges all buffer/texture uploads and does a search and replace for recorded->replayed handle, it might do too much (replacing data that happens to have the same value as a handle) or do too little (e.g,, one passes handle+offset somewhere.)

The only way to fully support bindless would be if the OpenGL driver provided special extension that allowed glretrace to ask for a specific handle..

@baozholu

This comment was marked as resolved.

@baozholu
Copy link
Author

#923

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants