• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tape_Worm

[SharpDX] Speed issues when drawing

13 posts in this topic

I'm using SharpDX and Direct3D 11.I 've got 8192 textured (single texture) quads (32768 vertices), each vertex has a Vector4 for position, a Vector2 for texture coordinates, and a Vector4 for color. Every frame I discard my dynamic vertex buffer and refill it (this is just an unrefined stress test) with the vertex data.

It is REALLY slow. Something like 150+ msec for frame delta (~5-6 FPS).

All I'm doing is this:
[code]
Draw()
{
lock_vertex_buffer(discard);
for (int i = 0; i < 8192; i++)
{
Matrix proj_view_world = proj_view * world;
UpdateVertices(proj_view_world);
WriteData();
}
unlock_vertex_buffer();

ImmediateContext.DrawIndexed(8192 * 6, 0, 0);
}
[/code]

And for the record, I'm initializing an index buffer, but I never touch it again.

Now, if I comment out the DrawIndexed, I get ~200FPS (which is comparable to my old DirectX 9 code and that's not much different than this), so that seems to indicate that the bottleneck is in the DrawIndexed method.

I'm really new to the whole Direct3D 11 thing, so can anyone shed any light/advice on this?

Thanks
0

Share this post


Link to post
Share on other sites
[quote name='Tape_Worm' timestamp='1326855562' post='4903871']so that seems to indicate that the bottleneck is in the DrawIndexed method.[/quote]Kinda sorta, but not really.
Without the draw-indexed, then there's no dependency on the dynamic vertex buffer, so your app has no reason to wait for that data to arrive on the GPU.
Also, without the draw-indexed, you're not going to be launching any GPU commands, which means no pixel/vertex shaders will run.

Are your quads visible on the screen?
1

Share this post


Link to post
Share on other sites
Hi,

check your CPU usage too. If it is 100% then you aren't bound by the GPU.


[color=#000000] [/color][color=#000088]for[/color][color=#000000] [/color][color=#666600]([/color][color=#000088]int[/color][color=#000000] i [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]0[/color][color=#666600];[/color][color=#000000] i [/color][color=#666600]<[/color][color=#000000] [/color][color=#006666]8192[/color][color=#666600];[/color][color=#000000] i[/color][color=#666600]++)[/color]
[color=#000000] [/color][color=#666600]{[/color]
[color=#000000] [/color][color=#660066]Matrix[/color][color=#000000] proj_view_world [/color][color=#666600]=[/color][color=#000000] proj_view [/color][color=#666600]*[/color][color=#000000] world[/color][color=#666600];[/color]
[color=#000000] [/color][color=#660066]UpdateVertices[/color][color=#666600]([/color][color=#000000]proj_view_world[/color][color=#666600]);[/color]
[color=#000000] [/color][color=#660066]WriteData[/color][color=#666600]();[/color]
[color=#000000] [/color][color=#666600]}[/color]

What do you do in the "[color=#660066][size=2][left]UpdateVertices"[/left][/size][/color]? Could you consider moving your calculations to GPU instead of performing them on CPU? Probably your GPU is just sitting idle while you perform your updates. You could easily draw 8000 quads with geometry instancing.

Cheers!
0

Share this post


Link to post
Share on other sites
[quote name='Martins Mozeiko' timestamp='1326870815' post='4903900']
How are you locking and unlocking buffer and also how are you writing data to buffer?
[/quote]

Using the Map/Unmap methods. Sorry, the terminology has changed and I'm still stuck in the past.

[quote name='Hodgman' timestamp='1326873663' post='4903911']
[quote name='Tape_Worm' timestamp='1326855562' post='4903871']so that seems to indicate that the bottleneck is in the DrawIndexed method.[/quote]Kinda sorta, but not really.
Without the draw-indexed, then there's no dependency on the dynamic vertex buffer, so your app has no reason to wait for that data to arrive on the GPU.
Also, without the draw-indexed, you're not going to be launching any GPU commands, which means no pixel/vertex shaders will run.

Are your quads visible on the screen?
[/quote]

Yep, they're quite visible. I only mentioned that because I thought maybe the stuff inside the loop (i.e. the transformation math, buffer writing) was causing the issue. They're not.

[quote name='kauna' timestamp='1326879031' post='4903925']
Hi,

check your CPU usage too. If it is 100% then you aren't bound by the GPU.


[color=#000000] [/color][color=#000088]for[/color][color=#000000] [/color][color=#666600]([/color][color=#000088]int[/color][color=#000000] i [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]0[/color][color=#666600];[/color][color=#000000] i [/color][color=#666600]<[/color][color=#000000] [/color][color=#006666]8192[/color][color=#666600];[/color][color=#000000] i[/color][color=#666600]++)[/color]
[color=#000000] [/color][color=#666600]{[/color]
[color=#000000] [/color][color=#660066]Matrix[/color][color=#000000] proj_view_world [/color][color=#666600]=[/color][color=#000000] proj_view [/color][color=#666600]*[/color][color=#000000] world[/color][color=#666600];[/color]
[color=#000000] [/color][color=#660066]UpdateVertices[/color][color=#666600]([/color][color=#000000]proj_view_world[/color][color=#666600]);[/color]
[color=#000000] [/color][color=#660066]WriteData[/color][color=#666600]();[/color]
[color=#000000] [/color][color=#666600]}[/color]

What do you do in the "
[left]UpdateVertices"[/left]
? Could you consider moving your calculations to GPU instead of performing them on CPU? Probably your GPU is just sitting idle while you perform your updates. You could easily draw 8000 quads with geometry instancing.

Cheers!
[/quote]

No, I'm trying to stay away from stuff like instancing for the time being (and seriously, 8000 quads shouldn't be affecting performance like this). No, I don't get 100% CPU. Granted I'm not sure if that's a good indicator or not. It's interesting to note that I put a Sleep(10) in the method that calls Draw() (after it) and I still get the same frame rate, so I'm assuming that means the CPU is free and clear.

I've tried PIX and a profiler, and the profiler doesn't seem to show anything glaring. And I really can't make hide nor hair out of the data pix is presenting me.

Anyway, thanks guys. If you all have any other ideas, that'd be swell.
0

Share this post


Link to post
Share on other sites
How many pixels does each quad cover?

If every quad is covering the entire screen, then that's only 0.018ms per full-screen-quad, which is actually extremely fast. Graphics cards from a few years back will take ~0.5ms to draw a textured quad over an entire "HD" res buffer,
1

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1326891524' post='4903954'] How many pixels does each quad cover? If every quad is covering the entire screen, then that's only 0.018ms per full-screen-quad, which is actually extremely fast. Graphics cards from a few years back will take ~0.5ms to draw a textured quad over an entire "HD" res buffer, [/quote]

I had that thought last night. The screen is 800x600, the quad is 260x260. I resized the quad to 66x66 and it still gave lousy performance, something like 20 FPS if I recall. In my D3D9 app I've got 8192 128x128 textured and alpha blended quads on the screen at ~200 FPS.

I just tried the D3D11 app here at the office, and this thing has a Radeon 4550 which is quite slow (running in 10.1 downlevel mode, not that it matters, I get these issues on my home computer which uses a Direct3D 11 card). With my D3D9 app I got ~22 FPS, with this D3D11 (running in 10.1) I get ~0.15 FPS. Something's not kosher here.

I also updated the code to only fill the vertex buffer one time only, so every time the frame is drawn it just calls DrawIndexed(). Something's just not right here.

Oh, also, this is my vertex/pixel shader for the quads (in case there's something in here that'd be a problem):
[code]
Texture2D theTexture : register(t0);
SamplerState sample : register(s0);

struct VS_IN
{
float4 pos : POSITION;
float4 col : COLOR;
float2 uv : TEXTURECOORD;
};

struct PS_IN
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 uv : TEXTURECOORD;
};

PS_IN VS( VS_IN input )
{
return input;
}

float4 PS( PS_IN input ) : SV_Target
{
return theTexture.Sample(sample, input.uv);
}
[/code]

Yeah, I'm flummoxed.
0

Share this post


Link to post
Share on other sites
Just to keep up to date here:

I've modified my code to use SlimDX and I'm still getting the same issue. Also, I noticed on this machine that the system just chugs when running the application (e.g. the mouse pauses, window events take forever to happen, etc...) and yet, the CPU usage on task manager never climbs above 2-3%. I'm updating the driver on this computer to the latest ATI driver (11.12) to see if it helps any.

... some time passes...

Nope, still lousy performance.

Anyone have any idea why DrawIndexed would give such lousy performance with only 32,768 vertices?
0

Share this post


Link to post
Share on other sites
Hi,

I assume that you enabled the Direct3d debug libraries and studied the output (if any) from the program.

Best regards
0

Share this post


Link to post
Share on other sites
Here's some more ideas:

Is the shader in the D3D11 version more complicated than just doing a texture read?

Try turning alpha testing off in D3D9 (or on in D3D11 by using clip() in the shader). That can have a significant performance impact as it cuts down on the need to blend pixels with the frame buffer. The performance difference will depend on how transparent the texture is, and the card you're testing on.

It's also possible that the D3D9 version is rejecting pixels due to the depth testing or stencil testing. Make sure those are disabled in both cases.
1

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1326910890' post='4904025']
Here's some more ideas:

Is the shader in the D3D11 version more complicated than just doing a texture read?

Try turning alpha testing off in D3D9 (or on in D3D11 by using clip() in the shader). That can have a significant performance impact as it cuts down on the need to blend pixels with the frame buffer. The performance difference will depend on how transparent the texture is, and the card you're testing on.

It's also possible that the D3D9 version is rejecting pixels due to the depth testing or stencil testing. Make sure those are disabled in both cases.
[/quote]

The D3D9 code does not use a shader at all, just fixed function.

I removed alpha testing/blending, and I'm still getting the same results (well, not 100% the same, instead of 22 FPS in the D3D9 version, I'm getting 19 FPS because there's nothing to reject), and the D3D11 version is still horrifically slow. I'm starting to think this is something related to Direct3D 11 in general and/or my ATI drivers (using the latest version 11.12).

[quote name='kauna' timestamp='1326907264' post='4904014']
Hi,

I assume that you enabled the Direct3d debug libraries and studied the output (if any) from the program.

Best regards
[/quote]

Yes, I have, and no there's nothing of consequence being reported.
0

Share this post


Link to post
Share on other sites
You're all brilliant. No one thing was the cause of the problem, however a couple things combined made a huge difference.

So, here's why I'm a dumbass:[list]
[*]Forgot anti-aliasing was still enabled.
[*]The texture itself had no alpha to reject, so that was a part of it.
[*]The fill size of the quad was another major part of it.
[*]And because the fill size was rather large, -and- alpha blending was enabled, it was really slowing down.
[/list]

It's still not performing at the same speed, but I expect that's due to how much of a mess this test app is.

Thanks guys, I appreciate the help. Hopefully one day I'll be able to return the favour.
0

Share this post


Link to post
Share on other sites
Didnt they used to recommend changing the data (buffering it in the CPU mem) first and THEN locking the buffer, copying the entire block, unlocking, making the draw call --- so that the GPU could be processing in parallel with the Apps data creation ?




Also shouldnt "Matrix proj_view_world = proj_view * world;" be outside of the 8K loop ?? or is that part of the 'stress' ...
0

Share this post


Link to post
Share on other sites
[quote name='wodinoneeye' timestamp='1327031045' post='4904454']
Didnt they used to recommend changing the data (buffering it in the CPU mem) first and THEN locking the buffer, copying the entire block, unlocking, making the draw call --- so that the GPU could be processing in parallel with the Apps data creation ?




Also shouldnt "Matrix proj_view_world = proj_view * world;" be outside of the 8K loop ?? or is that part of the 'stress' ...
[/quote]

1. That's a good point. However, if you read through the thread you'll notice that I called this loop only once after my initial problem and I still had speed issues even though it was only calling DrawIndexed in the draw method. So this really had nothing to do with the issue.

2. I'm doing transforms on vertices and processing those vertices on the CPU so I can send them to the buffer pre-transformed. Putting that math outside of the loop would have broken that. I'm aware I can put the transform in the shader, however if I did that I'd end up having to make a single Draw call for each primitive that I want transformed. Unless there's another way to go about it (that'll work on D3D9 downlevel hardware)?
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0