Sunday 6 October 2013

cinder and windows RT/Phone, and lot of joy...

As some of you might know, I started to contribute to cinder.

There's a few reasons about it:

  • Having cinder app running as vvvv plugins can be pretty cool.
  • Let's spread a bit the dx11 world
  • I want to test if cinder is appropriate to become new FlareTic core (since i still look at moving some parts to c++)
So Microsoft people contributed some (decent) amount of code to have cinder running on WinRT. After some look there's quite a few bits which did tick me:
  • Code is more to replicate OpenGl fixed function. That's great, we are in 2013 and we use DirectX11 to emulate DirectX7/OpenGL1 (I'll stop commenting now on that, there's intention for quick portability but come on...)
  • No love for windows phone
  • I'm not commenting on code quality either.
So my idea is anyway to deal with decent scale graphics, if it means I need to replace most of the codebase so be it, at least by the look of it I have renderwindows and some events done for me, I can easily push my dx11 code ;)

So let's start, I run project as RT (since I already have window code for desktop there's no point using it as starting point).

Ok renderer code is a right mess with million (ok I exaggerate a tad) lines of random boilerplate code. I started to clean it with my resource wrapper, but then realized I would just waste my time (since I'm not gonna use that code anyway).

So let's go back the good old fashioned way, create two new wrappers for App/Renderer (basically copy the RT code), get rid of all the boilerplate dx stuff and push my render context instead.

Fix couple of initialization issues, and here we go, I got render working (instancing 65k boxes, my trademark hello world ;)

So technically by the look of it it wasn't that hard I thought (I just had to recompile and modify effects framework a little bit to fit it in, even if Microsoft decided to divorce Effects11 I still believe it's a great tool and it stays an integral part of my workflow for now).

Now since I also got a dx11.1 renderer, I decided to quickly check one new feature. Logical blend states.
That was easy, create a Xor Blend, apply to pipeline and look, all works out of the box (screenshot below looks a bit freaky and doesn't make justice to possibilities offered).


Now I wanted to test the other feature (UAV at every stage), which is for me the most exciting one, but since some big company called NVidia (not to name them) decided they would not implement it, I decided to leave it for later (I got an high end ATI but machine needs a big clean).

So let's go for another fun feature, try to build all that lot on windows phone.

So first thing is :
Build cinder for ARM : done, there's already target and lib files.
Build effects11 for ARM : quite simple as well, except there's of course no d3dcompiler shader/lib on folders. Copy files around a little tad solved it, really not the right way to do, but it's fine for quick testing ;)

All cinder compiled, let's try application now )

Build test application : Obvious 200 compile errors....
  • First microsoft decided to hide some #pragma lib deep into some imaging source files in cinder core, ok found them removed them.
  • Surface uses Wic a lot, not supported on windows phone. So basically any code making use of Surface class in cinder will create you linker error (and Surface class is used a lot).
  • Nevermind, comment all that lot (you love Git to repair your mess afterwards by the way ;)
  • Application Compiles
  • Run->Can't find d3dcompiler.dll ... That drives me nuts, I add it into project but it just doesn't want to deploy it... And I would LOVE to know why shader reflection was not allowed in the first place (if any Microsoft person reads this blog and has an answer, please let me know, I'll keep quiet about it promised).
  • Ok nervermind, since it's there out of the box in windows 8.1 (including phone), let's just try to see if my dx11 code + cinder runs (just a swapchain with solid color will do the job).
  • Comment any D3D compiler related parts, run, crash.
This random line to build cursor in WinRTApp is not supported on phone:

Code Snippet
  1. window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);

Run again, crash...

Now it's swapchain, to make things easy, options in WindowsRT and Windows Phone have to of course be different, so here is Windows phone SwapChain creation:

Code Snippet
  1. DXGI_SWAP_CHAIN_DESC1 desc;
  2. ZeroMemory(&desc,sizeof(DXGI_SWAP_CHAIN_DESC1));
  3. desc.BufferCount =1;// 2;
  4. desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  5. desc.SampleDesc.Count = 1;
  6. desc.SampleDesc.Quality = 0;
  7. desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
  8. desc.Scaling = DXGI_SCALING_STRETCH;
  9. desc.SwapEffect =DXGI_SWAP_EFFECT_DISCARD;// DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
  10. desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
  11. desc.Width = width;
  12. desc.Height = height;

Please note I love previous comment saying all windows store apps... Well doesn't apply to phone obviously...

Ok run again, hurray I got swapchain rendering on my phone.

Now try to switch back from my renderer to contributed one (error dataflow... ;) , please, we want Direct2d/DirectWrite/Wic also for phone ;)

Conclusion:
-Having cinder running as plugin will be piece of cake, for windows apps it's also pretty simple.
-Getting standalone Desktop/RT (pro) path is also quite trivial
-For anything like phone, seems gonna be a pain without scrapping a lot of code and cleaning it up.
-As a use for my tool, no decision yet.
-c++ is fun ;)
-Let's have a decent try on windows phone 8.1 (which already removes d3dcompiler issue, the biggest caveat for me).



No comments:

Post a Comment