"Unknown NIR alu instr: div 32" encountered while developing with OpenGL 3.3
System information
Output of inxi -GSC -xx
output:
System:
Host: user Kernel: 6.5.0-15-generic x86_64 bits: 64 compiler: N/A
Desktop: GNOME 42.9 tk: GTK 3.24.33 wm: gnome-shell dm: GDM3
Distro: Ubuntu 22.04.3 LTS (Jammy Jellyfish)
CPU:
Info: 6-core model: AMD Ryzen 5 3600 bits: 64 type: MT MCP arch: Zen 2
rev: 0 cache: L1: 384 KiB L2: 3 MiB L3: 32 MiB
Speed (MHz): avg: 2215 high: 2547 min/max: 2200/4208 boost: enabled
cores: 1: 2200 2: 2052 3: 2200 4: 2200 5: 2200 6: 2200 7: 2200 8: 2200
9: 2547 10: 2196 11: 2200 12: 2195 bogomips: 86243
Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
Graphics:
Device-1: AMD Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT]
vendor: Micro-Star MSI driver: amdgpu v: kernel pcie: speed: 16 GT/s
lanes: 16 ports: active: DP-1,DP-2,HDMI-A-1 empty: DP-3 bus-ID: 05:00.0
chip-ID: 1002:731f
Display: wayland server: X.org v: 1.21.1.4 with: Xwayland v: 22.1.1
compositor: gnome-shell driver: X: loaded: amdgpu,ati
unloaded: fbdev,modesetting,radeon,vesa gpu: amdgpu display-ID: 0
Monitor-1: DP-1 model: MSI G24C4 res: 1920x1080 dpi: 94
diag: 598mm (23.5")
Monitor-2: DP-2 model: Samsung S22F350 res: 1920x1080 dpi: 102
diag: 547mm (21.5")
Monitor-3: HDMI-A-1 model: Acer EB222Q res: 1920x1080 dpi: 102
diag: 547mm (21.5")
OpenGL: renderer: AMD Radeon RX 5700 XT (navi10 LLVM 16.0.6 DRM 3.54
6.5.0-15-generic)
v: 4.6 Mesa 23.2.0-devel direct render: Yes
Issue
I have encountered an error message while developing with OpenGL:
Unknown NIR alu instr: div 32 %11 = ineg %10
radeonsi: can't compile a main shader part (type: MESA_SHADER_FRAGMENT, name: GLSL3).
This is probably a driver bug, please report it to https://gitlab.freedesktop.org/mesa/mesa/-/issues.
Unknown NIR alu instr: div 32 %11 = ineg %10
Unknown NIR alu instr: div 32 %11 = ineg %10
Unknown NIR alu instr: div 32 %11 = ineg %10
...
The last line is printed repeatedly on each newly drawn frame. The message appeared while I was playing with the GLSL code.
Here's a minimum reproducible example I could get on my device:
Vertex
#version 330 core
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 coords;
out vec2 uv_coords;
void main()
{
gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
uv_coords = coords;
}
Fragment
#version 330 core
in vec2 uv_coords;
out vec4 FragColor;
uniform sampler2D tex;
// This should make a blur gradient, no blur on the 400 leftmost columns, then
// a gradient up to a blur of strength 20 over 20 pixels (1 strength level per
// pixel).
void main()
{
FragColor = vec4(0.0, 0.5, 1.0, 1.0);
int blur_strength = int(floor(clamp(gl_FragCoord.x - 400, 0, 20)));
float divisors[21] = float[21](
1.0,
8.881580,
24.031157,
45.304184,
71.174217,
99.920395,
129.820221,
159.317474,
187.143555,
212.382355,
234.480820,
253.215805,
268.632599,
280.970123,
290.587860,
297.900818,
303.330780,
307.271240,
310.067993,
312.010956,
313.332306
);
float dist = 0.002;
int steps = blur_strength;
vec3 color = vec3(0.0);
for (int x = -blur_strength; x <= blur_strength; x++) {
for (int y = -blur_strength; y <= blur_strength; y++) {
// color += texture(tex, uv_coords + vec2(x, y) * dist).rgb * pow(1.01, -x * x - y * y) / divisors[blur_strength];
color += vec3(1.0 / divisors[blur_strength]);
}
}
FragColor = vec4(color.rgb, 1.0);
}
Drawing a simple 2D quad covering the screen with this shader prints this error. The shader seems to be skipped entirely when that happens, as the glClearColor shows through.
In case it helps, I've also made a minimum C++ app that runs the shader. It requires SDL3, Glad, and stb_image. It expects an img.png
and a shader.{vert,frag}
in the current working directory.
I've noticed that Pastebin is down, and the snippets section here has been disabled. I'll paste it here, but I can edit it out if it takes too much space or if Pastebin starts working again:
#include <SDL3/SDL.h>
#include <fstream>
#include <stdexcept>
#include <glad/glad.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>
static const int WIDTH = 640;
static const int HEIGHT = 480;
// Loads "./img.png"
unsigned int create_some_texture()
{
unsigned int id;
int width, height, nrChannels;
unsigned char *data = stbi_load("img.png", &width, &height, &nrChannels, 0);
GLenum type;
if (nrChannels == 3)
{
type = GL_RGB;
}
else if (nrChannels == 4)
{
type = GL_RGBA;
}
else
{
throw std::runtime_error("Texture isn't RGB or RGBA");
}
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, type, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(data);
return id;
}
// Loads "./shader.{vert,frag}"
unsigned int create_shader()
{
unsigned int vert, frag, shader;
{
std::ifstream file("shader.vert");
std::string contents((std::istreambuf_iterator<char>(file)), (std::istreambuf_iterator<char>()));
const char *src = contents.c_str();
int success;
char err[1024];
vert = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vert, 1, &src, NULL);
glCompileShader(vert);
glGetShaderiv(vert, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(vert, 1024, NULL, err);
throw std::runtime_error(err);
}
}
{
std::ifstream file("shader.frag");
std::string contents((std::istreambuf_iterator<char>(file)), (std::istreambuf_iterator<char>()));
const char *src = contents.c_str();
int success;
char err[1024];
frag = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(frag, 1, &src, NULL);
glCompileShader(frag);
glGetShaderiv(frag, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(frag, 1024, NULL, err);
throw std::runtime_error(err);
}
}
shader = glCreateProgram();
glAttachShader(shader, vert);
glAttachShader(shader, frag);
glLinkProgram(shader);
return shader;
}
// Generates a generic plane with texture coordinates
unsigned int create_some_mesh()
{
const float data[] = {
-1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, -1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f
};
unsigned int vao, vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
// Vertices
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*) 0);
glEnableVertexAttribArray(0);
// Tex coords
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
return vao;
}
void main_loop(SDL_Window* w)
{
bool quit = false;
glViewport(0, 0, WIDTH, HEIGHT);
unsigned int shader = create_shader();
unsigned int texture = create_some_texture();
unsigned int vao = create_some_mesh();
// Setup texture
glUseProgram(shader);
int location = glGetUniformLocation(shader, "tex");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glUniform1i(location, 0);
while (!quit)
{
SDL_Event e;
while (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_EVENT_QUIT:
quit = true;
return;
}
}
glClearColor(0.2f, 0.2f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shader);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 6);
SDL_GL_SwapWindow(w);
SDL_Delay(10);
}
}
int main()
{
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_Window* w = SDL_CreateWindow("OpenGL", WIDTH, HEIGHT, SDL_WINDOW_OPENGL);
SDL_GLContext ctx = SDL_GL_CreateContext(w);
gladLoadGL();
main_loop(w);
SDL_DestroyWindow(w);
SDL_Quit();
return 0;
}
Additional information
I've observed that uncommenting line 47 of the fragment shader, and commenting line 48, results in visible vertical bands in odd-numbered columns in the blur gradient:
Screencast_from_2024-01-31_05_52_53_PM
This is probably a different issue; I mention it here only if it happens to be related in some way and helps identifying the issue.
I've included the same shader on a 3D renderer as it shows the banding more clearly.