Renderer: Add support for storage buffers
This commit is contained in:
@@ -41,17 +41,26 @@ namespace Nz
|
||||
|
||||
private:
|
||||
struct DescriptorPool;
|
||||
struct StorageBufferDescriptor;
|
||||
struct TextureDescriptor;
|
||||
struct UniformBufferDescriptor;
|
||||
|
||||
DescriptorPool& AllocatePool();
|
||||
ShaderBindingPtr AllocateFromPool(std::size_t poolIndex, UInt32 setIndex);
|
||||
template<typename F> void ForEachDescriptor(std::size_t poolIndex, std::size_t bindingIndex, F&& functor);
|
||||
StorageBufferDescriptor& GetStorageBufferDescriptor(std::size_t poolIndex, std::size_t bindingIndex, std::size_t descriptorIndex);
|
||||
TextureDescriptor& GetTextureDescriptor(std::size_t poolIndex, std::size_t bindingIndex, std::size_t descriptorIndex);
|
||||
UniformBufferDescriptor& GetUniformBufferDescriptor(std::size_t poolIndex, std::size_t bindingIndex, std::size_t descriptorIndex);
|
||||
void Release(ShaderBinding& binding);
|
||||
inline void TryToShrink();
|
||||
|
||||
struct StorageBufferDescriptor
|
||||
{
|
||||
GLuint buffer;
|
||||
GLintptr offset;
|
||||
GLsizeiptr size;
|
||||
};
|
||||
|
||||
struct TextureDescriptor
|
||||
{
|
||||
GLuint texture;
|
||||
@@ -66,7 +75,7 @@ namespace Nz
|
||||
GLsizeiptr size;
|
||||
};
|
||||
|
||||
using Descriptor = std::variant<std::monostate, TextureDescriptor, UniformBufferDescriptor>;
|
||||
using Descriptor = std::variant<std::monostate, StorageBufferDescriptor, TextureDescriptor, UniformBufferDescriptor>;
|
||||
|
||||
struct DescriptorPool
|
||||
{
|
||||
|
||||
@@ -265,6 +265,7 @@ namespace Nz
|
||||
case GL::BufferTarget::ElementArray: return GL_ELEMENT_ARRAY_BUFFER;
|
||||
case GL::BufferTarget::PixelPack: return GL_PIXEL_PACK_BUFFER;
|
||||
case GL::BufferTarget::PixelUnpack: return GL_PIXEL_UNPACK_BUFFER;
|
||||
case GL::BufferTarget::Storage: return GL_SHADER_STORAGE_BUFFER;
|
||||
case GL::BufferTarget::TransformFeedback: return GL_TRANSFORM_FEEDBACK_BUFFER;
|
||||
case GL::BufferTarget::Uniform: return GL_UNIFORM_BUFFER;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Nz::GL
|
||||
ElementArray,
|
||||
PixelPack,
|
||||
PixelUnpack,
|
||||
Storage,
|
||||
TransformFeedback,
|
||||
Uniform,
|
||||
|
||||
@@ -52,6 +53,7 @@ namespace Nz::GL
|
||||
{
|
||||
DepthClamp,
|
||||
SpirV,
|
||||
StorageBuffers,
|
||||
TextureCompressionS3tc,
|
||||
TextureFilterAnisotropic,
|
||||
|
||||
@@ -120,6 +122,7 @@ namespace Nz::GL
|
||||
void BindFramebuffer(FramebufferTarget target, GLuint fbo) const;
|
||||
void BindProgram(GLuint program) const;
|
||||
void BindSampler(UInt32 textureUnit, GLuint sampler) const;
|
||||
void BindStorageBuffer(UInt32 storageUnit, GLuint buffer, GLintptr offset, GLsizeiptr size) const;
|
||||
void BindTexture(TextureTarget target, GLuint texture) const;
|
||||
void BindTexture(UInt32 textureUnit, TextureTarget target, GLuint texture) const;
|
||||
void BindUniformBuffer(UInt32 uboUnit, GLuint buffer, GLintptr offset, GLsizeiptr size) const;
|
||||
@@ -212,22 +215,23 @@ namespace Nz::GL
|
||||
GLsizei width, height;
|
||||
};
|
||||
|
||||
struct TextureUnit
|
||||
{
|
||||
GLuint sampler = 0;
|
||||
std::array<GLuint, UnderlyingCast(TextureTarget::Max) + 1> textureTargets = { 0 };
|
||||
};
|
||||
|
||||
struct UniformBufferUnit
|
||||
struct BufferBinding
|
||||
{
|
||||
GLuint buffer = 0;
|
||||
GLintptr offset = 0;
|
||||
GLsizeiptr size = 0;
|
||||
};
|
||||
|
||||
struct TextureUnit
|
||||
{
|
||||
GLuint sampler = 0;
|
||||
std::array<GLuint, UnderlyingCast(TextureTarget::Max) + 1> textureTargets = { 0 };
|
||||
};
|
||||
|
||||
std::array<GLuint, UnderlyingCast(BufferTarget::Max) + 1> bufferTargets = { 0 };
|
||||
std::vector<TextureUnit> textureUnits;
|
||||
std::vector<UniformBufferUnit> uboUnits;
|
||||
std::vector<BufferBinding> storageUnits;
|
||||
std::vector<BufferBinding> uboUnits;
|
||||
Box scissorBox;
|
||||
Box viewport;
|
||||
GLuint boundProgram = 0;
|
||||
|
||||
Reference in New Issue
Block a user