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 error running 'Hello World' code #227

Open
kayleigh222 opened this issue Dec 22, 2024 · 3 comments
Open

OpenGL error running 'Hello World' code #227

kayleigh222 opened this issue Dec 22, 2024 · 3 comments

Comments

@kayleigh222
Copy link

Hiya! I'm getting:
File "/home//.local/lib/python3.10/site-packages/OpenGL/GL/shaders.py", line 196, in compileProgram
program.check_validate()
File "/home//.local/lib/python3.10/site-packages/OpenGL/GL/shaders.py", line 105, in check_validate
raise RuntimeError(
RuntimeError: Validation failure (0): b'active samplers with a different type refer to the same texture image unit'

Error when running the Hello World code on CPU:
image

Any pointers on how to fix it?

@hexadecimal-REBOOT
Copy link

I'm getting the same issue on a M1 Mac

@rghilduta
Copy link

Seeing the same thing on a rented A10

@hexadecimal-REBOOT
Copy link

Based on the jit_render.py code, the OpenGL shader validation error on M1 Macs is occurring in the texture binding and program compilation process. Here are the key issues and required changes:

  1. In the forward_pass function, texture units are not properly managed:
def forward_pass(self, renderer, V, P, cam_pos, flags, program_flags, screen_size, color_list=None, reflection_mat=np.identity(4, np.float32), floor_tex=0):
    # Need to track and limit texture units
    active_texture = lighting_texture  # Could exceed M1's 16 texture unit limit
  1. In the bind_lighting function, texture units are not properly bounded:
@njit
def bind_lighting(pid, flags, light, shadow_map, light_matrix, ambient_light, gl):
    active_texture = 0
    # Need to ensure texture unit doesn't exceed 15 (0-15 range for M1)

Required changes:

  1. Add texture unit management:
MAX_TEXTURE_UNITS = 16  # M1 Mac limit

@njit
def bind_lighting(pid, flags, light, shadow_map, light_matrix, ambient_light, gl):
    active_texture = 0
    # Track used texture units
    used_units = set()
    
    for i in range(n):
        if active_texture >= MAX_TEXTURE_UNITS:
            break
        # Assign texture units ensuring no conflicts
        texture_unit = active_texture % MAX_TEXTURE_UNITS
        used_units.add(texture_unit)
        active_texture += 1
  1. Modify texture binding in forward pass:
@njit
def forward_pass(...):
    # Track sampler types per texture unit
    sampler_types = {}
    
    for id in idx:
        if active_texture >= MAX_TEXTURE_UNITS:
            break
            
        # Ensure different sampler types use different units
        texture_unit = active_texture % MAX_TEXTURE_UNITS
        if texture_unit not in sampler_types:
            sampler_types[texture_unit] = set()
  1. Add validation checks:
def _validate_texture_units(self):
    # Ensure total texture units don't exceed M1 limit
    total_units = (
        len(self.shadow_map) +  # Shadow maps
        sum(1 for tex in self.textures if tex[0])  # Material textures
    )
    if total_units > MAX_TEXTURE_UNITS:
        raise ValueError(f"Total texture units ({total_units}) exceeds M1 Mac limit (16)")

These changes would:

  • Prevent texture unit overflow
  • Ensure different sampler types use different units
  • Validate texture unit allocation before rendering
  • Work within M1 Mac's OpenGL limitations

The error occurs because the current implementation doesn't properly manage texture units within the M1's constraints.

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

No branches or pull requests

3 participants