/[pcsx2_0.9.7]/trunk/pcsx2/IPU/mpeg2lib/Mpeg.h
ViewVC logotype

Diff of /trunk/pcsx2/IPU/mpeg2lib/Mpeg.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/pcsx2/IPU/mpeg2lib/Mpeg.h	2010/09/07 03:24:11	31
+++ trunk/pcsx2/IPU/mpeg2lib/Mpeg.h	2010/09/07 11:08:22	62
@@ -22,8 +22,52 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#ifndef __MPEG_H__
-#define __MPEG_H__
+#pragma once
+
+#include <xmmintrin.h>
+
+template< typename T >
+__noinline void memzero_sse_a( T& dest )
+{
+#define MZFqwc (sizeof(dest)/16)
+
+	C_ASSERT( (sizeof(dest) & 0xf) == 0 );
+
+	__m128 zeroreg = _mm_setzero_ps();
+
+	float (*destxmm)[4] = (float(*)[4])&dest;
+
+#define StoreDestIdx(idx) case idx: _mm_store_ps(&destxmm[idx][0], zeroreg)
+
+	switch( MZFqwc & 0x07 )
+	{
+		StoreDestIdx(0x07);
+		StoreDestIdx(0x06);
+		StoreDestIdx(0x05);
+		StoreDestIdx(0x04);
+		StoreDestIdx(0x03);
+		StoreDestIdx(0x02);
+		StoreDestIdx(0x01);
+	}
+
+	destxmm += (MZFqwc & 0x07);
+	for( uint i=0; i<MZFqwc / 8; ++i, destxmm+=8 )
+	{
+		_mm_store_ps(&destxmm[0][0], zeroreg);
+		_mm_store_ps(&destxmm[1][0], zeroreg);
+		_mm_store_ps(&destxmm[2][0], zeroreg);
+		_mm_store_ps(&destxmm[3][0], zeroreg);
+		_mm_store_ps(&destxmm[4][0], zeroreg);
+		_mm_store_ps(&destxmm[5][0], zeroreg);
+		_mm_store_ps(&destxmm[6][0], zeroreg);
+		_mm_store_ps(&destxmm[7][0], zeroreg);
+	}
+
+#undef MZFqwc
+};
+
+// the IPU is fixed to 16 byte strides (128-bit / QWC resolution):
+static const uint decoder_stride = 16;
 
 enum macroblock_modes
 {
@@ -64,29 +108,29 @@
 };
 
 struct macroblock_8{
-	unsigned char Y[16][16];	//0
-	unsigned char Cb[8][8];		//1
-	unsigned char Cr[8][8];		//2
+	u8 Y[16][16];		//0
+	u8 Cb[8][8];		//1
+	u8 Cr[8][8];		//2
 };
 
 struct macroblock_16{
-	short Y[16][16];			//0
-	short Cb[8][8];				//1
-	short Cr[8][8];				//2
+	s16 Y[16][16];			//0
+	s16 Cb[8][8];			//1
+	s16 Cr[8][8];			//2
 };
 
 struct macroblock_rgb32{
 	struct {
-		unsigned char r, g, b, a;
+		u8 r, g, b, a;
 	} c[16][16];
 };
 
