Why are half my uniforms missing when initializing a compute shader using python modernGL?

176 Views Asked by At

Here is the problem: I'm creating a compute shader in python for radiative transfer using modernGL. But upon creation, it does not contain all the uniforms I declare in the shader code. Here is my (simplified) python code:

# Creation of the context
context = mgl.create_standalone_context(require=440)
# Creation of the compute shader with the source code passed as a string stored in a separate file
compute_shader = context.compute_shader(src_code)

# I set the uniform values stored in a dictionary defined previously. The keys of the dictionary match the uniforms defined in the shader source code.
for key, value in uniforms.items():
    compute_shader.get(key, default=None).write(value)

Here is the head of the shader source file 'src_code':

#version 440

uniform float instrument_azimut;
uniform float instrument_elevation;
uniform float instrument_altitude;
uniform float instrument_lon;
uniform float instrument_lat;
uniform float instrument_area;
uniform float instrument_fov;
uniform float wavelength;
uniform int   los_nb_points;
uniform float map_delta_az;
uniform bool  is_point_source;
uniform int   atm_nb_altitudes;
uniform int   atm_nb_angles;
uniform bool  use_aerosol;
// Iterable uniforms
uniform float instrument_los[3];
uniform float los_altitudes[100];
uniform float atm_altitudes[121];
uniform float map_azimuts[10];
uniform float map_distances[10];
uniform float los_volumes[100];
uniform float atm_total_abs[121];
uniform float atm_ray_beta[121];
uniform float atm_aer_beta[121];
uniform float atm_angles[100];
uniform float atm_aer_Pfct[121];
uniform float atm_aer_Pfct_DoLP[121];
uniform float los_transmittance[100];


#define X 1
#define Y 1
#define Z 100


// Set up our compute groups
layout(local_size_x = X, local_size_y = Y, local_size_z = Z) in;

// Define constant values
const float EARTH_RADIUS = 6371.; //km
const float PI = 3.14159;
const float DtoR = PI / 180;
const float RtoD = 1. / DtoR;


// Stokes paramter buffers
layout(std430, binding=0) buffer in_0{
    float in_V[];};
layout(std430, binding=1) buffer in_1{
    float in_Vcos[];};
layout(std430, binding=2) buffer in_2{
    float in_Vsin[];};

layout(std430, binding=3) buffer out_3{
    float out_V[];};
layout(std430, binding=4) buffer out_4{
    float out_Vcos[];};
layout(std430, binding=5) buffer out_5{
    float out_Vsin[];};

\\...All useful functions...

When I try to list the uniforms contained in the compute shader object, almost half are missing! The following loop

for u in compute_shader:
    print(u)

outputs:

instrument_elevation
instrument_altitude
instrument_area
map_delta_az
is_point_source
atm_nb_altitudes
atm_nb_angles
use_aerosol
los_altitudes
atm_altitudes
map_azimuts
map_distances
los_volumes
atm_total_abs
atm_ray_beta
atm_aer_beta
atm_angles
atm_aer_Pfct
atm_aer_Pfct_DoLP
los_transmittance

So when I try to write the value of the uniform "instrument_lon" (float) or "instrument_los" (float array) for example, it doesn't exists in the compute shader object. I'm lost here... I thought about a format issue, so I tried to explicitly set the type of the uniform values in the dictionary. I also tried to declare them in a different order, but it is always the same that are missing. But I can't see any differences with the one initialized correctly... Any help very welcome!

1

There are 1 best solutions below

0
On

This question was solved on github here: link The problem was that I did not use the single float value uniforms that were disappearing. One exception being the length 3 array, that I did use, and that I couldn't get rid off. So I passed it as a vec3 uniform instead, and it solved the issue. About the number of components, it was not the main issue, but it still is good practice to reduce it below 1024, so I will do that using a couple of buffers.