@@ -2002,13 +2002,14 @@ void COpenGLDriver::drawIndexedIndirect(const asset::SBufferBinding<IGPUBuffer>
2002
2002
extGlMultiDrawElementsIndirect (primType,indexSize,(void *)offset,maxCount,stride);
2003
2003
}
2004
2004
2005
- void COpenGLDriver::SAuxContext::flushState_descriptors (E_PIPELINE_BIND_POINT _pbp, const COpenGLPipelineLayout* _currentLayout, const COpenGLPipelineLayout* _prevLayout )
2005
+ void COpenGLDriver::SAuxContext::flushState_descriptors (E_PIPELINE_BIND_POINT _pbp, const COpenGLPipelineLayout* _currentLayout)
2006
2006
{
2007
+ const COpenGLPipelineLayout* prevLayout = effectivelyBoundDescriptors.layout .get ();
2007
2008
// bind new descriptor sets
2008
2009
int32_t compatibilityLimit = 0u ;
2009
- if (_prevLayout && _currentLayout)
2010
- compatibilityLimit = _prevLayout ->isCompatibleUpToSet (IGPUPipelineLayout::DESCRIPTOR_SET_COUNT-1u , _currentLayout)+1u ;
2011
- if (!_prevLayout && !_currentLayout)
2010
+ if (prevLayout && _currentLayout)
2011
+ compatibilityLimit = prevLayout ->isCompatibleUpToSet (IGPUPipelineLayout::DESCRIPTOR_SET_COUNT-1u , _currentLayout)+1u ;
2012
+ if (!prevLayout && !_currentLayout)
2012
2013
compatibilityLimit = static_cast <int32_t >(IGPUPipelineLayout::DESCRIPTOR_SET_COUNT);
2013
2014
2014
2015
int64_t newUboCount = 0u , newSsboCount = 0u , newTexCount = 0u , newImgCount = 0u ;
@@ -2035,23 +2036,13 @@ count = (first_count.resname.count - std::max(0, static_cast<int32_t>(first_coun
2035
2036
}
2036
2037
2037
2038
// if prev and curr pipeline layouts are compatible for set N, currState.set[N]==nextState.set[N] and the sets were bound with same dynamic offsets, then binding set N would be redundant
2038
- /*
2039
- // @Crisspl this is BUGGY.
2040
- // Imagine I have desc sets A, B, C
2041
- // I do some compute work while binding a pipeline layout with {A,B,C,nullptr}
2042
- // then I do some graphics work while binding a pipeline layout with {nullptr,B,nullptr}, I only ever use one pipeline
2043
- // when I do the graphics flush, the bindings will not be updated because prevLayout and currentLayout come from graphics (and are the same)
2044
- // AND the effectivelyBoundDescriptor matches with the only descriptor of the graphics bind point (both are B) this leads to problems
2045
- // you need to detect if switching effective pipelines (graphics to compute and back) will cause offsets to shift
2046
- // my suggestion is to track `current.effectivelyBoundDescriptors` and `next.effectivelyBoundDescriptors` then work from that instead of compare the next state for a pipeline with "previous" effectivelyBoundDescriptors
2047
2039
if ((i < compatibilityLimit) &&
2048
2040
(effectivelyBoundDescriptors.descSets [i].set == nextState.descriptorsParams [_pbp].descSets [i].set ) &&
2049
2041
(effectivelyBoundDescriptors.descSets [i].dynamicOffsets == nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets )
2050
2042
)
2051
2043
{
2052
2044
continue ;
2053
2045
}
2054
- */
2055
2046
2056
2047
const auto multibind_params = nextState.descriptorsParams [_pbp].descSets [i].set ?
2057
2048
nextState.descriptorsParams [_pbp].descSets [i].set ->getMultibindParams () :
@@ -2121,10 +2112,10 @@ count = (first_count.resname.count - std::max(0, static_cast<int32_t>(first_coun
2121
2112
}
2122
2113
2123
2114
// unbind previous descriptors if needed (if bindings not replaced by new multibind calls)
2124
- if (_prevLayout )// if previous pipeline was nullptr, then no descriptors were bound
2115
+ if (prevLayout )// if previous pipeline was nullptr, then no descriptors were bound
2125
2116
{
2126
2117
int64_t prevUboCount = 0u , prevSsboCount = 0u , prevTexCount = 0u , prevImgCount = 0u ;
2127
- const auto & first_count = _prevLayout ->getMultibindParamsForDescSet (video::IGPUPipelineLayout::DESCRIPTOR_SET_COUNT - 1u );
2118
+ const auto & first_count = prevLayout ->getMultibindParamsForDescSet (video::IGPUPipelineLayout::DESCRIPTOR_SET_COUNT - 1u );
2128
2119
2129
2120
prevUboCount = first_count.ubos .first + first_count.ubos .count ;
2130
2121
prevSsboCount = first_count.ssbos .first + first_count.ssbos .count ;
@@ -2145,6 +2136,7 @@ count = (first_count.resname.count - std::max(0, static_cast<int32_t>(first_coun
2145
2136
}
2146
2137
2147
2138
// update state in state tracker
2139
+ effectivelyBoundDescriptors.layout = core::smart_refctd_ptr<const COpenGLPipelineLayout>(_currentLayout);
2148
2140
for (uint32_t i = 0u ; i < video::IGPUPipelineLayout::DESCRIPTOR_SET_COUNT; ++i)
2149
2141
{
2150
2142
currentState.descriptorsParams [_pbp].descSets [i] = nextState.descriptorsParams [_pbp].descSets [i];
@@ -2154,10 +2146,6 @@ count = (first_count.resname.count - std::max(0, static_cast<int32_t>(first_coun
2154
2146
2155
2147
void COpenGLDriver::SAuxContext::flushStateGraphics (uint32_t stateBits)
2156
2148
{
2157
- const COpenGLPipelineLayout* prevLayout = nullptr ;
2158
- if ((stateBits & GSB_DESCRIPTOR_SETS) && currentState.pipeline .graphics .pipeline )
2159
- prevLayout = static_cast <const COpenGLPipelineLayout*>(currentState.pipeline .graphics .pipeline ->getLayout ());
2160
-
2161
2149
if (stateBits & GSB_PIPELINE)
2162
2150
{
2163
2151
if (nextState.pipeline .graphics .pipeline != currentState.pipeline .graphics .pipeline )
@@ -2357,7 +2345,7 @@ void COpenGLDriver::SAuxContext::flushStateGraphics(uint32_t stateBits)
2357
2345
if (stateBits & GSB_DESCRIPTOR_SETS)
2358
2346
{
2359
2347
const COpenGLPipelineLayout* currLayout = static_cast <const COpenGLPipelineLayout*>(currentState.pipeline .graphics .pipeline ->getLayout ());
2360
- flushState_descriptors (EPBP_GRAPHICS, currLayout, prevLayout );
2348
+ flushState_descriptors (EPBP_GRAPHICS, currLayout);
2361
2349
}
2362
2350
if ((stateBits & GSB_VAO_AND_VERTEX_INPUT) && currentState.pipeline .graphics .pipeline )
2363
2351
{
@@ -2557,10 +2545,6 @@ void COpenGLDriver::SAuxContext::flushStateGraphics(uint32_t stateBits)
2557
2545
2558
2546
void COpenGLDriver::SAuxContext::flushStateCompute (uint32_t stateBits)
2559
2547
{
2560
- const COpenGLPipelineLayout* prevLayout = nullptr ;
2561
- if ((stateBits & GSB_DESCRIPTOR_SETS) && currentState.pipeline .compute .pipeline )
2562
- prevLayout = static_cast <const COpenGLPipelineLayout*>(currentState.pipeline .compute .pipeline ->getLayout ());
2563
-
2564
2548
if (stateBits & GSB_PIPELINE)
2565
2549
{
2566
2550
if (nextState.pipeline .compute .usedShader != currentState.pipeline .compute .usedShader )
@@ -2591,7 +2575,7 @@ void COpenGLDriver::SAuxContext::flushStateCompute(uint32_t stateBits)
2591
2575
if (stateBits & GSB_DESCRIPTOR_SETS)
2592
2576
{
2593
2577
const COpenGLPipelineLayout* currLayout = static_cast <const COpenGLPipelineLayout*>(currentState.pipeline .compute .pipeline ->getLayout ());
2594
- flushState_descriptors (EPBP_COMPUTE, currLayout, prevLayout );
2578
+ flushState_descriptors (EPBP_COMPUTE, currLayout);
2595
2579
}
2596
2580
}
2597
2581
0 commit comments