コード例 #1
0
ファイル: shaders.cpp プロジェクト: NoSuchProcess/openswr
void VertexFuncSmoothSphereMapAOS(
    const VERTEXINPUT &in,
    VERTEXOUTPUT &out)
{
    const FLOAT *pWorldMat = (FLOAT *)in.pConstants;
    const FLOAT *pLightPos = (FLOAT *)in.pConstants + CONST_OFFSET_LIGHT_POSITION;

    Mat4Vec3Multiply(out.pVertices, pWorldMat, (FLOAT *)in.pAttribs);

    // Transform normals in attrib buffer by world matrix.
    OSALIGNLINE(FLOAT) normals[4];
    Mat4Vec3Multiply(&normals[0], pWorldMat, &in.pAttribs[SHADER_INPUT_SLOT_NORMAL]);

    // Normalize normals
    __m128 normal = Vec3Normalize(&normals[0]);

    __m128 lightPos = _mm_load_ps(pLightPos);
    __m128 lightDir = _mm_load_ps(in.pAttribs);

    // Compute a light direction vector for each vertex.
    //     lightDir = Normalize(lightPos - vertexPos)
    lightDir = _mm_sub_ps(lightPos, lightDir);
    lightDir = Vec3Normalize(lightDir);

    __m128 ndotl0 = Vec3Diffuse(normal, lightDir);

    _mm_store_ps(&out.pAttribs[0], _mm_load_ps(&in.pAttribs[0]));

    _mm_store_ss(&out.pAttribs[0x2], ndotl0);
}
コード例 #2
0
ファイル: threads.cpp プロジェクト: daniel-schuermann/mesa
//////////////////////////////////////////////////////////////////////////
/// @brief Update client stats.
INLINE void UpdateClientStats(SWR_CONTEXT* pContext, uint32_t workerId, DRAW_CONTEXT* pDC)
{
    if ((pContext->pfnUpdateStats == nullptr) || (GetApiState(pDC).enableStatsBE == false))
    {
        return;
    }

    DRAW_DYNAMIC_STATE& dynState = pDC->dynState;
    OSALIGNLINE(SWR_STATS) stats{ 0 };

    // Sum up stats across all workers before sending to client.
    for (uint32_t i = 0; i < pContext->NumWorkerThreads; ++i)
    {
        stats.DepthPassCount += dynState.pStats[i].DepthPassCount;

        stats.PsInvocations  += dynState.pStats[i].PsInvocations;
        stats.CsInvocations  += dynState.pStats[i].CsInvocations;
    }


    pContext->pfnUpdateStats(GetPrivateState(pDC), &stats);
}
コード例 #3
0
ファイル: shaders.cpp プロジェクト: NoSuchProcess/openswr
void GLVSLightShader(
    const VERTEXINPUT &in,
    VERTEXOUTPUT &out)
{
    // output description
    const UINT FRONT_COLOR = 0;
    const UINT BACK_COLOR = 4;

    // compute position
    const FLOAT *pConstants = (FLOAT *)in.pConstants;
    const FLOAT *pMVP = &pConstants[GLVSLightConstants::MVP_MATRIX];
    Mat4Vec3Multiply(out.pVertices, pMVP, (FLOAT *)&in.pAttribs[SHADER_INPUT_SLOT_POSITION]);

    // Transform normals in attrib buffer by normal matrix.
    OSALIGNLINE(FLOAT) normals[4];
    Mat4Vec3Multiply(&normals[0], &pConstants[GLVSLightConstants::MV_MATRIX], &in.pAttribs[SHADER_INPUT_SLOT_NORMAL]);

    // Normalize normals
    //__m128 vNormal		= Vec3Normalize(&normals[0]);
    __m128 vNormal = _mm_load_ps(&normals[0]);

    // normalize light
    __m128 vLightDir = _mm_load_ps(&pConstants[GLVSLightConstants::LIGHT0_POS]);
    vLightDir = Vec3Normalize(vLightDir);

    // nDotL and clamp
    __m128 vNdotL0 = Vec3Diffuse(vNormal, vLightDir);

    // light diffuse * nDotL
    __m128 vLightDiffuse = _mm_load_ps(&pConstants[GLVSLightConstants::LIGHT0_DIFFUSE]);
    vLightDiffuse = _mm_mul_ps(vLightDiffuse, vNdotL0);

    // front color = front scene color + light_ambient * front_mat_ambient + light_diffuse * front_mat_diffuse;
    __m128 vFrontColor = _mm_load_ps(&pConstants[GLVSLightConstants::FRONT_SCENE_COLOR]);
    vFrontColor = _mm_add_ps(vFrontColor, _mm_mul_ps(vLightDiffuse, _mm_load_ps(&pConstants[GLVSLightConstants::FRONT_MAT_DIFFUSE])));
    __m128 vAmbient = _mm_mul_ps(_mm_load_ps(&pConstants[GLVSLightConstants::LIGHT0_AMBIENT]), _mm_load_ps(&pConstants[GLVSLightConstants::FRONT_MAT_AMBIENT]));
    vFrontColor = _mm_add_ps(vFrontColor, vAmbient);

    // clamp to 0..1
    vFrontColor = _mm_max_ps(vFrontColor, _mm_setzero_ps());
    vFrontColor = _mm_min_ps(vFrontColor, _mm_set1_ps(1.0));

    // store front color
    _mm_store_ps(&out.pAttribs[FRONT_COLOR], vFrontColor);

#if 1
    // back color
    // invert normal
    vNormal = _mm_mul_ps(vNormal, _mm_set1_ps(-1.0));

    // nDotL and clamp
    vNdotL0 = Vec3Diffuse(vNormal, vLightDir);

    // light diffuse * nDotL
    vLightDiffuse = _mm_load_ps(&pConstants[GLVSLightConstants::LIGHT0_DIFFUSE]);
    vLightDiffuse = _mm_mul_ps(vLightDiffuse, vNdotL0);

    // back color = back scene color + light_ambient * back_mat_ambient + light_diffuse * back_mat_diffuse;
    __m128 vBackColor = _mm_load_ps(&pConstants[GLVSLightConstants::BACK_SCENE_COLOR]);
    vBackColor = _mm_add_ps(vBackColor, _mm_mul_ps(vLightDiffuse, _mm_load_ps(&pConstants[GLVSLightConstants::BACK_MAT_DIFFUSE])));
    vAmbient = _mm_mul_ps(_mm_load_ps(&pConstants[GLVSLightConstants::LIGHT0_AMBIENT]), _mm_load_ps(&pConstants[GLVSLightConstants::BACK_MAT_AMBIENT]));
    vBackColor = _mm_add_ps(vBackColor, vAmbient);

    // clamp 0..1
    vBackColor = _mm_max_ps(vBackColor, _mm_setzero_ps());
    vBackColor = _mm_min_ps(vBackColor, _mm_set1_ps(1.0));

    // store back color
    _mm_store_ps(&out.pAttribs[BACK_COLOR], vBackColor);
#endif
}