-struct rgb16{
-	unsigned short r:5, g:5, b:5, a:1;
+struct rgb16_t{
+	u16 r:5, g:5, b:5, a:1;
 };
 
 struct macroblock_rgb16{
-	struct rgb16	c[16][16];
+	rgb16_t	c[16][16];
 };
 
 struct decoder_t {
@@ -96,30 +140,26 @@
 	/* DCT coefficients - should be kept aligned ! */
 	s16 DCTblock[64];
 
-	/* bit parsing stuff */
-	u32 bitstream_buf;		/* current 32 bit working set */
-	int bitstream_bits;			/* used bits in working set */
-	u8 * bitstream_ptr;			/* buffer with stream data; 128 bits buffer */
+	u8 niq[64];			//non-intraquant matrix (sequence header)
+	u8 iq[64];			//intraquant matrix (sequence header)
 
-	struct macroblock_8		*mb8;
-	struct macroblock_16	*mb16;
-	struct macroblock_rgb32	*rgb32;
-	struct macroblock_rgb16	*rgb16;
+	macroblock_8 mb8;
+	macroblock_16 mb16;
+	macroblock_rgb32 rgb32;
+	macroblock_rgb16 rgb16;
 
-	int stride;
+	uint ipu0_data;
+	uint ipu0_idx;
 
-	/* predictor for DC coefficients in intra blocks */
-	s16 dc_dct_pred[3];
+	/* bit parsing stuff */
+	u32 bitstream_buf;		/* current 32 bit working set */
+	int bitstream_bits;			/* used bits in working set */
 
 	int quantizer_scale;	/* remove */
 	int dmv_offset;		/* remove */
 
 	/* now non-slice-specific information */
 
-	/* sequence header stuff */
-	u8 *intra_quantizer_matrix;
-	u8 *non_intra_quantizer_matrix;
-
 	/* picture header stuff */
 
 	/* what type of picture this is (I, P, B, D) */
@@ -127,6 +167,9 @@
 
 	/* picture coding extension stuff */
 
+	/* predictor for DC coefficients in intra blocks */
+	s16 dc_dct_pred[3];
+
 	/* quantization factor for intra dc coefficients */
 	int intra_dc_precision;
 	/* top/bottom/both fields */
@@ -159,39 +202,65 @@
 
 	/* stuff derived from bitstream */
 
-	/* pointer to the zigzag scan we're supposed to be using */
-	const u8 * scan;
+	/* the zigzag scan we're supposed to be using, true for alt, false for normal */
+	bool scantype;
 
 	int second_field;
 
 	int mpeg1;
+
+	template< typename T >
+	void SetOutputTo( T& obj )
+	{
+		uint mb_offset = ((uptr)&obj - (uptr)&mb8);
+		pxAssume( (mb_offset & 15) == 0 );
+		ipu0_idx	= mb_offset / 16;
+		ipu0_data	= sizeof(obj)/16;
+	}
+
+	u128* GetIpuDataPtr()
+	{
+		return ((u128*)&mb8) + ipu0_idx;
+	}
+	
+	void AdvanceIpuDataBy(uint amt)
+	{
+		pxAssumeDev(ipu0_data>=amt, "IPU FIFO Overflow on advance!" );
+		ipu0_idx += amt;
+		ipu0_data -= amt;
+	}
+	
+	bool ReadIpuData(u128* out);
+};
+
+struct mpeg2_scan_pack
+{
+	u8 norm[64];
+	u8 alt[64];
+
+	mpeg2_scan_pack();
 };
 
-extern void (__fastcall *mpeg2_idct_copy) (s16 * block, u8* dest, int stride);
-extern void (__fastcall *mpeg2_idct_add) (int last, s16 * block, s16* dest, int stride);
+extern void mpeg2_idct_copy(s16 * block, u8* dest, int stride);
+extern void mpeg2_idct_add(int last, s16 * block, s16* dest, int stride);
 
 #define IDEC	0
 #define BDEC	1
 
-void mpeg2sliceIDEC(void* pdone);
-void mpeg2_slice(void* pdone);
-int get_macroblock_address_increment(decoder_t * const decoder);
-int get_macroblock_modes (decoder_t * const decoder);
-
-extern int get_motion_delta (decoder_t * const decoder, const int f_code);
-extern int get_dmv (decoder_t * const decoder);
-
-extern int non_linear_quantizer_scale[];
-extern decoder_t g_decoder;
-
-void __fastcall ipu_csc(macroblock_8 *mb8, macroblock_rgb32 *rgb32, int sgn);
-void __fastcall ipu_dither(const macroblock_rgb32* rgb32, macroblock_rgb16 *rgb16, int dte);
-void __fastcall ipu_vq(macroblock_rgb16 *rgb16, u8* indx4);
-void __fastcall ipu_copy(const macroblock_8 *mb8, macroblock_16 *mb16);
-
-int slice (decoder_t * const decoder, u8 * buffer);
-/* idct.c */
-void mpeg2_idct_init ();
+extern bool mpeg2sliceIDEC();
+extern bool mpeg2_slice();
+extern int get_macroblock_address_increment();
+extern int get_macroblock_modes();
+
+extern int get_motion_delta(const int f_code);
+extern int get_dmv();
+
+extern void ipu_csc(macroblock_8& mb8, macroblock_rgb32& rgb32, int sgn);
+extern void ipu_dither(const macroblock_rgb32& rgb32, macroblock_rgb16& rgb16, int dte);
+extern void ipu_vq(macroblock_rgb16& rgb16, u8* indx4);
+extern void ipu_copy(const macroblock_8& mb8, macroblock_16& mb16);
+
+extern int slice (u8 * buffer);
 
 #ifdef _MSC_VER
 #define BigEndian(out, in) out = _byteswap_ulong(in)
@@ -199,4 +268,18 @@
 #define BigEndian(out, in) out = __builtin_bswap32(in) // or we could use the asm function bswap...
 #endif
 
-#endif//__MPEG_H__
+#ifdef _MSC_VER
+#define BigEndian64(out, in) out = _byteswap_uint64(in)
+#else
+#define BigEndian64(out, in) out = __builtin_bswap64(in) // or we could use the asm function bswap...
+#endif
+
+extern __aligned16 const mpeg2_scan_pack mpeg2_scan;
+extern const int non_linear_quantizer_scale[];
+
+// The IPU can only do one task at once and never uses other buffers so all mpeg state variables
+// are made available to mpeg/vlc modules as globals here:
+
+extern __aligned16 tIPU_BP g_BP;
+extern __aligned16 decoder_t decoder;
+

 

  ViewVC Help
Powered by ViewVC 1.1.22