@@ -1883,108 +1883,110 @@ void COpenGLDriver::SAuxContext::flushState_descriptors(E_PIPELINE_BIND_POINT _p
1883
1883
// bind new descriptor sets
1884
1884
int32_t compatibilityLimit = 0u ;
1885
1885
if (prevLayout && _currentLayout)
1886
- compatibilityLimit = prevLayout->isCompatibleUpToSet (IGPUPipelineLayout::DESCRIPTOR_SET_COUNT- 1u , _currentLayout)+ 1u ;
1887
- if (!prevLayout && !_currentLayout)
1886
+ compatibilityLimit = prevLayout->isCompatibleUpToSet (IGPUPipelineLayout::DESCRIPTOR_SET_COUNT - 1u , _currentLayout) + 1u ;
1887
+ if (!prevLayout && !_currentLayout)
1888
1888
compatibilityLimit = static_cast <int32_t >(IGPUPipelineLayout::DESCRIPTOR_SET_COUNT);
1889
1889
1890
1890
int64_t newUboCount = 0u , newSsboCount = 0u , newTexCount = 0u , newImgCount = 0u ;
1891
- if (_currentLayout)
1892
- for (uint32_t i=0u ; i<static_cast <int32_t >(IGPUPipelineLayout::DESCRIPTOR_SET_COUNT); ++i)
1893
- {
1894
- const auto & first_count = _currentLayout->getMultibindParamsForDescSet (i);
1895
-
1891
+ if (_currentLayout)
1892
+ for (uint32_t i = 0u ; i < static_cast <int32_t >(IGPUPipelineLayout::DESCRIPTOR_SET_COUNT); ++i)
1896
1893
{
1897
- GLsizei count{};
1894
+ const auto & first_count = _currentLayout->getMultibindParamsForDescSet (i);
1895
+
1896
+ {
1897
+ GLsizei count{};
1898
1898
1899
1899
#define CLAMP_COUNT (resname,limit,printstr ) \
1900
1900
count = (first_count.resname .count - std::max (0 , static_cast <int32_t >(first_count.resname .first + first_count.resname .count )-static_cast <int32_t >(limit)))
1901
1901
1902
- CLAMP_COUNT (ubos, COpenGLExtensionHandler::maxUBOBindings, UBO);
1903
- newUboCount = first_count.ubos .first + count;
1904
- CLAMP_COUNT (ssbos, COpenGLExtensionHandler::maxSSBOBindings, SSBO);
1905
- newSsboCount = first_count.ssbos .first + count;
1906
- CLAMP_COUNT (textures, COpenGLExtensionHandler::maxTextureBindings, texture); // TODO should use maxTextureBindingsCompute for compute
1907
- newTexCount = first_count.textures .first + count;
1908
- CLAMP_COUNT (textureImages, COpenGLExtensionHandler::maxImageBindings, image);
1909
- newImgCount = first_count.textureImages .first + count;
1902
+ CLAMP_COUNT (ubos, COpenGLExtensionHandler::maxUBOBindings, UBO);
1903
+ newUboCount = first_count.ubos .first + count;
1904
+ CLAMP_COUNT (ssbos, COpenGLExtensionHandler::maxSSBOBindings, SSBO);
1905
+ newSsboCount = first_count.ssbos .first + count;
1906
+ CLAMP_COUNT (textures, COpenGLExtensionHandler::maxTextureBindings, texture); // TODO should use maxTextureBindingsCompute for compute
1907
+ newTexCount = first_count.textures .first + count;
1908
+ CLAMP_COUNT (textureImages, COpenGLExtensionHandler::maxImageBindings, image);
1909
+ newImgCount = first_count.textureImages .first + count;
1910
1910
#undef CLAMP_COUNT
1911
- }
1911
+ }
1912
1912
1913
- // 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
1914
- if ((i < compatibilityLimit) &&
1915
- (effectivelyBoundDescriptors.descSets [i].set == nextState.descriptorsParams [_pbp].descSets [i].set ) &&
1916
- (effectivelyBoundDescriptors.descSets [i].dynamicOffsets == nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets )
1917
- )
1918
- {
1919
- continue ;
1920
- }
1913
+ // 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
1914
+ if ((i < compatibilityLimit) &&
1915
+ (effectivelyBoundDescriptors.descSets [i].set == nextState.descriptorsParams [_pbp].descSets [i].set ) &&
1916
+ (effectivelyBoundDescriptors.descSets [i].dynamicOffsets == nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets )
1917
+ )
1918
+ {
1919
+ continue ;
1920
+ }
1921
1921
1922
- const auto multibind_params = nextState.descriptorsParams [_pbp].descSets [i].set ?
1923
- nextState.descriptorsParams [_pbp].descSets [i].set ->getMultibindParams () :
1924
- COpenGLDescriptorSet::SMultibindParams{};// all nullptr
1922
+ const auto multibind_params = nextState.descriptorsParams [_pbp].descSets [i].set ?
1923
+ nextState.descriptorsParams [_pbp].descSets [i].set ->getMultibindParams () :
1924
+ COpenGLDescriptorSet::SMultibindParams{};// all nullptr
1925
1925
1926
- const GLsizei localStorageImageCount = newImgCount-first_count.textureImages .first ;
1927
- if (localStorageImageCount)
1928
- {
1929
- assert (multibind_params.textureImages .textures );
1930
- extGlBindImageTextures (first_count.textureImages .first , localStorageImageCount, multibind_params.textureImages .textures , nullptr ); // formats=nullptr: assuming ARB_multi_bind (or GL>4.4) is always available
1931
- }
1932
-
1933
- const GLsizei localTextureCount = newTexCount-first_count.textures .first ;
1934
- if (localTextureCount)
1935
- {
1936
- assert (multibind_params.textures .textures && multibind_params.textures .samplers );
1937
- extGlBindTextures (first_count.textures .first , localTextureCount, multibind_params.textures .textures , nullptr ); // targets=nullptr: assuming ARB_multi_bind (or GL>4.4) is always available
1938
- extGlBindSamplers (first_count.textures .first , localTextureCount, multibind_params.textures .samplers );
1939
- }
1926
+ const GLsizei localStorageImageCount = newImgCount - first_count.textureImages .first ;
1927
+ if (localStorageImageCount)
1928
+ {
1929
+ assert (multibind_params.textureImages .textures );
1930
+ // formats must be provided since we dont have ARB_multi_bind on ES
1931
+ extGlBindImageTextures (first_count.textureImages .first , localStorageImageCount, multibind_params.textureImages .textures , multibind_params.textureImages .formats );
1932
+ }
1940
1933
1941
- const bool nonNullSet = !!nextState.descriptorsParams [_pbp].descSets [i].set ;
1942
- const bool useDynamicOffsets = !!nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ;
1943
- // not entirely sure those MAXes are right
1944
- constexpr size_t MAX_UBO_COUNT = 96ull ;
1945
- constexpr size_t MAX_SSBO_COUNT = 91ull ;
1946
- constexpr size_t MAX_OFFSETS = MAX_UBO_COUNT>MAX_SSBO_COUNT ? MAX_UBO_COUNT:MAX_SSBO_COUNT;
1947
- GLintptr offsetsArray[MAX_OFFSETS]{};
1948
- GLintptr sizesArray[MAX_OFFSETS]{};
1949
-
1950
- const GLsizei localSsboCount = newSsboCount-first_count.ssbos .first ;// "local" as in this DS
1951
- if (localSsboCount)
1952
- {
1953
- if (nonNullSet)
1954
- for (GLsizei s=0u ;s<localSsboCount; ++s)
1955
- {
1956
- offsetsArray[s] = multibind_params.ssbos .offsets [s];
1957
- sizesArray[s] = multibind_params.ssbos .sizes [s];
1958
- // if it crashes below, it means that there are dynamic Buffer Objects in the DS, but the DS was bound with no (or not enough) dynamic offsets
1959
- // or for some weird reason (bug) descSets[i].set is nullptr, but descSets[i].dynamicOffsets is not
1960
- if (useDynamicOffsets && multibind_params.ssbos .dynOffsetIxs [s] < nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->size ())
1961
- offsetsArray[s] += nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->operator [](multibind_params.ssbos .dynOffsetIxs [s]);
1962
- if (sizesArray[s]==IGPUBufferView::whole_buffer)
1963
- sizesArray[s] = nextState.descriptorsParams [_pbp].descSets [i].set ->getSSBO (s)->getSize ()-offsetsArray[s];
1964
- }
1965
- assert (multibind_params.ssbos .buffers );
1966
- extGlBindBuffersRange (GL_SHADER_STORAGE_BUFFER, first_count.ssbos .first , localSsboCount, multibind_params.ssbos .buffers , nonNullSet ? offsetsArray:nullptr , nonNullSet ? sizesArray:nullptr );
1967
- }
1934
+ const GLsizei localTextureCount = newTexCount - first_count.textures .first ;
1935
+ if (localTextureCount)
1936
+ {
1937
+ assert (multibind_params.textures .textures && multibind_params.textures .samplers );
1938
+ // targets must be provided since we dont have ARB_multi_bind on ES
1939
+ extGlBindTextures (first_count.textures .first , localTextureCount, multibind_params.textures .textures , multibind_params.textures .targets );
1940
+ extGlBindSamplers (first_count.textures .first , localTextureCount, multibind_params.textures .samplers );
1941
+ }
1968
1942
1969
- const GLsizei localUboCount = (newUboCount - first_count.ubos .first );// "local" as in this DS
1970
- if (localUboCount)
1971
- {
1972
- if (nonNullSet)
1973
- for (GLsizei s=0u ;s<localUboCount; ++s)
1974
- {
1975
- offsetsArray[s] = multibind_params.ubos .offsets [s];
1976
- sizesArray[s] = multibind_params.ubos .sizes [s];
1977
- // if it crashes below, it means that there are dynamic Buffer Objects in the DS, but the DS was bound with no (or not enough) dynamic offsets
1978
- // or for some weird reason (bug) descSets[i].set is nullptr, but descSets[i].dynamicOffsets is not
1979
- if (useDynamicOffsets && multibind_params.ubos .dynOffsetIxs [s] < nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->size ())
1980
- offsetsArray[s] += nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->operator [](multibind_params.ubos .dynOffsetIxs [s]);
1981
- if (sizesArray[s]==IGPUBufferView::whole_buffer)
1982
- sizesArray[s] = nextState.descriptorsParams [_pbp].descSets [i].set ->getUBO (s)->getSize ()-offsetsArray[s];
1983
- }
1984
- assert (multibind_params.ubos .buffers );
1985
- extGlBindBuffersRange (GL_UNIFORM_BUFFER, first_count.ubos .first , localUboCount, multibind_params.ubos .buffers , nonNullSet ? offsetsArray:nullptr , nonNullSet ? sizesArray:nullptr );
1986
- }
1987
- }
1943
+ const bool nonNullSet = !!nextState.descriptorsParams [_pbp].descSets [i].set ;
1944
+ const bool useDynamicOffsets = !!nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ;
1945
+ // not entirely sure those MAXes are right
1946
+ constexpr size_t MAX_UBO_COUNT = 96ull ;
1947
+ constexpr size_t MAX_SSBO_COUNT = 91ull ;
1948
+ constexpr size_t MAX_OFFSETS = MAX_UBO_COUNT > MAX_SSBO_COUNT ? MAX_UBO_COUNT : MAX_SSBO_COUNT;
1949
+ GLintptr offsetsArray[MAX_OFFSETS]{};
1950
+ GLintptr sizesArray[MAX_OFFSETS]{};
1951
+
1952
+ const GLsizei localSsboCount = newSsboCount - first_count.ssbos .first ;// "local" as in this DS
1953
+ if (localSsboCount)
1954
+ {
1955
+ if (nonNullSet)
1956
+ for (GLsizei s = 0u ; s < localSsboCount; ++s)
1957
+ {
1958
+ offsetsArray[s] = multibind_params.ssbos .offsets [s];
1959
+ sizesArray[s] = multibind_params.ssbos .sizes [s];
1960
+ // if it crashes below, it means that there are dynamic Buffer Objects in the DS, but the DS was bound with no (or not enough) dynamic offsets
1961
+ // or for some weird reason (bug) descSets[i].set is nullptr, but descSets[i].dynamicOffsets is not
1962
+ if (useDynamicOffsets && multibind_params.ssbos .dynOffsetIxs [s] < nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->size ())
1963
+ offsetsArray[s] += nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->operator [](multibind_params.ssbos .dynOffsetIxs [s]);
1964
+ if (sizesArray[s] == IGPUBufferView::whole_buffer)
1965
+ sizesArray[s] = nextState.descriptorsParams [_pbp].descSets [i].set ->getSSBO (s)->getSize () - offsetsArray[s];
1966
+ }
1967
+ assert (multibind_params.ssbos .buffers );
1968
+ extGlBindBuffersRange (GL_SHADER_STORAGE_BUFFER, first_count.ssbos .first , localSsboCount, multibind_params.ssbos .buffers , nonNullSet ? offsetsArray : nullptr , nonNullSet ? sizesArray : nullptr );
1969
+ }
1970
+
1971
+ const GLsizei localUboCount = (newUboCount - first_count.ubos .first );// "local" as in this DS
1972
+ if (localUboCount)
1973
+ {
1974
+ if (nonNullSet)
1975
+ for (GLsizei s = 0u ; s < localUboCount; ++s)
1976
+ {
1977
+ offsetsArray[s] = multibind_params.ubos .offsets [s];
1978
+ sizesArray[s] = multibind_params.ubos .sizes [s];
1979
+ // if it crashes below, it means that there are dynamic Buffer Objects in the DS, but the DS was bound with no (or not enough) dynamic offsets
1980
+ // or for some weird reason (bug) descSets[i].set is nullptr, but descSets[i].dynamicOffsets is not
1981
+ if (useDynamicOffsets && multibind_params.ubos .dynOffsetIxs [s] < nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->size ())
1982
+ offsetsArray[s] += nextState.descriptorsParams [_pbp].descSets [i].dynamicOffsets ->operator [](multibind_params.ubos .dynOffsetIxs [s]);
1983
+ if (sizesArray[s] == IGPUBufferView::whole_buffer)
1984
+ sizesArray[s] = nextState.descriptorsParams [_pbp].descSets [i].set ->getUBO (s)->getSize () - offsetsArray[s];
1985
+ }
1986
+ assert (multibind_params.ubos .buffers );
1987
+ extGlBindBuffersRange (GL_UNIFORM_BUFFER, first_count.ubos .first , localUboCount, multibind_params.ubos .buffers , nonNullSet ? offsetsArray : nullptr , nonNullSet ? sizesArray : nullptr );
1988
+ }
1989
+ }
1988
1990
1989
1991
// unbind previous descriptors if needed (if bindings not replaced by new multibind calls)
1990
1992
if (prevLayout)// if previous pipeline was nullptr, then no descriptors were bound
@@ -2018,7 +2020,6 @@ count = (first_count.resname.count - std::max(0, static_cast<int32_t>(first_coun
2018
2020
effectivelyBoundDescriptors.descSets [i] = nextState.descriptorsParams [_pbp].descSets [i];
2019
2021
}
2020
2022
}
2021
-
2022
2023
void COpenGLDriver::SAuxContext::flushStateGraphics (uint32_t stateBits)
2023
2024
{
2024
2025
if (stateBits & GSB_PIPELINE)
0 commit comments