Sign in to follow this  
Gavin Williams

DX11 Wrapper for Direct X on WinRT

Recommended Posts

Gavin Williams    985
Just to set the scene, I've been using SlimDX for accessing Direct X 11 in C#. But I'm very much interested in how Direct X 11.1 will be made available to C# and how I can work with C#/DX11.1 on the Windows Store platform specifically. Obviously there is SharpDX. But at the moment I'm just trying to understand how interop might best work on Win RT to connect Direct X with C#. And how I might implement such interop, or at least understand it better.

So I've read or heard via the build videos that Direct X has been integrated with WinRT, at least, that's what some of the diagram's portray. But when I inspect the WinMetadata folder, Direct X is not part of the WinRT object model (it seems to me).

So is it that Direct X is in WinRT by name only ? And has it not been functionally integrated ? I would imagine that if it were integrated, then the CLR could generate a Runtime Callable Wrapper as needed, but I would say performance might not be as good as say SharpDX. I'm not sure if SharpDX uses C++/CLI or C++/CX, but I think the Runtime Callable Wrappers would incur an additional cost.

And if interop between Direct X and C# were implemented for RT, what then would be the best way. I would say use class libraries rather than Windows RT Components as I am only interested in C#.

Also, I would say use C++/CX rather than C++/CLI as I believe that CX provides better interop performance. In fact CX might be the only way to write RT wrappers (not Runtime Callable Wrappers). But this is confusing because as I've said, Direct X might not be actually a part of RT even though it is shown to be. I haven't quite worked out how CX fits into the picture other than to say it's next gen C++/CLI and is CLI for RT. So I would use CX to provide Direct X with a managed programming surface ? Or C++/CLI otherwise.Am I starting to understand this properly ? Or what can be said about how to approach this problem ? Edited by Gavin Williams

Share this post

Link to post
Share on other sites
bubu LV    1436
I think word "integrated" in this context means that WinRT supports D3D11 for applications and nothing else. Like GDI is not integrated with WinRT.

Share this post

Link to post
Share on other sites
Gavin Williams    985
Right ok... I have found this to confirm what you've said and what I suspected (from [url=""]DirectX and XAML interop (Windows Store apps using C++ and DirectX)[/url] )

Note DirectX APIs are not defined as Windows Runtime types, so you typically use C++/Cx to develop XAML app components that interop with DirectX. That said, you can create a Windows Store app with C# and XAML app that uses DirectX if you wrap the DirectX calls in a separate Windows Runtime type library.

Share this post

Link to post
Share on other sites
Gavin Williams    985
Alexandre Mutel went some way to lay out my options for me on msdn where I 'double posted' this question, as rough as it is. [url=""]http://social.msdn.m...42-484223559ef3[/url] Certainly there's enough insight there to keep me busy. Also this link provides a great demo by DevHawk on using WinRT to wrap C++ code. Which isn't hard at all but as a C++ noob, at first this all seems very daunting.

Share this post

Link to post
Share on other sites
Vexal    509
You use C++ / CX to interface with the operating system. All code you would write in a C++ Direct3D program for Win32 (xp, vista, 7) will be identical in a C++ Direct3D Windows RT application. Almost all of the Direct3D code will be the same. The only difference is the code used to create the window and bind it to the device context, and to get the user input (event handlers instead of directinput).

None of the code in C++ / CX is managed. The WinRT components use reference counting, but you do not have to use the components except to create a Window. There is no overhead of the XAML layer.

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  

  • Similar Content

    • By isu diss
       I'm trying to code Rayleigh part of Nishita's model (Display Method of the Sky Color Taking into Account Multiple Scattering). I get black screen no colors. Can anyone find the issue for me?
      #define InnerRadius 6320000 #define OutterRadius 6420000 #define PI 3.141592653 #define Isteps 20 #define Ksteps 10 static float3 RayleighCoeffs = float3(6.55e-6, 1.73e-5, 2.30e-5); RWTexture2D<float4> SkyColors : register (u0); cbuffer CSCONSTANTBUF : register( b0 ) { float fHeight; float3 vSunDir; } float Density(float Height) { return exp(-Height/8340); } float RaySphereIntersection(float3 RayOrigin, float3 RayDirection, float3 SphereOrigin, float Radius) { float t1, t0; float3 L = SphereOrigin - RayOrigin; float tCA = dot(L, RayDirection); if (tCA < 0) return -1; float lenL = length(L); float D2 = (lenL*lenL) - (tCA*tCA); float Radius2 = (Radius*Radius); if (D2<=Radius2) { float tHC = sqrt(Radius2 - D2); t0 = tCA-tHC; t1 = tCA+tHC; } else return -1; return t1; } float RayleighPhaseFunction(float cosTheta) { return ((3/(16*PI))*(1+cosTheta*cosTheta)); } float OpticalDepth(float3 StartPosition, float3 EndPosition) { float3 Direction = normalize(EndPosition - StartPosition); float RayLength = RaySphereIntersection(StartPosition, Direction, float3(0, 0, 0), OutterRadius); float SampleLength = RayLength / Isteps; float3 tmpPos = StartPosition + 0.5 * SampleLength * Direction; float tmp; for (int i=0; i<Isteps; i++) { tmp += Density(length(tmpPos)-InnerRadius); tmpPos += SampleLength * Direction; } return tmp*SampleLength; } static float fExposure = -2; float3 HDR( float3 LDR) { return 1.0f - exp( fExposure * LDR ); } [numthreads(32, 32, 1)] //disptach 8, 8, 1 it's 256 by 256 image void ComputeSky(uint3 DTID : SV_DispatchThreadID) { float X = ((2 * DTID.x) / 255) - 1; float Y = 1 - ((2 * DTID.y) / 255); float r = sqrt(((X*X)+(Y*Y))); float Theta = r * (PI); float Phi = atan2(Y, X); static float3 Eye = float3(0, 10, 0); float ViewOD = 0, SunOD = 0, tmpDensity = 0; float3 Attenuation = 0, tmp = 0, Irgb = 0; //if (r<=1) { float3 ViewDir = normalize(float3(sin(Theta)*cos(Phi), cos(Theta),sin(Theta)*sin(Phi) )); float ViewRayLength = RaySphereIntersection(Eye, ViewDir, float3(0, 0, 0), OutterRadius); float SampleLength = ViewRayLength / Ksteps; //vSunDir = normalize(vSunDir); float cosTheta = dot(normalize(vSunDir), ViewDir); float3 tmpPos = Eye + 0.5 * SampleLength * ViewDir; for(int k=0; k<Ksteps; k++) { float SunRayLength = RaySphereIntersection(tmpPos, vSunDir, float3(0, 0, 0), OutterRadius); float3 TopAtmosphere = tmpPos + SunRayLength*vSunDir; ViewOD = OpticalDepth(Eye, tmpPos); SunOD = OpticalDepth(tmpPos, TopAtmosphere); tmpDensity = Density(length(tmpPos)-InnerRadius); Attenuation = exp(-RayleighCoeffs*(ViewOD+SunOD)); tmp += tmpDensity*Attenuation; tmpPos += SampleLength * ViewDir; } Irgb = RayleighCoeffs*RayleighPhaseFunction(cosTheta)*tmp*SampleLength; SkyColors[DTID.xy] = float4(Irgb, 1); } }  
    • By amadeus12
      I made my obj parser
      and It also calculate tagent space for normalmap.
      it seems calculation is wrong..
      any good suggestion for this?
      I can't upload my pics so I link my question.
      and I uploaded my code here

    • By Alessandro Pozzer
      Hi guys, 

      I dont know if this is the right section, but I did not know where to post this. 
      I am implementing a day night cycle on my game engine and I was wondering if there was a nice way to interpolate properly between warm colors, such as orange (sunset) and dark blue (night) color. I am using HSL format.
      Thank  you.
    • By thefoxbard
      I am aiming to learn Windows Forms with the purpose of creating some game-related tools, but since I know absolutely nothing about Windows Forms yet, I wonder:
      Is it possible to render a Direct3D 11 viewport inside a Windows Form Application? I see a lot of game editors that have a region of the window reserved for displaying and manipulating a 3D or 2D scene. That's what I am aiming for.
      Otherwise, would you suggest another library to create a GUI for game-related tools?
      I've found a tutorial here in gamedev that shows a solution:
      Though it's for D3D9, I'm not sure if it would work for D3D11?
    • By Cyndanera
      in directx I need to know how would I play the animation in directx rendering frames for each part of the model moving parts - like the bones, how would would that work?
      I'm new to writing a animation player, for a model parser.
      I'm asking so I understand how to do this, I'm new to loading a model and playing\moving the bones to effect the mesh.
  • Popular Now