以下代码很快崩溃(在最大缓冲区大小 2^27 texels 之前)
我删除了每一行无用的代码,使其更易于阅读。
const int MAX_LAYER_DEPTH = 5;
#include "vapp.h"
#include "vmath.h"
#include <stdio.h>
BEGIN_APP_DECLARATION(OITDemo)
// Override functions from base class
virtual void Initialize(const char * title);
virtual void Display(bool auto_redraw);
virtual void Finalize(void);
virtual void Reshape(int width, int height);
GLuint linked_list_buffer;
GLuint linked_list_texture;
GLint current_width;
GLint current_height;
END_APP_DECLARATION()
DEFINE_APP(OITDemo, "Order Independent Transparency")
void OITDemo::Initialize(const char * title)
{
base::Initialize(title);
glGenBuffers(1, &linked_list_buffer);
glGenTextures(1, &linked_list_texture);
Reshape(100,100);
return;
}
void OITDemo::Display(bool auto_redraw)
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glBindImageTexture(1, linked_list_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
base::Display();
return;
}
void OITDemo::Reshape(int width, int height)
{
current_width = width;
current_height = height;
glBindImageTexture(1, 0, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI);
static GLuint texBufferSize = 2047;
++texBufferSize;
printf("%d : texBufferSize\n",texBufferSize);
glBindBuffer(GL_TEXTURE_BUFFER, linked_list_buffer);
glBufferData(GL_TEXTURE_BUFFER, texBufferSize * texBufferSize * MAX_LAYER_DEPTH * sizeof(vmath::vec4), NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
// Bind it to a texture (for use as a TBO)
glBindTexture(GL_TEXTURE_BUFFER, linked_list_texture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32UI, linked_list_buffer);
glBindTexture(GL_TEXTURE_BUFFER, 0);
glViewport(0, 0, current_width, current_height);
return;
}
void OITDemo::Finalize(void)
{
glDeleteTextures(1, &linked_list_texture);
glDeleteBuffers(1, &linked_list_buffer);
}
驱动程序很可能无法处理碎片它在重新分配 21694445 ( 2083 x 2083 x 5 ) 和 23587920 个元素之间崩溃。显卡返回的最大缓冲区大小(纹素数)为 2^27(1.34 亿纹素)
如果我们在应用程序开始时分配一个大缓冲区并且从不更改它,似乎效果更好。但是,如果我们在应用程序的生命周期内尝试重新分配它,就会惨遭失败。
最初代码绑定图像纹理,然后使用使用该图像纹理和 imageStore 的着色器进行跟踪,但我发现我不需要任何着色器来使驱动程序崩溃。
有什么线索可以预测/防止司机撞车吗?