MCPcopy Create free account
hub / github.com/carbonengine/trinity / SetConstants

Method SetConstants

trinityal/dx11/Tr2RenderContextDx11.cpp:1171–1271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1169}
1170
1171ALResult Tr2RenderContextAL::SetConstants(
1172 const Tr2ConstantBufferAL& buffer,
1173 Tr2RenderContextEnum::ShaderType constantType,
1174 uint32_t registerIndex,
1175 uint32_t ) throw()
1176{
1177 using namespace Tr2RenderContextEnum;
1178
1179 ID3D11Buffer* bufArray[1] = { buffer.m_buffer->m_buffer };
1180
1181 if( buffer.m_buffer->GetUsage() == Tr2ConstantUsageAL::ONE_SHOT )
1182 {
1183 uint32_t constantDataSize = buffer.GetSize();
1184 const void* constantData = buffer.m_buffer->m_bufferMirror.get();
1185
1186 if( constantType < SHADER_TYPE_FIRST || constantType >= SHADER_TYPE_COUNT || registerIndex >= CB_SLOT_COUNT )
1187 {
1188 return E_INVALIDARG;
1189 }
1190
1191 if( constantDataSize == 0 )
1192 {
1193 return S_OK;
1194 }
1195 SharedConstantBuffer& cb = m_sharedConstantBuffers[constantType * CB_SLOT_COUNT + registerIndex];
1196 if( cb.mirror.size() < constantDataSize )
1197 {
1198 cb.mirror.resize( "Tr2RenderContextAL.m_sharedConstantBuffers.mirror", constantDataSize );
1199 }
1200 if( cb.size == constantDataSize )
1201 {
1202 if( memcmp( cb.mirror.get(), constantData, constantDataSize ) == 0 )
1203 {
1204 CCP_STATS_INC( cbCacheHit );
1205 return S_OK;
1206 }
1207 }
1208 bool alreadySet = cb.size != 0;
1209
1210 CCP_STATS_INC( cbCacheMiss );
1211 memcpy( cb.mirror.get(), constantData, constantDataSize );
1212 cb.size = buffer.GetSize();
1213 if( !cb.constantBuffer.IsValid() || cb.constantBuffer.GetSize() < constantDataSize )
1214 {
1215 auto& renderContext = Tr2RenderContextAL::GetPrimaryRenderContext();
1216 CR_RETURN_HR( cb.constantBuffer.Create( ( constantDataSize + 15 ) / 16 * 16, renderContext ) );
1217 alreadySet = false;
1218 }
1219 void* data;
1220 CR_RETURN_HR( cb.constantBuffer.Lock( &data, *this ) );
1221 memcpy( data, constantData, constantDataSize );
1222 CR_RETURN_HR( cb.constantBuffer.Unlock( *this ) );
1223
1224 bufArray[0] = cb.constantBuffer.m_buffer->m_buffer;
1225
1226 if( alreadySet )
1227 {
1228 return S_OK;

Callers

nothing calls this directly

Calls 14

GetUsageMethod · 0.80
getMethod · 0.80
sizeMethod · 0.80
VSSetConstantBuffersMethod · 0.80
PSSetConstantBuffersMethod · 0.80
CSSetConstantBuffersMethod · 0.80
GSSetConstantBuffersMethod · 0.80
HSSetConstantBuffersMethod · 0.80
DSSetConstantBuffersMethod · 0.80
GetSizeMethod · 0.45
IsValidMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected