@@ -3289,6 +3289,23 @@ namespace bgfx
32893289 {
32903290 const UniformRef& uniform = getUniformRef (_handle);
32913291
3292+ const UniformFreq::Enum freq = UINT16_MAX == _id
3293+ ? UniformFreq::Frame
3294+ : UniformFreq::View
3295+ ;
3296+
3297+ BX_ASSERT (0 < uniform.m_refCount
3298+ , " Uniform reference count it 0 (handle %3d)!"
3299+ , _handle.idx
3300+ );
3301+ BX_ASSERT (uniform.m_freq == freq
3302+ , " Setting uniform per view, but uniform is created with different bgfx::UniformFreq::Enum!"
3303+ );
3304+ BX_ASSERT (_num == UINT16_MAX || uniform.m_num >= _num
3305+ , " Truncated uniform update. %d (max: %d)"
3306+ , _num, uniform.m_num
3307+ );
3308+
32923309 UniformCacheKey key =
32933310 {
32943311 .m_offset = 0 ,
@@ -4667,9 +4684,10 @@ namespace bgfx
46674684 }
46684685
46694686 PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum (name);
4670- if (PredefinedUniform::Count == predefined && UniformType::End != UniformType::Enum (type) )
4687+ if (PredefinedUniform::Count == predefined
4688+ && UniformType::End != UniformType::Enum (type) )
46714689 {
4672- uniforms[sr.m_num ] = createUniform (name, UniformFreq::Draw , UniformType::Enum (type), num);
4690+ uniforms[sr.m_num ] = createUniform (name, UniformFreq::Count , UniformType::Enum (type), num);
46734691 sr.m_num ++;
46744692 }
46754693 }
@@ -5354,7 +5372,11 @@ namespace bgfx
53545372 const uint32_t oldsize = g_uniformTypeSize[uniform.m_type ];
53555373 const uint32_t newsize = g_uniformTypeSize[_type];
53565374
5357- uniform.m_freq = _freq; // Ignore shader created uniforms, and use UniformFreq when user creates uniform.
5375+ if (UniformFreq::Count != _freq)
5376+ {
5377+ // Ignore shader created uniforms, and use UniformFreq when user creates uniform.
5378+ uniform.m_freq = _freq;
5379+ }
53585380
53595381 if (oldsize < newsize
53605382 || uniform.m_num < _num)
@@ -5390,7 +5412,10 @@ namespace bgfx
53905412 UniformRef& uniform = m_uniformRef[handle.idx ];
53915413 uniform.m_name .set (_name);
53925414 uniform.m_refCount = 1 ;
5393- uniform.m_freq = _freq;
5415+ uniform.m_freq = UniformFreq::Count == _freq
5416+ ? UniformFreq::Draw
5417+ : _freq
5418+ ;
53945419 uniform.m_type = _type;
53955420 uniform.m_num = _num;
53965421
0 commit comments