Ejemplo n.º 1
0
	//----------------------------------------------------------------------------//
	void D3D9Shader::parseParam(D3DXHANDLE parent, String prefix, unsigned int index)
	{
		D3DXHANDLE hConst = mpConstTable->GetConstant(parent, index);

		D3DXCONSTANT_DESC desc;
		uint numParams = 1;
		HRESULT hr = mpConstTable->GetConstantDesc(hConst, &desc, &numParams);
		if(FAILED(hr))
		{
			TITAN_EXCEPT_API(
				"we can not get constants descriptions from shader");
		}

		String paramName = desc.Name;
		// trim the odd '$' which appears at the start of the names in HLSL
		if (paramName.at(0) == '$')
			paramName.erase(paramName.begin());

		// Also trim the '[0]' suffix if it exists, we will add our own indexing later
		if (StringUtil::endsWith(paramName, "[0]", false))
		{
			paramName.erase(paramName.size() - 3);
		}

		if (desc.Class == D3DXPC_STRUCT)
		{
			prefix = prefix + paramName + ".";
			for(uint i = 0;i < desc.StructMembers; ++i)
			{
				parseParam(hConst, prefix, i);
			}
		}
		else
		{
			if (desc.Type == D3DXPT_FLOAT || desc.Type == D3DXPT_INT || desc.Type == D3DXPT_BOOL)
			{
				size_t paramIndex = desc.RegisterIndex;
				String name = prefix + paramName;

				ShaderConstantDef def;
				def.registerIndex = paramIndex;
				populateDef(desc, def);
				if (def.isFloat())
				{
					def.physicalIndex = mFloatRegisterToPhysical->bufferSize;
					mFloatRegisterToPhysical->bufferMap.insert(ShaderRegisterIndexUseMap::value_type(
						paramIndex, 
						ShaderRegisterIndexUse(def.physicalIndex,def.arraySize * def.elementSize)));
					mFloatRegisterToPhysical->bufferSize += def.arraySize * def.elementSize;
					mConstantDefs->floatBufferSize = mFloatRegisterToPhysical->bufferSize;
				}
				else
				{
					def.physicalIndex = mIntRegisterToPhysical->bufferSize;
					mIntRegisterToPhysical->bufferMap.insert(ShaderRegisterIndexUseMap::value_type(
						paramIndex, 
						ShaderRegisterIndexUse(def.physicalIndex,def.arraySize * def.elementSize)));
					mIntRegisterToPhysical->bufferSize += def.arraySize * def.elementSize;
					mConstantDefs->intBufferSize = mIntRegisterToPhysical->bufferSize;
				}

				mConstantDefs->constantDefMap.insert(ShaderConstantDefMap::value_type(name, def));

				mConstantDefs->genConstantDefArrayEntries(name, def);
			}
		}

	}
Ejemplo n.º 2
0
	//-----------------------------------------------------------------------
	void D3D10HLSLProgram::processParamElement(String prefix, LPCSTR pName, 
		size_t paramIndex, ID3D10ShaderReflectionType* varRefType) const
	{
		D3D10_SHADER_TYPE_DESC varRefTypeDesc;
		HRESULT hr = varRefType->GetDesc(&varRefTypeDesc);


		// Since D3D HLSL doesn't deal with naming of array and struct parameters
		// automatically, we have to do it by hand


		if (FAILED(hr))
		{
			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
				"Cannot retrieve constant description from HLSL program.", 
				"D3D10HLSLProgram::processParamElement");
		}

		String paramName = pName;
		// trim the odd '$' which appears at the start of the names in HLSL
		if (paramName.at(0) == '$')
			paramName.erase(paramName.begin());

		// Also trim the '[0]' suffix if it exists, we will add our own indexing later
		if (StringUtil::endsWith(paramName, "[0]", false))
		{
			paramName.erase(paramName.size() - 3);
		}




		if (varRefTypeDesc.Class == D3D10_SVC_STRUCT)
		{
			// work out a new prefix for nested members, if it's an array, we need an index
			prefix = prefix + paramName + ".";
			// Cascade into struct
			for (unsigned int i = 0; i < varRefTypeDesc.Members; ++i)
			{
				processParamElement(prefix, varRefType->GetMemberTypeName(i), i,  varRefType->GetMemberTypeByIndex(i));
			}
		}
		else
		{
			// Process params
			if (varRefTypeDesc.Type == D3D10_SVT_FLOAT || varRefTypeDesc.Type == D3D10_SVT_INT || varRefTypeDesc.Type == D3D10_SVT_BOOL)
			{
				String name = prefix + paramName;

				GpuConstantDefinition def;
				// populate type, array size & element size
				populateDef(varRefTypeDesc, def);
				if (def.isFloat())
				{
					def.physicalIndex = mFloatLogicalToPhysical.bufferSize;
					OGRE_LOCK_MUTEX(mFloatLogicalToPhysical.mutex)
						mFloatLogicalToPhysical.map.insert(
						GpuLogicalIndexUseMap::value_type(paramIndex, 
						GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize)));
					mFloatLogicalToPhysical.bufferSize += def.arraySize * def.elementSize;
					mConstantDefs.floatBufferSize = mFloatLogicalToPhysical.bufferSize;
				}
				else
				{
					def.physicalIndex = mIntLogicalToPhysical.bufferSize;
					OGRE_LOCK_MUTEX(mIntLogicalToPhysical.mutex)
						mIntLogicalToPhysical.map.insert(
						GpuLogicalIndexUseMap::value_type(paramIndex, 
						GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize)));
					mIntLogicalToPhysical.bufferSize += def.arraySize * def.elementSize;
					mConstantDefs.intBufferSize = mIntLogicalToPhysical.bufferSize;
				}

				mConstantDefs.map.insert(GpuConstantDefinitionMap::value_type(name, def));

				// Now deal with arrays
				mConstantDefs.generateConstantDefinitionArrayEntries(name, def);
			}
		}

	}