Beispiel #1
0
//================================================================================================
bool DXShader11::tryLoadBinThenCompile(LPCWSTR pSrcFile, 
									   LPCSTR pFuncName,
									   const D3D_SHADER_MACRO * pDefines)
{
	//First try loading from bin
	DAnsiStr strBinFile;
	strBinFile.copyFromW(pSrcFile);
	strBinFile =  PS::FILESTRINGUTILS::ChangeFileExt(strBinFile, DAnsiStr(".bin"));

	if(loadFromBinary(strBinFile.ptr())	)
		return true;

	//Could not find bin so try compiling the HLSL code and save bin afterwards.
	HRESULT res = compile(pSrcFile, pFuncName, pDefines, true);	
	return SUCCEEDED(res);
}
int SaveArrayCSV(const char* lpArrayName, float* lpArray, U32 count)
{

	DAnsiStr strPath = ExtractFilePath(GetExePath());
	DAnsiStr strFP = printToAStr("%s/%s", strPath.ptr(), lpArrayName);
	DAnsiStr strLine;
	for(int i=0; i<count; i++)
	{
		if(i < count - 1)
			strLine += printToAStr("%f, ", lpArray[i]);
		else
			strLine += printToAStr("%f", lpArray[i]);
	}

	WriteTextFile(strFP, strLine);
	return count;
}
Beispiel #3
0
int SimdPoly::linearizeBlobTree(CBlobNode* root, int parentID, int& outIsOperator)
{
    int curID = -1;
    if(parentID == -1)
    {
        vec3f lo = root->getOctree().lower;
        vec3f hi = root->getOctree().upper;
        m_blobPrims.bboxLo = svec3f(lo.x, lo.y, lo.z);
        m_blobPrims.bboxHi = svec3f(hi.x, hi.y, hi.z);

        //Set identity matrix
        float identity[] = {1.0f, 0.0f, 0.0f, 0.0f,
                            0.0f, 1.0f, 0.0f, 0.0f,
                            0.0f, 0.0f, 1.0f, 0.0f,
                            0.0f, 0.0f, 0.0f, 1.0f};

        m_blobPrimMatrices.count = 1;
        m_blobBoxMatrices.count = 1;
        for(U32 i=0; i<PRIM_MATRIX_STRIDE; i++)
            m_blobPrimMatrices.matrix[i] = identity[i];
        for(U32 i=0; i<BOX_MATRIX_STRIDE; i++)
            m_blobBoxMatrices.matrix[i] = identity[i];
    }

    //Operator
    outIsOperator = root->isOperator();
    if(outIsOperator)
    {
        if(m_blobOps.ctOps >= MAX_TREE_NODES)
        {
            ReportError("Exceeded maximum number of allowed Operators");
            FlushAllErrors();
            return PS_ERROR_OPERATOR_OVERFLOW;
        }

        curID = m_blobOps.ctOps;
        m_blobOps.ctOps++;
        m_blobOps.opType[curID] = root->getNodeType();

        if(root->countChildren() != 2)
        {
            ReportError("Not a binary Operator!");
            FlushAllErrors();
            return PS_ERROR_NON_BINARY_OP;
        }

        int isOp[2];
        int kidID[2];
        kidID[0] = this->linearizeBlobTree(root->getChild(0), curID, isOp[0]);
        kidID[1] = this->linearizeBlobTree(root->getChild(1), curID, isOp[1]);
        m_blobOps.opLeftChild[curID]  = kidID[0];
        m_blobOps.opRightChild[curID] = kidID[1];
        m_blobOps.opChildKind[curID]  = isOp[0]*2 + isOp[1];

        vec3f lo = root->getOctree().lower;
        vec3f hi = root->getOctree().upper;
        //ReadBox from BlobTree
        m_blobOps.vBoxLoX[curID] = lo.x;
        m_blobOps.vBoxLoY[curID] = lo.y;
        m_blobOps.vBoxLoZ[curID] = lo.z;

        m_blobOps.vBoxHiX[curID] = hi.x;
        m_blobOps.vBoxHiY[curID] = hi.y;
        m_blobOps.vBoxHiZ[curID] = hi.z;


        switch(root->getNodeType())
        {
        case(bntOpPCM):
        {
            CPcm* lpPCM = reinterpret_cast<CPcm*>(root);
            m_blobOps.resX[curID] = lpPCM->getPropagateLeft();
            m_blobOps.resY[curID] = lpPCM->getPropagateRight();
            m_blobOps.resZ[curID] = lpPCM->getAlphaLeft();
            m_blobOps.resW[curID] = lpPCM->getAlphaRight();
        }
            break;
        case(bntOpRicciBlend):
        {
            CRicciBlend* ricci = reinterpret_cast<CRicciBlend*>(root);
            float n = ricci->getN();
            m_blobOps.resX[curID] = n;
            if(n != 0.0f)
                m_blobOps.resY[curID] = 1.0f / n;
        }
            break;
        case(bntOpWarpTwist):
        {
            CWarpTwist* twist = reinterpret_cast<CWarpTwist*>(root);
            m_blobOps.resX[curID] = twist->getWarpFactor();
            m_blobOps.resY[curID] = static_cast<float>(twist->getMajorAxis());
        }
            break;
        case(bntOpWarpTaper):
        {
            CWarpTaper* taper = reinterpret_cast<CWarpTaper*>(root);
            m_blobOps.resX[curID] = taper->getWarpFactor();
            m_blobOps.resY[curID] = static_cast<float>(taper->getAxisAlong());
            m_blobOps.resZ[curID] = static_cast<float>(taper->getAxisTaper());
        }
            break;
        case(bntOpWarpBend):
        {
            CWarpBend* bend = reinterpret_cast<CWarpBend*>(root);
            m_blobOps.resX[curID] = bend->getBendRate();
            m_blobOps.resY[curID] = bend->getBendCenter();
            m_blobOps.resZ[curID] = bend->getBendRegion().left;
            m_blobOps.resW[curID] = bend->getBendRegion().right;
        }
            break;
        case(bntOpWarpShear):
        {
            CWarpShear* shear = reinterpret_cast<CWarpShear*>(root);
            m_blobOps.resX[curID] = shear->getWarpFactor();
            m_blobOps.resY[curID] = static_cast<float>(shear->getAxisAlong());
            m_blobOps.resZ[curID] = static_cast<float>(shear->getAxisDependent());
        }
            break;
        }

        return curID;
    }
    else
    {
        if(m_blobPrims.ctPrims >= MAX_TREE_NODES)
        {
            ReportError("Exceeded maximum number of allowed primitives");
            FlushAllErrors();
            return PS_ERROR_PRIM_OVERFLOW;
        }

        curID = m_blobPrims.ctPrims;
        m_blobPrims.ctPrims++;

        //
        vec4f d = root->getMaterial().diffused;
        m_blobPrims.colorX[curID] = d.x;
        m_blobPrims.colorY[curID] = d.y;
        m_blobPrims.colorZ[curID] = d.z;

        vec3f lo = root->getOctree().lower;
        vec3f hi = root->getOctree().upper;

        //ReadBox from BlobTree
        m_blobPrims.vPrimBoxLoX[curID] = lo.x;
        m_blobPrims.vPrimBoxLoY[curID] = lo.y;
        m_blobPrims.vPrimBoxLoZ[curID] = lo.z;

        m_blobPrims.vPrimBoxHiX[curID] = hi.x;
        m_blobPrims.vPrimBoxHiY[curID] = hi.y;
        m_blobPrims.vPrimBoxHiZ[curID] = hi.z;

        CMatrix mtxBackward = root->getTransform().getBackwardMatrix();
        if(mtxBackward.isIdentity())
        {
            m_blobPrims.idxMatrix[curID] = 0;
        }
        else
        {
            int idxMat = m_blobPrimMatrices.count;
            m_blobPrims.idxMatrix[curID] = idxMat;
            idxMat *= PRIM_MATRIX_STRIDE;

            float row[16];
            mtxBackward.getRow(&row[0], 0);
            mtxBackward.getRow(&row[4], 1);
            mtxBackward.getRow(&row[8], 2);
            mtxBackward.getRow(&row[12], 3);

            for(int i=0; i<PRIM_MATRIX_STRIDE; i++)
                m_blobPrimMatrices.matrix[idxMat + i] = row[i];
            m_blobPrimMatrices.count++;
        }

        m_blobPrims.skeletType[curID] = root->getNodeType();

        switch(root->getNodeType())
        {
        case(bntPrimPoint):
        {
            CSkeletonPrimitive *sprim = reinterpret_cast<CSkeletonPrimitive*>(root);
            CSkeletonPoint* skeletPoint = reinterpret_cast<CSkeletonPoint*>(sprim->getSkeleton());
            vec3f pos = skeletPoint->getPosition();

            m_blobPrims.posX[curID] = pos.x;
            m_blobPrims.posY[curID] = pos.y;
            m_blobPrims.posZ[curID] = pos.z;
        }
            break;
        case(bntPrimLine):
        {
            CSkeletonPrimitive *sprim = reinterpret_cast<CSkeletonPrimitive*>(root);
            CSkeletonLine* skeletLine = reinterpret_cast<CSkeletonLine*>(sprim->getSkeleton());
            //cfg->writeVec3f(strNodeName, "start", skeletLine->getStartPosition());
            //cfg->writeVec3f(strNodeName, "end", skeletLine->getEndPosition());
            vec3f s = skeletLine->getStartPosition();
            vec3f e = skeletLine->getEndPosition();

            m_blobPrims.posX[curID] = s.x;
            m_blobPrims.posY[curID] = s.y;
            m_blobPrims.posZ[curID] = s.z;
            m_blobPrims.dirX[curID] = e.x;
            m_blobPrims.dirY[curID] = e.y;
            m_blobPrims.dirZ[curID] = e.z;
        }
            break;
        case(bntPrimRing):
        {
            CSkeletonPrimitive *sprim = reinterpret_cast<CSkeletonPrimitive*>(root);
            CSkeletonRing* skeletRing = reinterpret_cast<CSkeletonRing*>(sprim->getSkeleton());
            //cfg->writeVec3f(strNodeName, "position", skeletRing->getPosition());
            //cfg->writeVec3f(strNodeName, "direction", skeletRing->getDirection());
            //cfg->writeFloat(strNodeName, "radius", skeletRing->getRadius());
            vec3f p = skeletRing->getPosition();
            vec3f d = skeletRing->getDirection();
            float r = skeletRing->getRadius();

            m_blobPrims.posX[curID] = p.x;
            m_blobPrims.posY[curID] = p.y;
            m_blobPrims.posZ[curID] = p.z;
            m_blobPrims.dirX[curID] = d.x;
            m_blobPrims.dirY[curID] = d.y;
            m_blobPrims.dirZ[curID] = d.z;
            m_blobPrims.resX[curID] = r;
            m_blobPrims.resY[curID] = r*r;

        }
            break;
        case(bntPrimDisc):
        {
            CSkeletonPrimitive *sprim = reinterpret_cast<CSkeletonPrimitive*>(root);
            CSkeletonDisc* skeletDisc = reinterpret_cast<CSkeletonDisc*>(sprim->getSkeleton());
            //cfg->writeVec3f(strNodeName, "position", skeletDisc->getPosition());
            //cfg->writeVec3f(strNodeName, "direction", skeletDisc->getDirection());
            //cfg->writeFloat(strNodeName, "radius", skeletDisc->getRadius());
            vec3f p = skeletDisc->getPosition();
            vec3f d = skeletDisc->getDirection();
            float r = skeletDisc->getRadius();
            m_blobPrims.posX[curID] = p.x;
            m_blobPrims.posY[curID] = p.y;
            m_blobPrims.posZ[curID] = p.z;
            m_blobPrims.dirX[curID] = d.x;
            m_blobPrims.dirY[curID] = d.y;
            m_blobPrims.dirZ[curID] = d.z;
            m_blobPrims.resX[curID] = r;
            m_blobPrims.resY[curID] = r*r;
        }
            break;
        case(bntPrimCylinder):
        {
            CSkeletonPrimitive *sprim = reinterpret_cast<CSkeletonPrimitive*>(root);
            CSkeletonCylinder* skeletCyl = reinterpret_cast<CSkeletonCylinder*>(sprim->getSkeleton());
            //cfg->writeVec3f(strNodeName, "position", skeletCyl->getPosition());
            //cfg->writeVec3f(strNodeName, "direction", skeletCyl->getDirection());
            //cfg->writeFloat(strNodeName, "radius", skeletCyl->getRadius());
            //cfg->writeFloat(strNodeName, "height", skeletCyl->getHeight());
            vec3f p = skeletCyl->getPosition();
            vec3f d = skeletCyl->getDirection();
            m_blobPrims.posX[curID] = p.x;
            m_blobPrims.posY[curID] = p.y;
            m_blobPrims.posZ[curID] = p.z;
            m_blobPrims.dirX[curID] = d.x;
            m_blobPrims.dirY[curID] = d.y;
            m_blobPrims.dirZ[curID] = d.z;
            m_blobPrims.resX[curID] = skeletCyl->getRadius();
            m_blobPrims.resY[curID] = skeletCyl->getHeight();
        }
            break;

        case(bntPrimCube):
        {
            CSkeletonPrimitive *sprim = reinterpret_cast<CSkeletonPrimitive*>(root);
            CSkeletonCube* skeletCube = reinterpret_cast<CSkeletonCube*>(sprim->getSkeleton());
            //cfg->writeVec3f(strNodeName, "position", skeletCube->getPosition());
            //cfg->writeFloat(strNodeName, "side", skeletCube->getSide());
            vec3f p = skeletCube->getPosition();
            float side = skeletCube->getSide();
            m_blobPrims.posX[curID] = p.x;
            m_blobPrims.posY[curID] = p.y;
            m_blobPrims.posZ[curID] = p.z;
            m_blobPrims.resX[curID] = side;

        }
            break;
        case(bntPrimTriangle):
        {
            CSkeletonPrimitive *sprim = reinterpret_cast<CSkeletonPrimitive*>(root);
            CSkeletonTriangle* skeletTriangle = reinterpret_cast<CSkeletonTriangle*>(sprim->getSkeleton());
            //cfg->writeVec3f(strNodeName, "corner0", skeletTriangle->getTriangleCorner(0));
            //cfg->writeVec3f(strNodeName, "corner1", skeletTriangle->getTriangleCorner(1));
            //cfg->writeVec3f(strNodeName, "corner2", skeletTriangle->getTriangleCorner(2));
            vec3f p0 = skeletTriangle->getTriangleCorner(0);
            vec3f p1 = skeletTriangle->getTriangleCorner(1);
            vec3f p2 = skeletTriangle->getTriangleCorner(2);
            m_blobPrims.posX[curID] = p0.x;
            m_blobPrims.posY[curID] = p0.y;
            m_blobPrims.posZ[curID] = p0.z;
            m_blobPrims.dirX[curID] = p1.x;
            m_blobPrims.dirY[curID] = p1.y;
            m_blobPrims.dirZ[curID] = p1.z;
            m_blobPrims.resX[curID] = p2.x;
            m_blobPrims.resY[curID] = p2.y;
            m_blobPrims.resX[curID] = p2.z;
        }
            break;
        case(bntPrimNull):
        {
            m_blobPrims.posX[curID] = 0.0f;
            m_blobPrims.posY[curID] = 0.0f;
            m_blobPrims.posZ[curID] = 0.0f;
        }
        break;
        default:
        {
            DAnsiStr strMsg = printToAStr("Primitive %s has not been implemented in compact mode yet!", root->getName().c_str());
            ReportError(strMsg.ptr());
            FlushAllErrors();
        }
        }

        return curID;
    }
}
Beispiel #4
0
HRESULT DXShader11::compile( LPCWSTR pSrcFile, 
							 LPCSTR pFuncName,
							 const D3D_SHADER_MACRO * pDefines,
							 bool bSaveByteCode)
{
	HRESULT hr;
    
	if(!PS::FILESTRINGUTILS::FileExists( pSrcFile))
		return E_FAIL;

    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

    // We generally prefer to use the higher CS shader profile when possible as CS 5.0 is better performance on 11-class hardware
	LPCSTR pProfile = ( m_pDXDevice->getDevice()->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0 ) ? "cs_5_0" : "cs_4_0";

    ID3DBlob* pErrorBlob = NULL;
    ID3DBlob* pBlob = NULL;
	hr = D3DX11CompileFromFile(pSrcFile, pDefines, NULL, pFuncName, pProfile, 
						       dwShaderFlags, NULL, NULL, &pBlob, &pErrorBlob, NULL );
    if ( FAILED(hr) )
    {
        if ( pErrorBlob )
		{
            OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
			ReportError((const char*)pErrorBlob->GetBufferPointer());
		}

        SAFE_RELEASE( pErrorBlob );
        SAFE_RELEASE( pBlob );    

        return hr;
    }    

	hr = m_pDXDevice->getDevice()->CreateComputeShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &m_pComputeShader );
	if(SUCCEEDED(hr))
	{
		m_bCompiled = true;
		if(bSaveByteCode)
		{
			DAnsiStr strBinFile;
			strBinFile.copyFromW(pSrcFile);
			strBinFile =  PS::FILESTRINGUTILS::ChangeFileExt(strBinFile, DAnsiStr(".bin"));
			ofstream ofs(strBinFile.ptr(), ios::out | ios::trunc | ios::binary);
			if(!ofs.is_open())
				return false;

			ofs.write( reinterpret_cast<const char*>(pBlob->GetBufferPointer()), pBlob->GetBufferSize());
			ofs.close();
		}
	}


