W8&WP8 D3D renderer

Hello,
can you be please more specific what are the problems of native Direct3D renderer for new cocos version 3?

I spent last several hours (not much) of removing ANGLE libraries and I managed to implement Direct3D rendering for W8 (C++) and WP8 (hybrid XAML solution) and did not encounter any serious problem so far.

What I changed:

  1. Render window creation
  2. Texture loading to D3D texture (it is still in cocos2d::Texture2D)
  3. Shaders - I rewrite cocos shaders to HSLS which was pretty straightforward
  4. Rendering - It is very similar with OGL - vertex buffer, index buffer, input layout from shader etc.

What is still need to do:

  1. Complete resource management (possible use of DDS textures)
  2. Generalization of shaders (input layouts, constant buffers)
  3. State cache
  4. Some specific node rendering (labels, progress bar, scissor node, …)

What it brings to us?

In the first case - performance - native render is much more faster (on our W8 tablet 8FPS->60FPS), actually ANGLE solution is not usable for some serious work.
Prevent memory problems with ANGLE - especially when I use DDS textures (it is much more better now with 32-bit textures).

My solution is not probably so clean (I need to refactor few things since I wanted to test the solution firstly) and universal since we are using quite small subset of cocos features. Nevertheless I think that result will be much usable than ANGLE for many people. Fortunately D3D11 interface is very clean and intuitive.

-> I wanted to thank you for 3.0 renderer which allows this native implementation very easy and dynamic batching is super cool feature.

Jiri

11 Likes

When will you finish it? and do you want to share it?
If you will share it, can you push it to github for people to follow?

Sure, I can share it but I need do more work on it. I think that it will take one month since I cannot work on it fulltime.

great!. I’m waiting it!.

Actually I can publish it asap and you can help me with it :slight_smile: I’ll tell you when the repository will be ready.

If you need any help,we may cooperation.

I’ve know idea if I can do something for it, i will do the best any way.

Hello,
so I made repository here: https://github.com/jiriformanek/cocos2d-x

You can start experiment with this. So far there is only mods for basic render, Angel window is not created anymore, instead standard Direct3D creation process there (W8/WP8). Nevertheless angel libraries are still in the projects because there is a lot of gl methods to replace.

I’ve also added W8 proj files for Box2D and Audio but there are no tests so you have to create solution manually (I am using native C++ app without XAML for W8 - the native initialization is much simplier than XAML one).

WP8 XAML cpp-tests should work but there will be only red solid background since there is not render so far (just clearing the buffer).

I will push more code I have now: textures, shaders, rendering.

1 Like

Added full shader support, improvement of texture loading, configuration, Label funcionality.

Next:
ShaderCache and StateCache

2 Likes

I have downloaded it and try to compile it but it fails as this image


how do i fix it?

Hello, it seems that pixel shader HLSL is set as vertex shader. You can change it in the properties of the file but it is strange because I have not this problem. I’ll check it later.

As you can see, some shaders are not still rewritten (all that have commented GLSL code below). You can rewrite them to HLSL. It is very straightforward. When you define input (attributes) and const values (uniforms) you have to edit shader descriptor in ccShaders.cpp where is defined these thing manually (it seems that shader reflection is not supported on WP). You can inspire on Label* shaders, there is usage of input and uniform definition (note that uniform/const values are separated for VS and PS).

Next it seems that cocos tests are some problem with rendering (I merge all changes from my project where everything is working well), you can check it. Visual Studio has very fine tool for debugging of D3D.

Thank you, I solved hlsl and building success but it’s still not working, this is screenshot when I run on device. what is wrong?

I can’t build project with debug mode, this is output when I build solution with debug

Error    2    error LNK2001: unresolved external symbol WKPDID_D3DDebugObjectName    F:\cocos2d-x-sdk\cocos2d-x-3\tests\cpp-empty-test\proj-wp8-xaml\cpp-empty-testComponent\libcocos2d.lib(CCTexture2D.obj)    cpp-empty-testComponent

Hi,

Thank you for starting to implement native Direct X renderer. The Angle project is awful and completely useless on W8. I might be contributing to this project as I have wanted this for a long time and thought about writing it by myself.

dungmv: I know about the rendering problem. Sorry I have not time to solve it during the week. I suppose there is some minor problem (it’s working perfectly on my project). I recommend create some test project for W8. You can do better debugging of D3D (maybe it is also possible on WP8, I don’t know). It is Alt+F5 - Graphics - Start diagnostics. You see what is rendered, complete pipeline settings even shader debugging. Really cool feature.

The link error is strange again - there should be lib in the project: dxguid.lib. But I added it already so maybe vcproj file is not updated… I’ll check it but you can add this lib to the linker settings, It should work.

To all: If you tell me your github logins, I can add you as contributors.

I’ve tried it with WP8, so I will try it with windows 8
here is my github.com, you can add me to github

If I knew how to render in Direct3D, I would contribute to it somehow.
Hope this can be done A.S.A.P. and merged to the official branch.

Added DX state cache + shader cache (I do not undestand sense of this functionality since it is not used in cocos itself). Many nodes are not functional now. It is needed to add DX functionality as in Label (Atlas) or Renderer. It is very straightforward.

Next:
Scissor, ProgressTimer

Added:
ProgressTimer, Scissoring, LayerColor

Next:
Textures improvements

2 Likes

I’ve tried merge it with cocos official but I can not, it has a lot of conflict.
I think cocos must stop commit on render module