@@ -17,6 +17,34 @@ namespace video
17
17
template <size_t _STAGE_COUNT>
18
18
class IOpenGLPipeline
19
19
{
20
+ protected:
21
+ // needed for spirv-cross-based workaround of GL's behaviour of gl_InstanceID
22
+ struct SBaseInstance
23
+ {
24
+ GLint cache = 0 ;
25
+ GLint id = -1 ;
26
+ };
27
+
28
+ private:
29
+ using base_instance_cache_t = SBaseInstance;
30
+
31
+ _NBL_STATIC_INLINE_CONSTEXPR bool IsComputePipelineBase = (_STAGE_COUNT == 1u );
32
+ _NBL_STATIC_INLINE_CONSTEXPR uint32_t BaseInstancePerContextCacheSize = IsComputePipelineBase ? 0ull : sizeof (base_instance_cache_t );
33
+ _NBL_STATIC_INLINE_CONSTEXPR uint32_t UniformsPerContextCacheSize = _STAGE_COUNT*IGPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE + BaseInstancePerContextCacheSize;
34
+
35
+ static uint32_t baseInstanceCacheByteoffsetForCtx (uint32_t _ctxId)
36
+ {
37
+ return UniformsPerContextCacheSize*_ctxId;
38
+ }
39
+ static uint32_t uniformsCacheByteoffsetForCtx (uint32_t _ctxId)
40
+ {
41
+ return baseInstanceCacheByteoffsetForCtx (_ctxId) + BaseInstancePerContextCacheSize;
42
+ }
43
+ static uint32_t uniformsCacheByteoffsetForCtxAndStage (uint32_t _ctxId, uint32_t _stage)
44
+ {
45
+ return uniformsCacheByteoffsetForCtx (_ctxId) + _stage*IGPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE;
46
+ }
47
+
20
48
public:
21
49
IOpenGLPipeline (uint32_t _ctxCount, uint32_t _ctxID, const GLuint _GLnames[_STAGE_COUNT], const COpenGLSpecializedShader::SProgramBinary _binaries[_STAGE_COUNT]) :
22
50
m_GLprograms(core::make_refctd_dynamic_array<decltype (m_GLprograms)>(_ctxCount*_STAGE_COUNT))
@@ -34,8 +62,10 @@ class IOpenGLPipeline
34
62
(*m_GLprograms)[i*_STAGE_COUNT+j].GLname = GLname;
35
63
}
36
64
37
- const size_t uVals_sz = _STAGE_COUNT* _ctxCount*IGPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE ;
65
+ const size_t uVals_sz = UniformsPerContextCacheSize * _ctxCount;
38
66
m_uniformValues = reinterpret_cast <uint8_t *>(_NBL_ALIGNED_MALLOC (uVals_sz, 128 ));
67
+ for (uint32_t i = 0u ; i < _ctxCount; ++i)
68
+ getBaseInstanceState (i)[0 ] = base_instance_cache_t {};
39
69
}
40
70
~IOpenGLPipeline ()
41
71
{
@@ -46,7 +76,8 @@ class IOpenGLPipeline
46
76
_NBL_ALIGNED_FREE (m_uniformValues);
47
77
}
48
78
49
- uint8_t * getPushConstantsStateForStage (uint32_t _stageIx, uint32_t _ctxID) const { return const_cast <uint8_t *>(m_uniformValues + ((_STAGE_COUNT*_ctxID + _stageIx)*IGPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE)); }
79
+ uint8_t * getPushConstantsStateForStage (uint32_t _stageIx, uint32_t _ctxID) const { return const_cast <uint8_t *>(m_uniformValues + uniformsCacheByteoffsetForCtxAndStage (_ctxID, _stageIx)); }
80
+ base_instance_cache_t * getBaseInstanceState (uint32_t _ctxID) const { return const_cast <base_instance_cache_t *>(m_uniformValues + baseInstanceCacheByteoffsetForCtx (_ctxID)); }
50
81
51
82
protected:
52
83
void setUniformsImitatingPushConstants (uint32_t _stageIx, uint32_t _ctxID, const uint8_t * _pcData, const core::SRange<const COpenGLSpecializedShader::SUniform>& _uniforms, const core::SRange<const GLint>& _locations) const
@@ -80,6 +111,7 @@ class IOpenGLPipeline
80
111
{
81
112
// 1N for scalar types, 2N for gvec2, 4N for gvec3 and gvec4
82
113
// N==sizeof(float)
114
+ // WARNING / TODO : need some touch in case when we want to support `double` push constants
83
115
if (is_scalar_or_vec ())
84
116
arrayStride = (m.mtxRowCnt ==1u ) ? m.size : core::roundUpToPoT (m.mtxRowCnt )*sizeof (float );
85
117
// same as size in case of matrices
0 commit comments