#if defined(DEBUG) || defined(PROFILE)
	if ( m_pComputeShader )
		(m_pComputeShader)->SetPrivateData( WKPDID_D3DDebugObjectName, lstrlenA(pFuncName), pFuncName);
#endif

    SAFE_RELEASE( pErrorBlob );
    SAFE_RELEASE( pBlob );

    return hr;
}
Beispiel #5
0
	void CPerfTest::runTests()
	{
		if(this->FOnPerformTest == NULL)
			return;

		//count csv file events
		size_t rowoffset = countFileEvents();

		//Some variables 
		TestConfig* pConfig = NULL;		
		CPerfLogger* perf = PS::CPerfLogger::getInstance();


		//Count
		int ctConfigs = (int)m_lstTestConfigs.size();
		int ctFiles = (int)m_lstTestFiles.size();

		//Get TASK Manager
		TaskManager::JobResult arrResult;
		RenderTaskParams param;
		//TaskManager* pTaskManager = TaskManager::getTaskManager();


		DAnsiStr strTestFile; 
		DAnsiStr temp;
		for(int i=0; i < ctConfigs; i++)
		{
			pConfig = dynamic_cast<TestConfig*>(m_lstTestConfigs[i]);

			//Run all files with pConfig
			for(int j=0; j < ctFiles; j++)
			{			
				strTestFile = m_lstTestFiles[j];
				temp = PS::FILESTRINGUTILS::ExtractFileName(strTestFile);			

				//Output some progress status
				if(FOnOverallProgress)
					FOnOverallProgress(temp.ptr(), static_cast<float>(i * ctFiles + j) / static_cast<float>(ctConfigs * ctFiles) );

				//Control all performance outputs				
				if(FOnPerformTest)
				{
					param.strPathFileName = strTestFile;
					param.lpConfig        = pConfig;
					FOnPerformTest(&param);
					//pTaskManager->dispatch(&arrResult, TaskManager::JobFunction(FOnPerformTest), &param);
				}

				//FOnPerformTest(strTestFile.ptr(), *pConfig);
				//pTaskManager->wait(&arrResult);

				//Store test result
				storeTestResult(strTestFile, pConfig, perf, rowoffset);

				//Clear Performance
				perf->cleanup();
			}
		}

		//Write Final CSV file
		this->writeCSV();
	}