private static EffectObject.D3Dx_parameter GetParameterFromSymbol(MojoShader.MOJOSHADER_symbol symbol) { var param = new EffectObject.D3Dx_parameter { rows = symbol.info.rows, columns = symbol.info.columns, name = symbol.name ?? string.Empty, semantic = string.Empty // TODO: How do i do this with only MojoShader? }; var registerSize = (symbol.register_set == MojoShader.MOJOSHADER_symbolRegisterSet.MOJOSHADER_SYMREGSET_BOOL ? 1 : 4) * 4; int offset = (int)symbol.register_index * registerSize; param.bufferOffset = offset; switch (symbol.info.parameter_class) { case MojoShader.MOJOSHADER_symbolClass.MOJOSHADER_SYMCLASS_SCALAR: param.class_ = EffectObject.D3DXPARAMETER_CLASS.SCALAR; break; case MojoShader.MOJOSHADER_symbolClass.MOJOSHADER_SYMCLASS_VECTOR: param.class_ = EffectObject.D3DXPARAMETER_CLASS.VECTOR; break; case MojoShader.MOJOSHADER_symbolClass.MOJOSHADER_SYMCLASS_MATRIX_COLUMNS: param.class_ = EffectObject.D3DXPARAMETER_CLASS.MATRIX_COLUMNS; break; default: throw new Exception("Unsupported parameter class!"); } switch (symbol.info.parameter_type) { case MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_BOOL: param.type = EffectObject.D3DXPARAMETER_TYPE.BOOL; break; case MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_FLOAT: param.type = EffectObject.D3DXPARAMETER_TYPE.FLOAT; break; case MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_INT: param.type = EffectObject.D3DXPARAMETER_TYPE.INT; break; default: throw new Exception("Unsupported parameter type!"); } // HACK: We don't have real default parameters from mojoshader! param.data = new byte[param.rows * param.columns * 4]; param.member_count = symbol.info.member_count; param.element_count = symbol.info.elements > 1 ? symbol.info.elements : 0; if (param.member_count > 0) { param.member_handles = new EffectObject.D3Dx_parameter[param.member_count]; var members = MarshalHelper.UnmarshalArray <MojoShader.MOJOSHADER_symbol>( symbol.info.members, (int)symbol.info.member_count); for (int i = 0; i < param.member_count; i++) { var mparam = GetParameterFromSymbol(members[i]); param.member_handles[i] = mparam; } } else { param.member_handles = new EffectObject.D3Dx_parameter[param.element_count]; for (int i = 0; i < param.element_count; i++) { var mparam = new EffectObject.D3Dx_parameter { name = string.Empty, semantic = string.Empty, type = param.type, class_ = param.class_, rows = param.rows, columns = param.columns, data = new byte[param.columns * param.rows * 4] }; param.member_handles[i] = mparam; } } return(param); }
private static EffectObject.D3Dx_parameter GetParameterFromType(SharpDX.D3DCompiler.ShaderReflectionType type) { var param = new EffectObject.D3Dx_parameter { rows = (uint)type.Description.RowCount, columns = (uint)type.Description.ColumnCount, name = type.Description.Name ?? string.Empty, semantic = string.Empty, bufferOffset = type.Description.Offset }; switch (type.Description.Class) { case SharpDX.D3DCompiler.ShaderVariableClass.Scalar: param.class_ = EffectObject.D3DXPARAMETER_CLASS.SCALAR; break; case SharpDX.D3DCompiler.ShaderVariableClass.Vector: param.class_ = EffectObject.D3DXPARAMETER_CLASS.VECTOR; break; case SharpDX.D3DCompiler.ShaderVariableClass.MatrixColumns: param.class_ = EffectObject.D3DXPARAMETER_CLASS.MATRIX_COLUMNS; break; default: throw new Exception("Unsupported parameter class!"); } switch (type.Description.Type) { case SharpDX.D3DCompiler.ShaderVariableType.Bool: param.type = EffectObject.D3DXPARAMETER_TYPE.BOOL; break; case SharpDX.D3DCompiler.ShaderVariableType.Float: param.type = EffectObject.D3DXPARAMETER_TYPE.FLOAT; break; case SharpDX.D3DCompiler.ShaderVariableType.Int: param.type = EffectObject.D3DXPARAMETER_TYPE.INT; break; default: throw new Exception("Unsupported parameter type!"); } param.member_count = (uint)type.Description.MemberCount; param.element_count = (uint)type.Description.ElementCount; if (param.member_count > 0) { param.member_handles = new EffectObject.D3Dx_parameter[param.member_count]; for (var i = 0; i < param.member_count; i++) { var mparam = GetParameterFromType(type.GetMemberType(i)); mparam.name = type.GetMemberTypeName(i) ?? string.Empty; param.member_handles[i] = mparam; } } else { param.member_handles = new EffectObject.D3Dx_parameter[param.element_count]; for (var i = 0; i < param.element_count; i++) { var mparam = new EffectObject.D3Dx_parameter { name = string.Empty, semantic = string.Empty, type = param.type, class_ = param.class_, rows = param.rows, columns = param.columns, data = new byte[param.columns * param.rows * 4] }; param.member_handles[i] = mparam; } } return(param); }