Skip to content

Instantly share code, notes, and snippets.

@thatcosmonaut
Created November 5, 2020 06:56
Show Gist options
  • Save thatcosmonaut/7053bb003644eca3571113d745746104 to your computer and use it in GitHub Desktop.
Save thatcosmonaut/7053bb003644eca3571113d745746104 to your computer and use it in GitHub Desktop.
Stress test for FNA dynamic buffer updates using None
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace FuckNone
{
class FuckNoneGame : Game
{
static int BUFFER_SIZE = 8388608;
static int UPDATES_PER_FRAME = 32;
GraphicsDeviceManager graphics;
VertexPositionColorTexture[] vertexData = new VertexPositionColorTexture[BUFFER_SIZE];
DynamicVertexBuffer buffer;
BasicEffect effect;
public FuckNoneGame()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.PreferMultiSampling = true;
Content.RootDirectory = "Content";
Window.AllowUserResizing = true;
IsMouseVisible = true;
var random = new System.Random();
for (var i = 0; i < BUFFER_SIZE; i++)
{
vertexData[i] = new VertexPositionColorTexture(
new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()),
new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 1f),
new Vector2((float)random.NextDouble(), (float)random.NextDouble())
);
}
}
protected override void Initialize()
{
base.Initialize();
buffer = new DynamicVertexBuffer(GraphicsDevice, typeof(VertexPositionColorTexture), BUFFER_SIZE, BufferUsage.None);
buffer.SetData(vertexData, 0, BUFFER_SIZE, SetDataOptions.None);
effect = new BasicEffect(GraphicsDevice);
}
protected override void LoadContent()
{
base.LoadContent();
}
protected override void UnloadContent()
{
base.UnloadContent();
}
protected override void Update(GameTime gameTime)
{
for (var i = 0; i < UPDATES_PER_FRAME; i++)
{
buffer.SetData(vertexData, 0, BUFFER_SIZE, SetDataOptions.None);
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment