Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NK_UINT_DRAW_INDEX not working for D3D11 implementation #236

Closed
Hecklezz opened this issue Dec 28, 2020 · 14 comments
Closed

NK_UINT_DRAW_INDEX not working for D3D11 implementation #236

Hecklezz opened this issue Dec 28, 2020 · 14 comments

Comments

@Hecklezz
Copy link
Contributor

Hecklezz commented Dec 28, 2020

If I draw a tonne of things at once, I reach the limit of the maximum number of indices or vertexes of the default ushort size. However, I read that defining NK_UINT_DRAW_INDEX will increase this limit to a uint which should be way more than enough for what I need it for.

However, if I have this define added, even when barely drawing anything for e.g. just using the nuklear demo, this happens (defined)-

Click to expand

image

when it should look normal like this (not defined)-

Click to expand

image

Does anyone know how to properly fix this in the D3D11 implementation, or perhaps what I am doing wrong?

The demo used is from here-
https://github.com/Immediate-Mode-UI/Nuklear/tree/master/demo/d3d11

Thank you.

@Hejsil
Copy link
Contributor

Hejsil commented Dec 28, 2020

Hi. I seems you're hitting the problem stated in this comment. Specifically:

     * and don't forget to specify the new element size in your drawing
     * backend (OpenGL, DirectX, ...). For example in OpenGL for `glDrawElements`
     * instead of specifing `GL_UNSIGNED_SHORT` you have to define `GL_UNSIGNED_INT`.
     * Sorry for the inconvenience. */

@Hejsil
Copy link
Contributor

Hejsil commented Dec 28, 2020

Now, I cannot be 100% sure, but I think you need to fix this line:

-    ID3D11DeviceContext_IASetIndexBuffer(context, d3d11.index_buffer, DXGI_FORMAT_R16_UINT, 0);
+    ID3D11DeviceContext_IASetIndexBuffer(context, d3d11.index_buffer, DXGI_FORMAT_R32_UINT, 0);

@Hecklezz
Copy link
Contributor Author

Hello there, thank you for the suggestion as it almost fixes the issue, but I also had to increase the MAX_VERTEX_BUFFER and MAX_INDEX_BUFFER (MAX_INDEX_BUFFER being MAX_VERTEX_BUFFER / 4) to a much larger number. Now it is able to render an ungodly amount of things without any problems what-so-ever.

Thank you!

@Hejsil
Copy link
Contributor

Hejsil commented Dec 28, 2020

@Hecklezz Cool. Would you be willing to open a PR that adds the changes required for this to work on the demo?

@Hecklezz
Copy link
Contributor Author

Isn't the default ushort the intended default behavior though?

@Hejsil
Copy link
Contributor

Hejsil commented Dec 28, 2020

Yes, but I was thinking of having some ifdefs on NK_UINT_DRAW_INDEX and have the old thing if it is not defined, and do this fix if it is.

@Hecklezz
Copy link
Contributor Author

Hecklezz commented Dec 29, 2020

What do you think is an appropriate MAX_VERTEX_BUFFER and MAX_INDEX_BUFFER size as the default for when using uint instead of ushort for the draw index?
Because compared to ushort, it can be ALOT larger, but making it that big would just be stupid.

@Hejsil
Copy link
Contributor

Hejsil commented Dec 29, 2020

Hmm, good question. The current values are already 2x/4x larger than ushort max. Idk what you're drawing and if it is a realistic workload, but I would probably leave those as is.

@Hecklezz
Copy link
Contributor Author

What I was drawing was just testing extreme unrealistic cases, and if left to draw "everything" instead of things that were culled, or too far away, etc. So alright, I guess it can be left as they currently are.

@Hecklezz
Copy link
Contributor Author

Do you think something like this will suffice-

NK_API void nk_d3d11_render(ID3D11DeviceContext* context, enum nk_anti_aliasing AA) {
    const float blend_factor[4] = {0.0f, 0.0f, 0.0f, 0.0f};
    const UINT stride = sizeof(struct nk_d3d11_vertex);
    const UINT offset = 0;
#ifdef NK_UINT_DRAW_INDEX
    DXGI_FORMAT index_buffer_format = DXGI_FORMAT_R32_UINT;
#else
    DXGI_FORMAT index_buffer_format = DXGI_FORMAT_R16_UINT;
#endif

    context->IASetInputLayout(d3d11.input_layout);
    context->IASetVertexBuffers(0, 1, &d3d11.vertex_buffer, &stride, &offset);
    context->IASetIndexBuffer(d3d11.index_buffer, index_buffer_format, 0);
    context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

@Hejsil
Copy link
Contributor

Hejsil commented Dec 29, 2020

Yea, that seems good to me

@Hecklezz
Copy link
Contributor Author

I should not add NK_UINT_DRAW_INDEX to the demo though right? Leave that up to the end-user to add themselves?

@Hejsil
Copy link
Contributor

Hejsil commented Dec 29, 2020

Correct

@Hecklezz
Copy link
Contributor Author

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants