Adam Hines

I have an application that draws a large number of point sprites on the screen using DrawUserPrimatives using additive blending. This works fine on the windows version, with around 4 million point sprites being rendered.

On the XBOX, when there are greater than around 20,000 sprites nothing draws and then the program exits with code 0 and no error messages. Any insight into what I'm doing wrong

-Adam

Here is the relevant shader code:

texture Texture;
float4x4 WorldViewProjection;
float alpha;

sampler TextureSampler =
sampler_state
{
Texture = <Texture>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};

struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Color : COLOR0;
float2 TextureUV : TEXCOORD0;
float1 Size : PSIZE;
};

VS_OUTPUT PointSpriteVS
(
float4 Position : POSITION,
float3 Normal : NORMAL,
float4 Color : COLOR0,
float2 TexCoord0 : TEXCOORD0,
float1 Size : PSIZE
)
{
VS_OUTPUT Output;

Output.Position = mul(Position, WorldViewProjection);
Output.Color = Color;
Output.TextureUV = TexCoord0;
Output.Size = Size;

return Output;
}

struct PS_OUTPUT
{
float4 Color : COLOR0;
};

PS_OUTPUT PointSpritePS
(
float4 Color : COLOR0,
#ifdef XBOX
float4 TextureUV : SPRITETEXCOORD
#else
float2 TextureUV : TEXCOORD0
#endif
)
{
PS_OUTPUT Output;

#ifdef XBOX
TextureUV.xy = abs(TextureUV.zw);
#endif

Output.Color.rgb = Color.rgb;
Output.Color.a = alpha*tex2D(TextureSampler, TextureUV.xy).a;
return Output;
}

technique PointSprite
{
pass P0
{
PointSpriteEnable = true;
AlphaBlendEnable = true;
SrcBlend = SrcAlpha;
DestBlend = ONE;
ZWriteEnable = false;

VertexShader = compile vs_1_1 PointSpriteVS();
#ifdef XBOX
PixelShader = compile ps_3_0 PointSpritePS();
#else
PixelShader = compile ps_1_1 PointSpritePS();
#endif
}
}



And the VertexFormat is as below:

public struct PointSpriteVertexFormat
{
private Vector3 position;
private float pointSize;
private Color color;

public PointSpriteVertexFormat(Vector3 position, float pointSize, Color color)
{
this.position = position;
this.pointSize = pointSize;
this.color = color;
}

public void Set(Vector3 position, float pointSize, Color color)
{
this.position = position;
this.pointSize = pointSize;
this.color = color;
}

public static VertexElement[] Elements =
{
new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0),
new VertexElement(0, sizeof(float)*3, VertexElementFormat.Single, VertexElementMethod.Default, VertexElementUsage.PointSize, 0),
new VertexElement(0, sizeof(float)*3 + sizeof(float)*1, VertexElementFormat.Color, VertexElementMethod.Default, VertexElementUsage.Color, 0),
};

public static int SizeInBytes = sizeof(float) * (3 + 1 + 4);
}


Re: XNA Framework Point Sprites on XBOX 360 causes crash

Peter D.

Ok this is an easy one. The 360 has 512mb of memory, which is shared with the graphics card. You don't get 256mb for graphics (probably what your PC card has). You are simply over-runnung the allocated graphics memory. As yet I haven't looked into how we partition memory on the 360 when we use XNA. However you have merely run into one of the banes of console programming i.e. the need to actally budget your memory to the megabyte!





Re: XNA Framework Point Sprites on XBOX 360 causes crash

Shawn Hargreaves - MSFT

20,000 vertices is still only 400k, though - that's nowhere near enough to be running out of memory.

How are you drawing these points from the CPU side





Re: XNA Framework Point Sprites on XBOX 360 causes crash

Leaf.

I've just done a point sprite test and it seems to be related to using DrawUserPrimitives(). If I use DrawUserPrimitives() then it falls over at around 20,000 points - in my case it draws for a few frames before crashing back to the XNA Launcher.

If I switch to using a vertex buffer and doing a SetData() every frame then I can draw much more than 20,000 points (like 200,000).

Cheers,
Leaf.






Re: XNA Framework Point Sprites on XBOX 360 causes crash

Shawn Hargreaves - MSFT

Interesting. I bet this is overflowing the internal GPU pushbuffer size. Would you mind filing a connect bug on this to make sure the relevant people see it





Re: XNA Framework Point Sprites on XBOX 360 causes crash

Adam Hines

Sure, I'll do that later tonight when i get home.




Re: XNA Framework Point Sprites on XBOX 360 causes crash

Peter D.

Yep as people actually start to seriously test their creations we will run into a lot more of these memory bugs/limitations.

Shawn. Is there a way to allocate memory from XNA as in what has the GPU/Data ratio been set to when using an XNA project





Re: XNA Framework Point Sprites on XBOX 360 causes crash

Shawn Hargreaves - MSFT

Good question. I'm fairly sure there isn't a fixed allocation split, but I could be wrong about that.





Re: XNA Framework Point Sprites on XBOX 360 causes crash

71M

Hi Leaf,

Could you explain your method for getting around this, preferably with a code snippet Smile

Cheers,

Tim