Пример #1
0
dx10ConstantBuffer::dx10ConstantBuffer(ID3D10ShaderReflectionConstantBuffer* pTable)
	: m_bChanged(true)
{
	D3D10_SHADER_BUFFER_DESC Desc;

	CHK_DX(pTable->GetDesc(&Desc));

	m_strBufferName._set(Desc.Name);
	m_eBufferType = Desc.Type;
	m_uiBufferSize = Desc.Size;

	//	Fill member list with variable descriptions
	m_MembersList.resize(Desc.Variables);
	m_MembersNames.resize(Desc.Variables);
	for (u32 i=0; i<Desc.Variables; ++i)
	{
		ID3D10ShaderReflectionVariable* pVar;
		ID3D10ShaderReflectionType*		pType;

		D3D10_SHADER_VARIABLE_DESC		var_desc;

		pVar = pTable->GetVariableByIndex(i);
		VERIFY(pVar);
		pType = pVar->GetType();
		VERIFY(pType);
		pType->GetDesc(&m_MembersList[i]);
		//	Buffers with the same layout can contain totally different members
		CHK_DX(pVar->GetDesc(&var_desc));
		m_MembersNames[i] = var_desc.Name;
	}

	m_uiMembersCRC = crc32( &m_MembersList[0], Desc.Variables*sizeof(m_MembersList[0]));

	R_CHK(dx10BufferUtils::CreateConstantBuffer(&m_pBuffer, Desc.Size));
	VERIFY(m_pBuffer);
	m_pBufferData = xr_malloc(Desc.Size);
	VERIFY(m_pBufferData);
}
Пример #2
0
BOOL R_constant_table::parseConstants(ID3D10ShaderReflectionConstantBuffer* pTable, u16 destination)
{
	//VERIFY(_desc);
	//ID3D10ShaderReflectionConstantBuffer *pTable = (ID3D10ShaderReflectionConstantBuffer *)_desc;
	VERIFY(pTable);
	D3D10_SHADER_BUFFER_DESC	TableDesc;
	CHK_DX(pTable->GetDesc(&TableDesc));

	//D3DXSHADER_CONSTANTTABLE* desc	= (D3DXSHADER_CONSTANTTABLE*) _desc;
	//D3DXSHADER_CONSTANTINFO* it		= (D3DXSHADER_CONSTANTINFO*) (LPBYTE(desc)+desc->ConstantInfo);
	//LPBYTE					 ptr	= LPBYTE(desc);
	//for (u32 dwCount = desc->Constants; dwCount; dwCount--,it++)
	for (u32 i = 0; i < TableDesc.Variables; ++i)
	{
		ID3D10ShaderReflectionVariable* pVar;
		D3D10_SHADER_VARIABLE_DESC		VarDesc;
		ID3D10ShaderReflectionType*		pType;
		D3D10_SHADER_TYPE_DESC			TypeDesc;

		pVar = pTable->GetVariableByIndex(i);
		VERIFY(pVar);
		pVar->GetDesc(&VarDesc);
		pType = pVar->GetType();
		VERIFY(pType);
		pType->GetDesc(&TypeDesc);

		// Name
		//LPCSTR	name		=	LPCSTR(ptr+it->Name);
		LPCSTR	name		=	VarDesc.Name;

		// Type
		//u16		type		=	RC_float;
		u16		type = u16(-1);
		switch(TypeDesc.Type)
		{
		case D3D10_SVT_FLOAT:
			type = RC_float;
			break;
		case D3D10_SVT_BOOL:
			type	= RC_bool;
			break;
		case D3D10_SVT_INT:
			type	= RC_int;
			break;
		default:
			fatal ("R_constant_table::parse: unexpected shader variable type.");
		}

		// Rindex,Rcount
		//u16		r_index		=	it->RegisterIndex;
		//	Used as byte offset in constant buffer
		VERIFY(VarDesc.StartOffset<0x10000);
		u16		r_index		=	u16(VarDesc.StartOffset);
		u16		r_type		=	u16(-1);

		// TypeInfo + class
		//D3DXSHADER_TYPEINFO*	T	= (D3DXSHADER_TYPEINFO*)(ptr+it->TypeInfo);
		BOOL bSkip					= FALSE;
		//switch (T->Class)
		switch (TypeDesc.Class)
		{
		case D3D10_SVC_SCALAR:
			r_type = RC_1x1;
			break;
		case D3D10_SVC_VECTOR:
			{
				switch(TypeDesc.Columns)
				{
				case 4:
					r_type = RC_1x4;
					break;
				case 3:
					r_type = RC_1x3;
				    break;
				case 2:
					r_type = RC_1x2;
					break;
				default:
					fatal("Vector: 1 components is scalar - there is special case for this!!!!!");
				    break;
				}
			}
			break;
		case D3D10_SVC_MATRIX_ROWS:
			{
				switch (TypeDesc.Columns)
				{
				case 4:
					switch (TypeDesc.Rows)
					{
					case 2:
						r_type = RC_2x4;
						break;
					case 3:
						r_type = RC_3x4;
						break;
						/*
						switch (it->RegisterCount)
						{
						case 2:	r_type	=	RC_2x4;	break;
						case 3: r_type	=	RC_3x4;	break;
						default:	
						fatal		("MATRIX_ROWS: unsupported number of RegisterCount");
						break;
						}
						break;
						*/
					case 4: 
						r_type = RC_4x4;
						//VERIFY(4 == it->RegisterCount); 
						break;
					default:
						fatal		("MATRIX_ROWS: unsupported number of Rows");
						break;
					}
					break;
				default:
					fatal		("MATRIX_ROWS: unsupported number of Columns");
					break;
				}
			}
			break;
		case D3D10_SVC_MATRIX_COLUMNS:
			fatal		("Pclass MATRIX_COLUMNS unsupported");
			break;
		case D3D10_SVC_STRUCT:
			fatal		("Pclass D3DXPC_STRUCT unsupported");
			break;
		case D3D10_SVC_OBJECT:
			{
				//	TODO: DX10: 
				VERIFY(!"Implement shader object parsing.");
				/*
				switch (T->Type)
				{
				case D3DXPT_SAMPLER:
				case D3DXPT_SAMPLER1D:
				case D3DXPT_SAMPLER2D:
				case D3DXPT_SAMPLER3D:
				case D3DXPT_SAMPLERCUBE:
				{
				// ***Register sampler***
				// We have determined all valuable info, search if constant already created
				ref_constant	C		=	get	(name);
				if (!C)	{
				C					= new R_constant();//.g_constant_allocator.create();
				C->name				=	name;
				C->destination		=	RC_dest_sampler;
				C->type				=	RC_sampler;
				R_constant_load& L	=	C->samp;
				L.index				=	u16(r_index	+ ( (destination&1)? 0 : D3DVERTEXTEXTURESAMPLER0 ));
				L.cls				=	RC_sampler	;
				table.push_back		(C);
				} else {
				R_ASSERT			(C->destination	==	RC_dest_sampler);
				R_ASSERT			(C->type		==	RC_sampler);
				R_constant_load& L	=	C->samp;
				R_ASSERT			(L.index		==	r_index);
				R_ASSERT			(L.cls			==	RC_sampler);
				}
				}
				break;
				default:
				fatal		("Pclass D3DXPC_OBJECT - object isn't of 'sampler' type");
				break;
				}
				*/
			}
			bSkip		= TRUE;
			break;
		default:
			bSkip		= TRUE;
			break;
		}
		if (bSkip)			continue;

		// We have determined all valuable info, search if constant already created
		ref_constant	C		=	get	(name);
		if (!C)	{
			C					= new R_constant();//.g_constant_allocator.create();
			C->name				=	name;
			C->destination		=	destination;
			C->type				=	type;
			//R_constant_load& L	=	(destination&1)?C->ps:C->vs;
			R_constant_load& L	=	((destination&RC_dest_pixel)
									? C->ps : (destination&RC_dest_vertex)
									? C->vs : C->gs);
			L.index				=	r_index;
			L.cls				=	r_type;
			table.push_back		(C);
		} else {
			C->destination		|=	destination;
			VERIFY	(C->type	==	type);
			//R_constant_load& L	=	(destination&1)?C->ps:C->vs;
			R_constant_load& L	=	((destination&RC_dest_pixel)
									? C->ps : (destination&RC_dest_vertex)
									? C->vs : C->gs);
			L.index				=	r_index;
			L.cls				=	r_type;
		}
	}
	return TRUE;
}
Пример #3
0
void ShaderReflectionPimpl::PrintReflection(ID3D10ShaderReflection * reflection)
{
	std::cout << "ShaderReflection: " << std::endl;
	D3D10_SHADER_DESC shader_desc;
	reflection->GetDesc(&shader_desc);


	unsigned int input_count = shader_desc.InputParameters;
	std::cout << "	InputCount: " << input_count << std::endl;

	for (unsigned int input_index = 0; input_index < input_count; ++input_index)
	{
		D3D10_SIGNATURE_PARAMETER_DESC input_signature;
		reflection->GetInputParameterDesc(input_index, &input_signature);

		unsigned int component[4];
		component[0] = (input_signature.Mask & 0x01);
		component[1] = (input_signature.Mask & 0x02) >> 1;
		component[2] = (input_signature.Mask & 0x04) >> 2;
		component[3] = (input_signature.Mask & 0x08) >> 3;

		unsigned int num_components_used = 0;
		for (unsigned int i = 0; i < 4; ++i)
		{
			num_components_used += component[i];
		}

		std::cout << "		Input: " << input_signature.SemanticName << " | ";
		std::cout << input_signature.SemanticIndex << " | ";
		std::cout << input_signature.Register << " | ";
		std::cout << component[3] << component[2] << component[1] << component[0] << " | " << num_components_used << std::endl;
	}

	unsigned int cbuffer_count = shader_desc.ConstantBuffers;
	std::cout << "	CBufferCount: " << cbuffer_count << std::endl;

	for (unsigned int cbuffer_index = 0; cbuffer_index < cbuffer_count; ++cbuffer_index)
	{
		ID3D10ShaderReflectionConstantBuffer * cbuff = reflection->GetConstantBufferByIndex(cbuffer_index);

		D3D10_SHADER_BUFFER_DESC shader_buff_desc;
		cbuff->GetDesc(&shader_buff_desc);

		std::cout << "		CBuffer: " << shader_buff_desc.Name << " | " << shader_buff_desc.Size << " | " << shader_buff_desc.Type << std::endl;

		unsigned int variable_count = shader_buff_desc.Variables;

		for (unsigned int var_index = 0; var_index < variable_count; ++var_index)
		{

			ID3D10ShaderReflectionVariable * shader_var = cbuff->GetVariableByIndex(var_index);
			

			D3D10_SHADER_VARIABLE_DESC shader_var_desc;
			shader_var->GetDesc(&shader_var_desc);
			ID3D10ShaderReflectionType * type = shader_var->GetType();

			D3D10_SHADER_TYPE_DESC var_type_desc;
			type->GetDesc(&var_type_desc);

			std::cout << "			Var: " << shader_var_desc.Name << std::endl;
			std::cout << "				Size: " << shader_var_desc.Size << std::endl;
			std::cout << "				Offset: " << shader_var_desc.StartOffset << std::endl;
			std::cout << "				Class: " << var_type_desc.Class << std::endl;
			std::cout << "				Type: " << var_type_desc.Type << std::endl;
			std::cout << "				Rows: " << var_type_desc.Rows << std::endl;
			std::cout << "				Columns: " << var_type_desc.Columns << std::endl;
			switch (var_type_desc.Class)
			{
			case D3D10_SVC_MATRIX_ROWS:
				std::cout << "				Order: Row-Major" << std::endl;
				break;
			case D3D10_SVC_MATRIX_COLUMNS:
				std::cout << "				Order: Column-Major" << std::endl;
				break;
			default:
				std::cout << "				Order: Column-Major" << std::endl;
				break;

			}
		}
	}

	unsigned int boundresource_count = shader_desc.BoundResources;
	std::cout << "	BoundResources: " << boundresource_count << std::endl;

	for (unsigned int boundresource_index = 0; boundresource_index < boundresource_count; ++boundresource_index)
	{
		D3D10_SHADER_INPUT_BIND_DESC input_bind_desc;
		reflection->GetResourceBindingDesc(boundresource_index, &input_bind_desc);

		std::cout << "		Name: " << input_bind_desc.Name << std::endl;
		std::cout << "			BindPoint: " << input_bind_desc.BindPoint << std::endl;

		switch(input_bind_desc.Dimension)
		{
			case D3D10_SRV_DIMENSION_UNKNOWN:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_UNKNOWN" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_BUFFER:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_BUFFER" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_TEXTURE1D:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURE1D" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_TEXTURE1DARRAY:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURE1DARRAY" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_TEXTURE2D:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURE2D" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_TEXTURE2DARRAY:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURE2DARRAY" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_TEXTURE2DMS:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURE2DMS" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY" << std::endl;
				break;
				case D3D10_SRV_DIMENSION_TEXTURE3D:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURE3D" << std::endl;
				break;
			case D3D10_SRV_DIMENSION_TEXTURECUBE:
				std::cout << "			Dimension: D3D10_SRV_DIMENSION_TEXTURECUBE" << std::endl;
				break;
			default:
				break;
		}


		switch(input_bind_desc.Type)
		{
			case D3D10_SIT_CBUFFER:
				std::cout << "			Type: D3D10_SIT_CBUFFER" << std::endl;
				break;
			case D3D10_SIT_TBUFFER:
				std::cout << "			Type: D3D10_SIT_TBUFFER" << std::endl;
				break;
			case D3D10_SIT_TEXTURE:
				std::cout << "			Type: D3D10_SIT_TEXTURE" << std::endl;
				break;
			case D3D10_SIT_SAMPLER:
				std::cout << "			Type: D3D10_SIT_SAMPLER" << std::endl;
				break;
			default:
				break;
		}
	}
}