diff TaskManager/Test/test_render/spe/DrawSpan.cpp @ 200:efd7e4712342 draft

fix run_draw
author gongo@localhost.localdomain
date Mon, 26 Jan 2009 14:27:45 +0900
parents b56fb6ac2fc4
children 1eba8570808c
line wrap: on
line diff
--- a/TaskManager/Test/test_render/spe/DrawSpan.cpp	Mon Jan 26 14:02:45 2009 +0900
+++ b/TaskManager/Test/test_render/spe/DrawSpan.cpp	Mon Jan 26 14:27:45 2009 +0900
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <string.h>
+#include <spu_intrinsics.h>
 #include "DrawSpan.h"
 #include "polygon_pack.h"
 #include "texture.h"
@@ -115,9 +116,20 @@
     float *buf = (float*)smanager->allocate(sizeof(float)*width*height);
     float def = 65535.0f;
 
+#if 1
     for (int i = 0; i < width*height; i++) {
 	buf[i] = def;
     }
+#else 
+    vector float init = {0.0f, 0.0f, 0.0f, 0.0f};
+    vector float defi = {def, def, def, def};
+
+    for (int i = 0; i < width*height; i += 4) {
+	vector float *out = (vector float *)&buf[i];
+
+	*out = spu_add(init, defi);
+    }
+#endif
 
     return buf;
 }
@@ -422,6 +434,143 @@
 	    }
 	}
 
+	for (int t = 0; t < spack->info.size; t++) {	  
+	    span = &spack->span[t];
+
+	    uint32 rgb = 0x0000ff00;
+	    float tex1 = span->tex_x1;
+	    float tex2 = span->tex_x2;
+	    float tey1 = span->tex_y1;
+	    float tey2 = span->tex_y2;
+
+	    /**
+	     * Span が持つ 1 pixel 毎の
+	     * テクスチャの座標
+	     */
+	    int tex_xpos;
+	    int tex_ypos;
+
+	    /**
+	     * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と
+	     * そのブロックのアドレス(MainMemory)
+	     */
+	    int tex_localx;
+	    int tex_localy;
+	    uint32 *tex_addr;
+
+	    int x = span->x;
+	    int y = span->y;
+	    int x_len = span->length_x;
+	    float z = span->start_z;
+	    float zpos = span->end_z;
+
+	    // 座標が [0 .. split_screen_w-1] に入るように x,y を -1
+	    int localx = getLocalX(x-1);
+	    int localy = getLocalY(y-1);
+
+	    if (x_len == 1) {
+		if (x < rangex_start || rangex_end < x) {
+		    continue;
+		}
+
+		flag = 1;
+		tex_xpos = (int)((span->tex_width-1) * tex1);
+		tex_ypos = (int)((span->tex_height-1) * tey1);
+
+		if (zpos < zRow[localx + (rangex*localy)]) {
+		    tex_addr = getTile(tex_xpos, tex_ypos,
+				       span->tex_width, span->tex_addr);
+		    tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
+		    tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
+		    
+		    if (!isAvailableTile(tex_addr)) {
+#  if defined(PROFILE)
+			printf("%d %u start load tile\n",
+			       smanager->get_cpuid(), spu_read_decrementer());
+#  endif
+			set_rgb(tex_addr);
+			smanager->dma_wait(TEX_LOAD);
+#  if defined(PROFILE)
+			printf("%d %u end load tile\n",
+			       smanager->get_cpuid(), spu_read_decrementer());
+#  endif
+			tileNum++;
+		    }
+
+		    rgb = get_rgb(tex_localx, tex_localy, tex_addr);
+
+		    zRow[localx + (rangex*localy)] = zpos;
+		    linebuf[localx + (rangex*localy)] = rgb;
+		}
+	    } else {
+		int js = (x < rangex_start) ? rangex_start - x : 0;
+		int je = (x + x_len > rangex_end) ? rangex_end - x : x_len;
+		float tex_x, tex_y, tex_z;
+
+		for (int j = js; j <= je; j++) {
+		    flag = 1;
+		    localx = getLocalX(x-1+j);
+
+		    tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1);
+
+		    tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1);
+		    tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1);
+		    if (tex_x > 1) tex_x = 1;
+		    if (tex_x < 0) tex_x = 0;
+		    if (tex_y > 1) tex_y = 1;
+		    if (tex_y < 0) tex_y = 0;
+		    tex_xpos = (int)((span->tex_width-1) * tex_x);
+		    tex_ypos = (int)((span->tex_height-1) * tex_y);
+		    
+		    if (tex_z < zRow[localx + (rangex*localy)]) {
+			tex_addr = getTile(tex_xpos, tex_ypos,
+					   span->tex_width, span->tex_addr);
+			tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
+			tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
+
+			/**
+			 * Tile が無い場合、一旦タスクはここで中断し、
+			 * Tile をロードするタスクを走らせた後に再起動する
+			 */
+			if (!isAvailableTile(tex_addr)) {
+			    spack->info.start = t;
+#if 0
+			    set_rgbs(tex_addr,
+				     getTile(span->tex_width-1, tex_ypos,
+					     span->tex_width, span->tex_addr));
+			    //smanager->dma_wait(TEX_LOAD);
+			    reboot(spack, j);
+			    goto FINISH;
+#else
+
+#  if defined(PROFILE)
+			    printf("%d %u start load tile\n",
+				   smanager->get_cpuid(), 
+				   spu_read_decrementer());
+#  endif
+
+			    set_rgb(tex_addr);
+			    smanager->dma_wait(TEX_LOAD);
+			    tileNum++;
+
+#  if defined(PROFILE)
+			    printf("%d %u end load tile\n",
+				   smanager->get_cpuid(),
+				   spu_read_decrementer());
+#  endif
+#endif
+			}
+			
+			rgb = get_rgb(tex_localx, tex_localy, tex_addr);
+
+			zRow[localx + (rangex*localy)] = tex_z;
+			linebuf[localx + (rangex*localy)] = rgb;
+		    }
+		}
+	    }
+	}
+
+
 	smanager->dma_wait(SPAN_PACK_LOAD);
 
 	SpanPackPtr tmp_spack = spack;