Page 1 of 1

vu1_triangle

Posted: Fri Apr 22, 2005 8:46 am
by denver
Hello,
observing the code included from vu1_triangle (main.c), there is a while(1) which in each iteration, a variable called final_matrix is uploaded to VU1mem, a triangle prim (packed into a GIF_TAG) is uploaded to VU1mem and finally VIF_NOP-VIF_MSCAL are sent to VIF1.

Now, the question is: why the demo doesn't work fine (the triangle isnt drawn) when i upload the triangle prim just before the while(1) and not in each iteration?

Considering the triangle prim is the same at all iterations, i upload it before the while(1) and not uploading it into the while(1) with the intention to save cycles.

It seems that after each iteration (more in particular, after the execution of the vu-program), the VU1mem is cleared and all the data lost.

Thats my code:

Code: Select all


    ///////////////////////////////////////////////////////////////////////////
    // Add giftag and color of the triangle

    *((u64*)p_data)++ = DMA_CNT_TAG( 5 );
    *((u32*)p_data)++ = VIF_CODE( VIF_STCYL,0,0x0404 );
    *((u32*)p_data)++ = VIF_CODE( VIF_UNPACK_V4_32,5,4 );

    *((u64*)p_data)++ = GIF_TAG( 1, 1, 1, GS_SETREG_PRIM( GS_PRIM_PRIM_TRIANGLE,
                                          0, 0, 0, 0, 0, 0, 0, 0 ), 0, 4 );
    *((u64*)p_data)++ = 0x5551;

    *((u32*)p_data)++  = 127;
    *((u32*)p_data)++  = 127;
    *((u32*)p_data)++  = 127;
    *((u32*)p_data)++  = 0;

    ///////////////////////////////////////////////////////////////////////////
    // add vertex coords of the triangle

    *((float*)p_data)++ = -100.0f;
    *((float*)p_data)++ =  100.0f;
    *((float*)p_data)++ =    0.0f;
    *((float*)p_data)++ =    1.0f;

    *((float*)p_data)++ = -100.0f;
    *((float*)p_data)++ = -100.0f;
    *((float*)p_data)++ =    0.0f;
    *((float*)p_data)++ =    1.0f;

    *((float*)p_data)++ =   50.0f;
    *((float*)p_data)++ =   50.0f;
    *((float*)p_data)++ =  100.0f;
    *((float*)p_data)++ =    1.0f;

  /////////////////////////////////////////////////////////////////////////////
  // Loop of the demo

  while( 1 )
  {
    angle += 0.03f;

    PbScreenClear&#40; 30<<16|20<<8|40 &#41;;

    ///////////////////////////////////////////////////////////////////////////
    // Rotate & build final matrix to be used in the vu1 program.

    PbMatrixRotateZ&#40; &rotate_matrix, angle &#41;;
    PbMatrixMultiply&#40; &temprot_matrix, &rotate_matrix, &camera_matrix &#41;;
    PbMatrixMultiply&#40; &final_matrix, &temprot_matrix, &viewscreen_matrix &#41;;
    FlushCache&#40;0&#41;;  

    p_data = p_store = PbSprAlloc&#40; 10*16 &#41;;

    ///////////////////////////////////////////////////////////////////////////
    // Build the data we need to send to the vu1

    *&#40;&#40;u64*&#41;p_data&#41;++ = DMA_REF_TAG&#40; &#40;u32&#41;&final_matrix, 4 &#41;;
    *&#40;&#40;u32*&#41;p_data&#41;++ = VIF_CODE&#40; VIF_STCYL,0,0x0404 &#41;;
    *&#40;&#40;u32*&#41;p_data&#41;++ = VIF_CODE&#40; VIF_UNPACK_V4_32,4,0 &#41;;

    ///////////////////////////////////////////////////////////////////////////
    // End the list and start the program

    *&#40;&#40;u64*&#41;p_data&#41;++ = DMA_END_TAG&#40; 0 &#41;;
    *&#40;&#40;u32*&#41;p_data&#41;++ = VIF_CODE&#40; VIF_NOP,0,0 &#41;;
    *&#40;&#40;u32*&#41;p_data&#41;++ = VIF_CODE&#40; VIF_MSCAL,0,0 &#41;;

    PbDmaSend01ChainSpr&#40; p_store &#41;;

    ///////////////////////////////////////////////////////////////////////////
    // Sync and flipscreen

    PbScreenSyncFlip&#40;&#41;;
  &#125;
Thanks in advance

Posted: Fri Apr 22, 2005 5:32 pm
by blackdroid
because p_data is probably pointing no where near from where you want to send from.
and then you do an alloc for each frame, so its going to be overwritten.