protected void ProcessParamElement( ConstantTable constantTable, EffectHandle parent, string prefix, int index )
{
var constant = constantTable.GetConstant( parent, index );
// Since D3D HLSL doesn't deal with naming of array and struct parameters
// automatically, we have to do it by hand
var desc = constantTable.GetConstantDescription( constant );
var paramName = desc.Name;
// trim the odd '$' which appears at the start of the names in HLSL
if ( paramName.StartsWith( "$" ) )
{
paramName = paramName.Remove( 0, 1 );
}
// Also trim the '[0]' suffix if it exists, we will add our own indexing later
if (paramName.EndsWith("[0]"))
{
paramName.Remove( paramName.Length - 3 );
}
if (desc.Class == ParameterClass.Struct)
{
// work out a new prefix for the nextest members if its an array, we need the index
prefix = prefix + paramName + ".";
// Cascade into struct
for (var i = 0; i < desc.StructMembers; ++i)
{
ProcessParamElement(constantTable, constant, prefix, i);
}
}
else
{
// process params
if ( desc.Type == ParameterType.Float ||
desc.Type == ParameterType.Int ||
desc.Type == ParameterType.Bool )
{
var paramIndex = desc.RegisterIndex;
var name = prefix + paramName;
var def = new GpuProgramParameters.GpuConstantDefinition();
def.LogicalIndex = paramIndex;
// populate type, array size & element size
PopulateDef( desc, def );
if ( def.IsFloat )
{
def.PhysicalIndex = floatLogicalToPhysical.BufferSize;
lock ( floatLogicalToPhysical.Mutex )
{
floatLogicalToPhysical.Map.Add( paramIndex,
new GpuProgramParameters.GpuLogicalIndexUse(
def.PhysicalIndex,
def.ArraySize*def.ElementSize,
GpuProgramParameters.GpuParamVariability.Global ) );
floatLogicalToPhysical.BufferSize += def.ArraySize*def.ElementSize;
}
}
else
{
def.PhysicalIndex = intLogicalToPhysical.BufferSize;
lock ( intLogicalToPhysical.Mutex )
{
intLogicalToPhysical.Map.Add( paramIndex,
new GpuProgramParameters.GpuLogicalIndexUse(
def.PhysicalIndex,
def.ArraySize*def.ElementSize,
GpuProgramParameters.GpuParamVariability.Global ) );
intLogicalToPhysical.BufferSize += def.ArraySize*def.ElementSize;
}
}
if ( !parametersMap.ContainsKey( paramName ) )
{
parametersMap.Add( paramName, def );
/*
parametersMapSizeAsBuffer += sizeof ( int );
parametersMapSizeAsBuffer += paramName.Length;
parametersMapSizeAsBuffer += Marshal.SizeOf( def );
*/
}
}
}
}