Skip to content

Commit 3f58a7b

Browse files
authored
fix(samples): waive CUDA-GL interop on non-NVIDIA GL contexts (#3077)
1 parent 9dc5f33 commit 3f58a7b

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎samples/cuda_core/glInteropFluid/glInteropFluid.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import random
100100
import sys
101101
import time
102+
from pathlib import Path
102103

103104
import numpy as np
104105

@@ -122,6 +123,9 @@
122123
ReadModeType,
123124
)
124125

126+
sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "cuda_python_test_helpers"))
127+
from cuda_python_test_helpers.graphics import gl_context_not_on_nvidia_gpu_reason
128+
125129
# ---------------------------------------------------------------------------
126130
# Simulation parameters (feel free to change these)
127131
# ---------------------------------------------------------------------------
@@ -560,6 +564,11 @@ def main(argv=None):
560564
print(f"Could not open a pyglet window ({exc}); waiving glInteropFluid.", file=sys.stderr)
561565
sys.exit(EXIT_WAIVED)
562566

567+
if reason := gl_context_not_on_nvidia_gpu_reason():
568+
print(f"{reason}; waiving glInteropFluid.", file=sys.stderr)
569+
window.close()
570+
sys.exit(EXIT_WAIVED)
571+
563572
# --- Step 3: Create GL resources for drawing a texture to screen ---
564573
# (Standard OpenGL boilerplate -- not CUDA-specific.)
565574
shader_prog, quad_vao, tex_id = create_display_resources(gl, WIDTH, HEIGHT)

‎samples/cuda_core/glInteropMipmapLod/glInteropMipmapLod.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import platform
9393
import sys
9494
import time
95+
from pathlib import Path
9596

9697
import numpy as np
9798

@@ -115,6 +116,9 @@
115116
ReadModeType,
116117
)
117118

119+
sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "cuda_python_test_helpers"))
120+
from cuda_python_test_helpers.graphics import gl_context_not_on_nvidia_gpu_reason
121+
118122
# ---------------------------------------------------------------------------
119123
# Configuration (feel free to change these)
120124
# ---------------------------------------------------------------------------
@@ -468,6 +472,12 @@ def main(argv=None):
468472
except Exception as exc:
469473
print(f"Could not open a pyglet window ({exc}); waiving glInteropMipmapLod.", file=sys.stderr)
470474
sys.exit(EXIT_WAIVED)
475+
476+
if reason := gl_context_not_on_nvidia_gpu_reason():
477+
print(f"{reason}; waiving glInteropMipmapLod.", file=sys.stderr)
478+
window.close()
479+
sys.exit(EXIT_WAIVED)
480+
471481
shader_prog, quad_vao, tex_id = create_display_resources(gl, WIDTH, HEIGHT)
472482
pbo_id, _ = create_pixel_buffer(gl, WIDTH, HEIGHT)
473483
resource = GraphicsResource.from_gl_buffer(pbo_id, flags="write_discard")

‎samples/cuda_core/glInteropPlasma/glInteropPlasma.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import platform
6565
import sys
6666
import time
67+
from pathlib import Path
6768

6869
try:
6970
import numpy as np
@@ -76,6 +77,9 @@
7677
ProgramOptions,
7778
launch,
7879
)
80+
81+
sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "cuda_python_test_helpers"))
82+
from cuda_python_test_helpers.graphics import gl_context_not_on_nvidia_gpu_reason
7983
except ImportError as e:
8084
print(f"Error: Required package not found: {e}")
8185
print("Please install from requirements.txt:")
@@ -318,6 +322,11 @@ def main():
318322
print(f"Could not open a pyglet window ({e}); waiving GL interop sample.", file=sys.stderr)
319323
sys.exit(EXIT_WAIVED)
320324

325+
if reason := gl_context_not_on_nvidia_gpu_reason():
326+
print(f"{reason}; waiving GL interop sample.", file=sys.stderr)
327+
window.close()
328+
sys.exit(EXIT_WAIVED)
329+
321330
# --- Step 3: Create GL resources for drawing a texture to screen ---
322331
shader_prog, quad_vao, tex_id = create_display_resources(gl, WIDTH, HEIGHT)
323332

0 commit comments

Comments
 (0)