SHADER_VARIABLE_TYPE GetOperandDataType(HLSLCrossCompilerContext* psContext, const Operand* psOperand)
{
    switch(psOperand->eType)
	{
		case OPERAND_TYPE_TEMP:
		{
			SHADER_VARIABLE_TYPE eCurrentType;
			int i = 0;

			if(psOperand->eSelMode == OPERAND_4_COMPONENT_SELECT_1_MODE)
			{
				return psOperand->aeDataType[psOperand->aui32Swizzle[0]];
			}
			if(psOperand->eSelMode == OPERAND_4_COMPONENT_SWIZZLE_MODE)
			{
				if(psOperand->ui32Swizzle == (NO_SWIZZLE))
				{
					return psOperand->aeDataType[0];
				}

				return psOperand->aeDataType[psOperand->aui32Swizzle[0]];
			}

			if(psOperand->eSelMode == OPERAND_4_COMPONENT_MASK_MODE)
			{
				uint32_t ui32CompMask = psOperand->ui32CompMask;
				if(!psOperand->ui32CompMask)
				{
					ui32CompMask = OPERAND_4_COMPONENT_MASK_ALL;
				}
				for(;i<4;++i)
				{
					if(ui32CompMask & (1<<i))
					{
						eCurrentType = psOperand->aeDataType[i];
						break;
					}
				}

	#ifdef _DEBUG
				//Check if all elements have the same basic type.
				for(;i<4;++i)
				{
					if(psOperand->ui32CompMask & (1<<i))
					{
						if(eCurrentType != psOperand->aeDataType[i])
						{
							ASSERT(0);
						}
					}
				}
	#endif
				return eCurrentType;
			}

			ASSERT(0);
    
			break;
		}
		case OPERAND_TYPE_OUTPUT:
		{
			const uint32_t ui32Register = psOperand->aui32ArraySizes[psOperand->iIndexDims-1];
			InOutSignature* psOut;

			if(GetOutputSignatureFromRegister(ui32Register, psOperand->ui32CompMask, 0, &psContext->psShader->sInfo, &psOut))
			{
				if( psOut->eComponentType == INOUT_COMPONENT_UINT32)
				{
					return SVT_UINT;
				}
				else if( psOut->eComponentType == INOUT_COMPONENT_SINT32)
				{
					return SVT_INT;
				}
			}
			break;
		}
		case OPERAND_TYPE_INPUT:
		{
			const uint32_t ui32Register = psOperand->aui32ArraySizes[psOperand->iIndexDims-1];
			InOutSignature* psIn;

			//UINT in DX, INT in GL.
			if(psOperand->eSpecialName == NAME_PRIMITIVE_ID)
			{
				return SVT_INT;
			}

			if(GetInputSignatureFromRegister(ui32Register, &psContext->psShader->sInfo, &psIn))
			{
				if( psIn->eComponentType == INOUT_COMPONENT_UINT32)
				{
					return SVT_UINT;
				}
				else if( psIn->eComponentType == INOUT_COMPONENT_SINT32)
				{
					return SVT_INT;
				}
			}
			break;
		}
		case OPERAND_TYPE_CONSTANT_BUFFER:
		{
			ConstantBuffer* psCBuf = NULL;
			ShaderVarType* psVarType = NULL;
			int32_t index = -1;
			int32_t rebase = -1;
			int foundVar;
			GetConstantBufferFromBindingPoint(RGROUP_CBUFFER, psOperand->aui32ArraySizes[0], &psContext->psShader->sInfo, &psCBuf);
			if(psCBuf)
			{
				foundVar = GetShaderVarFromOffset(psOperand->aui32ArraySizes[1], psOperand->aui32Swizzle, psCBuf, &psVarType, &index, &rebase);
				if(foundVar && index == -1 && psOperand->psSubOperand[1] == NULL)
				{
					return psVarType->Type;
				}
			}
			else
			{
				// Todo: this isn't correct yet.
				return SVT_FLOAT;
			}
			break;
		}
		case OPERAND_TYPE_IMMEDIATE32:
		{
			return psOperand->iIntegerImmediate ? SVT_INT : SVT_FLOAT;
		}

		case OPERAND_TYPE_INPUT_THREAD_ID:
		case OPERAND_TYPE_INPUT_THREAD_GROUP_ID:
		case OPERAND_TYPE_INPUT_THREAD_ID_IN_GROUP:
		case OPERAND_TYPE_INPUT_THREAD_ID_IN_GROUP_FLATTENED:
		{
			return SVT_UINT;
		}
		case OPERAND_TYPE_SPECIAL_ADDRESS:
		{
			return SVT_INT;
		}
		default:
		{
			return SVT_FLOAT;
		}
	}

	return SVT_FLOAT;
}
SHADER_VARIABLE_TYPE GetOperandDataType(HLSLCrossCompilerContext* psContext, const Operand* psOperand)
{
    if(psOperand->eType == OPERAND_TYPE_TEMP)
    {
        SHADER_VARIABLE_TYPE eCurrentType;
		int i = 0;

		if(psOperand->eSelMode == OPERAND_4_COMPONENT_SELECT_1_MODE)
		{
			return psOperand->aeDataType[psOperand->aui32Swizzle[0]];
		}
		if(psOperand->eSelMode == OPERAND_4_COMPONENT_SWIZZLE_MODE)
		{
			if(psOperand->ui32Swizzle == (NO_SWIZZLE))
			{
				return psOperand->aeDataType[0];
			}

			return psOperand->aeDataType[psOperand->aui32Swizzle[0]];
		}

		if(psOperand->eSelMode == OPERAND_4_COMPONENT_MASK_MODE)
		{
			uint32_t ui32CompMask = psOperand->ui32CompMask;
			if(!psOperand->ui32CompMask)
			{
				ui32CompMask = OPERAND_4_COMPONENT_MASK_ALL;
			}
			for(;i<4;++i)
			{
				if(ui32CompMask & (1<<i))
				{
					eCurrentType = psOperand->aeDataType[i];
					break;
				}
			}

#ifdef _DEBUG
			//Check if all elements have the same basic type.
			for(;i<4;++i)
			{
				if(psOperand->ui32CompMask & (1<<i))
				{
					if(eCurrentType != psOperand->aeDataType[i])
					{
						ASSERT(0);
					}
				}
			}
#endif
			return eCurrentType;
		}

		ASSERT(0);
    }
	else if(psOperand->eType == OPERAND_TYPE_OUTPUT)
	{
		const uint32_t ui32Register = psOperand->aui32ArraySizes[psOperand->iIndexDims-1];
		InOutSignature* psOut;

		if(GetOutputSignatureFromRegister(ui32Register, psOperand->ui32CompMask, &psContext->psShader->sInfo, &psOut))
		{
			if( psOut->eComponentType == INOUT_COMPONENT_UINT32)
			{
				return SVT_UINT;
			}
			else if( psOut->eComponentType == INOUT_COMPONENT_SINT32)
			{
				return SVT_INT;
			}
		}
	}
	else if(psOperand->eType == OPERAND_TYPE_INPUT)
	{
		const uint32_t ui32Register = psOperand->aui32ArraySizes[psOperand->iIndexDims-1];
		InOutSignature* psIn;

		if(GetInputSignatureFromRegister(ui32Register, &psContext->psShader->sInfo, &psIn))
		{
			if( psIn->eComponentType == INOUT_COMPONENT_UINT32)
			{
				return SVT_UINT;
			}
			else if( psIn->eComponentType == INOUT_COMPONENT_SINT32)
			{
				return SVT_INT;
			}
		}
	}
	else if(psOperand->eType == OPERAND_TYPE_CONSTANT_BUFFER)
	{
        ConstantBuffer* psCBuf = NULL;
        ShaderVar* psVar = NULL;
        int32_t index = -1;
		int foundVar;
        GetConstantBufferFromBindingPoint(psOperand->aui32ArraySizes[0], &psContext->psShader->sInfo, &psCBuf);
		foundVar = GetShaderVarFromOffset(psOperand->aui32ArraySizes[1], psOperand->aui32Swizzle, psCBuf, &psVar, &index);
		if(foundVar && index == -1 && psOperand->psSubOperand[1] == NULL)
		{
			return psVar->sType.Type;
		}
	}
	else if(psOperand->eType == OPERAND_TYPE_IMMEDIATE32)
	{
		return psOperand->iIntegerImmediate ? SVT_INT : SVT_FLOAT;
	}
    return SVT_FLOAT;
}