Skip to content

Commit 8f4c7fe

Browse files
committed
Clean-up buffer binds
1 parent 6dbbd9b commit 8f4c7fe

File tree

6 files changed

+85
-23
lines changed

6 files changed

+85
-23
lines changed

src.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ set(COMMONTESTLIST
7878
)
7979

8080
set(RENDERERLIST
81+
${ENGINE_DIR}/renderer/BufferBind.h
8182
${ENGINE_DIR}/renderer/DetectGLVendors.cpp
8283
${ENGINE_DIR}/renderer/DetectGLVendors.h
8384
${ENGINE_DIR}/renderer/gl_shader.cpp

src/engine/renderer/BufferBind.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
===========================================================================
3+
4+
Daemon BSD Source Code
5+
Copyright (c) 2025 Daemon Developers
6+
All rights reserved.
7+
8+
This file is part of the Daemon BSD Source Code (Daemon Source Code).
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
* Neither the name of the Daemon developers nor the
18+
names of its contributors may be used to endorse or promote products
19+
derived from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
===========================================================================
33+
*/
34+
// BufferBind.h
35+
36+
#ifndef BUFFERBIND_H
37+
#define BUFFERBIND_H
38+
39+
namespace BufferBind {
40+
enum : uint32_t {
41+
// UBO
42+
MATERIALS = 0,
43+
TEX_DATA = 1,
44+
LIGHTMAP_DATA = 2,
45+
LIGHTS = 3,
46+
47+
SURFACE_BATCHES = 4,
48+
49+
// SSBO
50+
SURFACE_DESCRIPTORS = 0,
51+
SURFACE_COMMANDS = 1,
52+
CULLED_COMMANDS = 2,
53+
PORTAL_SURFACES = 4,
54+
55+
GEOMETRY_CACHE_INPUT_VBO = 5,
56+
GEOMETRY_CACHE_VBO = 6,
57+
58+
COMMAND_COUNTERS_STORAGE = 9,
59+
TEX_DATA_STORAGE = 11,
60+
61+
DEBUG = 10,
62+
63+
// Atomic
64+
COMMAND_COUNTERS_ATOMIC = 0,
65+
66+
UNUSED = INT32_MAX
67+
};
68+
};
69+
70+
#endif // BUFFERBIND_H

src/engine/renderer/Material.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535

3636
#include "tr_local.h"
3737
#include "Material.h"
38+
#include "BufferBind.h"
3839
#include "ShadeCommon.h"
3940
#include "GeometryCache.h"
4041

@@ -541,7 +542,13 @@ void MaterialSystem::GenerateWorldCommandBuffer( std::vector<MaterialSurface>& s
541542
surfaceDescriptorsSSBO.BufferData( surfaceDescriptorsCount * descriptorSize, nullptr, GL_STATIC_DRAW );
542543
uint32_t* surfaceDescriptors = surfaceDescriptorsSSBO.MapBufferRange( surfaceDescriptorsCount * descriptorSize );
543544

544-
texDataBufferType = glConfig2.maxUniformBlockSize >= MIN_MATERIAL_UBO_SIZE ? GL_UNIFORM_BUFFER : GL_SHADER_STORAGE_BUFFER;
545+
if ( glConfig2.maxUniformBlockSize >= MIN_MATERIAL_UBO_SIZE ) {
546+
texDataBufferType = GL_UNIFORM_BUFFER;
547+
texDataBindingPoint = BufferBind::TEX_DATA;
548+
} else {
549+
texDataBufferType = GL_SHADER_STORAGE_BUFFER;
550+
texDataBindingPoint = BufferBind::TEX_DATA_STORAGE;
551+
}
545552

546553
texDataBuffer.BufferStorage( ( texData.size() + dynamicTexData.size() ) * TEX_BUNDLE_SIZE, 1, nullptr );
547554
texDataBuffer.MapAll();
@@ -2023,7 +2030,7 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
20232030

20242031
atomicCommandCountersBuffer.BindBuffer( GL_PARAMETER_BUFFER_ARB );
20252032

2026-
texDataBuffer.BindBufferBase( texDataBufferType );
2033+
texDataBuffer.BindBufferBase( texDataBufferType, texDataBindingPoint );
20272034
lightMapDataUBO.BindBufferBase();
20282035

20292036
if ( r_showGlobalMaterials.Get() && material.sort != 0
@@ -2140,7 +2147,7 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
21402147

21412148
atomicCommandCountersBuffer.UnBindBuffer( GL_PARAMETER_BUFFER_ARB );
21422149

2143-
texDataBuffer.UnBindBufferBase( texDataBufferType );
2150+
texDataBuffer.UnBindBufferBase( texDataBufferType, texDataBindingPoint );
21442151
lightMapDataUBO.UnBindBufferBase();
21452152

21462153
if ( material.usePolygonOffset ) {

src/engine/renderer/Material.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,26 +306,6 @@ struct SurfaceCommandBatch {
306306
uint32_t materialIDs[2] { 0, 0 };
307307
};
308308

309-
namespace BufferBind {
310-
enum : uint32_t {
311-
MATERIALS = 1,
312-
TEX_DATA = 6,
313-
LIGHTMAP_DATA = 2,
314-
LIGHTS = 0,
315-
SURFACE_DESCRIPTORS = 0,
316-
SURFACE_COMMANDS = 1,
317-
CULLED_COMMANDS = 2,
318-
SURFACE_BATCHES = 3,
319-
COMMAND_COUNTERS_ATOMIC = 0,
320-
COMMAND_COUNTERS_STORAGE = 4, // Avoid needlessly rebinding buffers
321-
PORTAL_SURFACES = 5,
322-
GEOMETRY_CACHE_INPUT_VBO = 6,
323-
GEOMETRY_CACHE_VBO = 7,
324-
DEBUG = 10,
325-
UNUSED = INT32_MAX
326-
};
327-
};
328-
329309
class MaterialSystem {
330310
public:
331311
vec3_t worldViewBounds[2];
@@ -431,6 +411,7 @@ class MaterialSystem {
431411
std::vector<shaderStage_t*> dynamicStages;
432412

433413
GLenum texDataBufferType;
414+
GLuint texDataBindingPoint;
434415
std::vector<TextureData> texData;
435416
std::vector<TextureData> dynamicTexData;
436417

src/engine/renderer/gl_shader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ static std::string GenVertexHeader() {
584584
if ( glConfig2.usingMaterialSystem ) {
585585
AddDefine( str, "BIND_MATERIALS", BufferBind::MATERIALS );
586586
AddDefine( str, "BIND_TEX_DATA", BufferBind::TEX_DATA );
587+
AddDefine( str, "BIND_TEX_DATA_STORAGE", BufferBind::TEX_DATA_STORAGE );
587588
AddDefine( str, "BIND_LIGHTMAP_DATA", BufferBind::LIGHTMAP_DATA );
588589
}
589590

@@ -628,6 +629,7 @@ static std::string GenFragmentHeader() {
628629
if ( glConfig2.usingMaterialSystem ) {
629630
AddDefine( str, "BIND_MATERIALS", BufferBind::MATERIALS );
630631
AddDefine( str, "BIND_TEX_DATA", BufferBind::TEX_DATA );
632+
AddDefine( str, "BIND_TEX_DATA_STORAGE", BufferBind::TEX_DATA_STORAGE );
631633
AddDefine( str, "BIND_LIGHTMAP_DATA", BufferBind::LIGHTMAP_DATA );
632634
}
633635

src/engine/renderer/gl_shader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2424
#define GL_SHADER_H
2525

2626
#include "tr_local.h"
27+
#include "BufferBind.h"
2728
#include <stdexcept>
2829

2930
#define USE_UNIFORM_FIREWALL 1

0 commit comments

Comments
 (0)