Skip to content

Instantly share code, notes, and snippets.

@BoyBaykiller
BoyBaykiller / boxTriangleIntersect.glsl
Last active October 27, 2023 03:00
Box vs Triangle Intersection test GLSL
float Min3(float a, float b, float c)
{
return min(a, min(b, c));
}
float Max3(float a, float b, float c)
{
return max(a, max(b, c));
}
@BoyBaykiller
BoyBaykiller / AmdEXT_shader_image_load_formattedNotReported.md
Last active March 9, 2025 05:22
OpenGL Bug: GL_EXT_shader_image_load_formatted extension not reported even though its implemented

I can require and use GL_EXT_shader_image_load_formatted in OpenGL-GLSL shaders without any problems:

#extension GL_EXT_shader_image_load_formatted : require
layout(binding = 0) restrict uniform image2D ImgResult;

However on the client side the extension is not reported when asking for it like this:

GLint numExt;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExt);
@BoyBaykiller
BoyBaykiller / AmdBindlessCompressedLodArtifacts.md
Last active March 9, 2025 05:22
OpenGL Bug Generating Mipmap after getting TextureHandle causes texture sampling to return black at any other Lod than 0 if compressed format is used

High level steps to reproduce:

  • Create a valid 2D Texture with compressed internal format

  • Upload some pixels

  • Generate a bindless texture handle

  • Generate a mipmap for the texture

@BoyBaykiller
BoyBaykiller / AmdBindlessSamplingCrash.md
Last active March 9, 2025 05:22
OpenGL Bug: Very simple shader sampling a texture and using Bindless Textures causes crash

Running this very simple shader causes a freeze for a few seconds and ultimately some kind of driver reset. This bug does not happen on latest public driver (24.3.1)!

Here is the shader code to reproduce it:

#version 460 core
#extension GL_ARB_bindless_texture : require

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
@BoyBaykiller
BoyBaykiller / AmdPerformanceglPushDebugGroup.md
Last active March 9, 2025 05:21
OpenGL Performance Issue: Cpu-Time for glPushDebugGroup is unreasonably long

Calling glPushDebugGroup can easily introduce performance issues. The following loop with 50 iterations takes 22ms!

int main()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
@BoyBaykiller
BoyBaykiller / AmdCreateDeleteBindlessTextureCrash.md
Last active March 9, 2025 05:21
OpenGL: Creating & Deleting many Bindless Textures without glfwSwapBuffers causes access violation in driver

Running the following code throws an exception (when creating the 1536th texture) from inside the driver: Exception thrown at 0x00007FFC07BFDB20 (atio6axx.dll) in MyProgram.exe: 0xC0000005: Access violation reading location 0x0000000000000008.

I am simply creating a texture making it bindless and deleting it again. If the texture is not made bindless it runs fine. Also putting glfwSwapBuffers always makes it run fine.

for (int i = 0; i < 1600; i++) {
    uint32_t test;
    glCreateTextures(GL_TEXTURE_2D, 1, &test);
@BoyBaykiller
BoyBaykiller / AmdMapReadHostMem.md
Created August 22, 2024 17:42
OpenGL MAP_READ_BIT or MAP_COHERENT_BIT cause buffer to reside in HOST memory even with ReBar/SAM

I've noticed that buffers allocated with GL_MAP_WRITE_BIT or GL_MAP_READ_BIT end up in HOST memory. Example:

uint32_t size = 1 << 22; // 4MiB
uint32_t buf;
glCreateBuffers(1, &buf);
glNamedBufferStorage(buf, size, nullptr, GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT);
//glMapNamedBufferRange(buf, 0, size, GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT); // not needed to reproduce

It happens with any other additional combination of flags too. What's interersting is that the memory report of a RX 5700 XT

@BoyBaykiller
BoyBaykiller / AmdBindlessPerformanceOverhead.md
Last active October 25, 2024 20:42
OpenGL Performance overhead of bindless resident textures

Currently, having many bindless resident textures can cause a big performance overhead in the OpenGL driver. Just to give you a rough idea of scale, these are the numbers I am getting in my renderer:

Count Time
0 0.5ms
1_000 0.56ms
2_000 7.8ms
4_000 16.6ms
8_000 58.8ms
@BoyBaykiller
BoyBaykiller / AmdMeshShaderCantUseBindlessExtension.md
Last active March 9, 2025 05:29
OpenGL Mesh shader compile error when enabling GL_ARB_bindless_texture

First, I want to thank you for making the effort of implementing Mesh Shaders in OpenGL!

When compiling a mesh or task shader that enables GL_ARB_bindless_texture I get this compiler output:

ERROR: 0:3: 'GL_ARB_bindless_texture' : not allowed when using generating SPIR-V codes
ERROR: 0:3: '#extension' : extra tokens -- expected newline
ERROR: 0:3: '' : compilation terminated
ERROR: 3 compilation errors.  No code generated.

Reproducible:

****** START compiling Program.EntryPoint:GetTest(Program.EntryPoint+Vector2,int):float (MethodHash=2b4c0cab)
Generating code for Windows x64
OPTIONS: Tier-0 compilation (set DOTNET_TieredCompilation=0 to disable)
OPTIONS: compCodeOpt = BLENDED_CODE
OPTIONS: compDbgCode = false
OPTIONS: compDbgInfo = true
OPTIONS: compDbgEnC = false
OPTIONS: compProcedureSplitting = false
OPTIONS: compProcedureSplittingEH = false
IL to import: