flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > DX11 Compute Shader, Directly to Backbuffer. Win64 |
Author |
|
bitRAKE 20 May 2013, 14:50
Uses d3dcompiler_43.dll, which is probably on your machine. (d3dcompiler_46.dll will work as well if you have the Win8 SDK.)
Purpose is to show minimum needed to use GPU and see result on screen. One thing that is confusing to me: the shader defines the output texture composed of float4, but the backbuffer is of type RGBA. I assume the conversion happens somewhere, but I could not find it documented. Found two other errors in the documentation along the way. From here usually we would want to pass some incremental data each iteration. This requires creating a constant buffer, and binding it to the compute shader. Next, probably might add more UAVs, or other types of buffers. To return data to the CPU. Compute shaders can be quite flexible. For example, http://pouet.net/prod.php?which=59091 and http://pouet.net/prod.php?which=59466 and http://pouet.net/prod.php?which=57302 is almost entirely a cs5 shader. Jan Vlietinck has made available 3D fluid simulation and other examples: http://users.skynet.be/fquake/ Hope it is useful to someone. No video on this one. Thanks baldr for the list macros.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||||||||||
20 May 2013, 14:50 |
|
HaHaAnonymous 20 May 2013, 17:58
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 20:24; edited 1 time in total |
|||
20 May 2013, 17:58 |
|
MHajduk 20 May 2013, 18:05
HaHaAnonymous wrote:
|
|||
20 May 2013, 18:05 |
|
revolution 20 May 2013, 18:38
My Win7 Pro here also doesn't have any of the DLL files.
The tyranny of the default means that using this requires the user to upgrade/update/download an external file. |
|||
20 May 2013, 18:38 |
|
HaHaAnonymous 20 May 2013, 18:53
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 20:24; edited 1 time in total |
|||
20 May 2013, 18:53 |
|
bitRAKE 20 May 2013, 20:08
https://docs.google.com/file/d/0B0Vow7Lxd7nuZ1R4a1VydHh0c2s/edit?usp=sharing
Above is the link to D3DCompiler_46.dll, from the Win8 SDK. It does not have any dependencies which would require any other part of the SDK, or DX update for that matter. The compiled bytecode might require an updated DX, though. Source will obviously need a slight change to use this latest version. Code: dll [d3dcompiler_46 D3DCompile] _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
20 May 2013, 20:08 |
|
bitRAKE 21 May 2013, 02:40
Here we have small data updates being sent to the GPU each iteration of the main loop. For a very lazy timer we just send RDTSC EAX. Enough to produce a strobing effect and cause seizures.
Next up is more internal state space - a texture buffer on the GPU to persist between updates.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||||||||||
21 May 2013, 02:40 |
|
bitRAKE 23 May 2013, 16:54
Once we have a a basic Raymarching framework:
(Largely, Rrrola's main loop - I think it has errors.) Code: [numthreads(32, 32, 1)] void cs0_Main( uint3 gId : SV_GroupID, uint3 dtId : SV_DispatchThreadID, uint3 gtId : SV_GroupThreadID, uint gI : SV_GroupIndex ) { // First convert 2D space into into 3D ray direction: // screen coords 16:10 ratio, square pixels, centered float sx = -1.60 + 3.2 * (float)dtId.x / (float)XRES; float sy = -1.00 + 2.0 * (float)dtId.y / (float)YRES; // bend rays (fish eye) float r2 = sx*sx*0.32f + sy*sy; float tt = (7.0f-sqrt(37.5f-11.5f*r2))/(r2+1.0f); float dx = sx*tt; float dy = sy*tt; float3 v = float3( dx * 0.955336f + 0.29552f, dy, 0.955336f - dx * 0.29552f ); // choose camera position // float3 p = float3( 0.195, 0.5, 0.0 ); float3 p = pos; // Intersect the view ray using raymarching. #define MAX_DIST 4.0 #define MIN_DIST 0.0001 float totalD = 0.0, D = 3.4e38, extraD = 0.0, lastD; int steps; int max_steps = 128; for (steps=0; steps<max_steps; steps++) { lastD = D; D = DE(p + totalD * normalize(v)); // Overstepping: have we jumped too far? Cancel last step. if (extraD > 0.0 && D < extraD) { totalD -= extraD; extraD = 0.0; D = 3.4e38; steps--; continue; } if (D < MIN_DIST || D > MAX_DIST) break; totalD += D; // Overstepping is based on the optimal length of the last step. totalD += extraD = 0.096 * D*(D+extraD)/lastD; } p += totalD * normalize(v); // diagnostic coloring of surface float3 color = float3(0,0,0); float dC = float(steps)/float(max_steps); // We've got a hit or we're not sure. if (D < MAX_DIST) { color = lerp(float3(0,1,0),float3(1,0,1),dC); // We've gone through all steps, but we haven't hit anything. if (D > MIN_DIST) { color = float3(1.0,1.0,1.0); } } output[dtId.xy] = float4(color,1); } http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm For example: Code: float cyl(float3 p, float r, float c) { return max(length(p.xz)-r, abs(p.y)-c); } float DE(float3 p) { return cly(p,1.0,1.3); } It's very fun to combine and tweak distance estimation function to get different effect / shape. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
23 May 2013, 16:54 |
|
bitRAKE 26 May 2013, 09:09
I'm still learning the DX11 changes - haven't programmed any DX since DX8, and a lot has changed. One of the mistakes made in my code above, is that once objects are bound to the context they remain bound. So, the main loop can be reduced to just: update of constant buffer(Map/Unmap), Dispatch, Present.
The DX11 documentation is a mess - saying something isn't possible, and then describing how to do it in other places, lol. It's still leaps and bounds better than DX8 though. Hard to believe how cheap and power efficient this 560Ti card is. |
|||
26 May 2013, 09:09 |
|
cod3b453 26 May 2013, 14:24
Just had a look at this to see how it's done - a lot different from DX6/7 when I played with that a few times!
I tried running it using Win7/ATI but it starts with a coloured box and then, according to my debugger, deadlocked - I see 4 worker threads all stuck in syscalls with the main thread at "$11512 call qword ptr [rax+10h]". |
|||
26 May 2013, 14:24 |
|
bitRAKE 26 May 2013, 15:04
It's erroring out, and then can't Release due to the pointers being invalid. I've attached the current iteration. There isn't much in the way of error checking. In fact, I don't even verify DX11 swapchain is being returned.
cmp byte [nFL+1],$0B ; would do it. ...I'd be glad to help diagnose this further, but would need more info. Would be nice to have it working on ATI, too. It only appears deadlocked because it doesn't process messages - that is by design and not a real problem. All the threads are created by the driver. If you don't see the pretty colored circles in this one then that would be a problem. Assuming you have DX11 hardware, etc... Oh, might want to change the resolution [in the source code] to match what you are using.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||||||||||
26 May 2013, 15:04 |
|
uart777 29 May 2013, 14:43
DirectX is nothing but Hell. Whatever you learn now will be deprecated soon.
Z77 does not assume there is a GPU so the graphics are truly portable, universal and helpful to OS creators and embedded systems programmers. For example, CodeVu draws everything - every single pixel, image, font, control, etc - directly to memory using only the CPU. Same with my ARM graphics. Windows has always had a monopoly on video cards. Manufacturers conceal information and make it impossible for individuals like us to ever come up. |
|||
29 May 2013, 14:43 |
|
bitRAKE 29 May 2013, 23:44
I completely agree. I enjoy learning so much - it will be fun the next time.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
29 May 2013, 23:44 |
|
tthsqe 30 May 2013, 03:03
bitrake,
are you going to make a fasm implementation of that shader code at http://boxplorer2.googlecode.com/svn/trunk/fragment.glsl of which you quoted a small portion for me? P.S: Thanks - I did try Rrrola's shading, but found that I didn't like as much as what I settled on finally for my renderer. |
|||
30 May 2013, 03:03 |
|
bitRAKE 30 May 2013, 04:08
I didn't have any plans to, but I have used pieces of it above in this thread. The verbosity of his shader has been most helpful at understanding.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
30 May 2013, 04:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.