-
Notifications
You must be signed in to change notification settings - Fork 4
/
Main.cpp
95 lines (71 loc) · 2.88 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
////////////////////////////////////////
//
// Radix Sort in DirectCompute
// by Jacob Maskiewicz
//
// CSE 190: GPU Programming
//
////////////////////////////////////////
#include <Windows.h>
#include "DXWrapper.h"
#include "Fractal.h"
#include "RadixSort.sh"
#include "qjulia4D.sh"
#include "ParallelReduction.sh"
// define the size of the window
#define THREADSX 16 // number of threads in the thread group used in the compute shader
#define THREADSY 16 // number of threads in the thread group used in the compute shader
#define WINDOWWIDTH 1280
#define WINDOWHEIGHT 720
#define WINWIDTH ((((WINDOWWIDTH + THREADSX - 1) / THREADSX) * THREADSX)) // multiply of ThreadsX
#define WINHEIGHT ((((WINDOWHEIGHT + THREADSY - 1) / THREADSY) * THREADSY)) // multiply of ThreadsY
#define WINPOSX 50
#define WINPOSY 50
int WINAPI WinMain(
HINSTANCE hInstance, // HANDLE TO AN INSTANCE. This is the "handle" to YOUR PROGRAM ITSELF.
HINSTANCE hPrevInstance,// USELESS on modern windows (totally ignore hPrevInstance)
LPSTR szCmdLine, // Command line arguments. similar to argv in standard C programs
int iCmdShow) // Start window maximized, minimized, etc.
{
HWND windowHandle = CreateWindow(L"edit", 0, WS_POPUP | WS_VISIBLE, WINPOSX, WINPOSY, WINWIDTH, WINHEIGHT, 0, 0, 0, 0);
ShowCursor(false);
DXWrapper dx(windowHandle, WINWIDTH, WINHEIGHT);
DXTexture& backBuffer = dx.getTexture(0);
DXConstantBuffer& constantBuffer = dx.getConstantBuffer(sizeof(Fractal::MainConstantBuffer));
DXStructuredBuffer& juliaOut = dx.getStructuredBuffer(sizeof(float)*4, WINWIDTH * WINHEIGHT);
DXStructuredBuffer& sums = dx.getStructuredBuffer(sizeof(float), WINWIDTH*WINHEIGHT/(THREADSX*THREADSY));
DXShader& shader = dx.getComputeShader(g_main, sizeof(g_main));
DXShader& qjulia = dx.getComputeShader(g_CS_QJulia4D, sizeof(g_CS_QJulia4D));
DXShader& reduce = dx.getComputeShader(g_PostFX, sizeof(g_PostFX));
Fractal::initialize();
MSG msg;
bool running = true;
while (running) {
PeekMessage(&msg, windowHandle, 0, 0, PM_REMOVE);
if (GetAsyncKeyState(VK_ESCAPE)) running = false;
Fractal::update();
Fractal::MainConstantBuffer* b = dx.map<Fractal::MainConstantBuffer>(constantBuffer);
b->c_height = WINHEIGHT;
b->c_width = WINWIDTH;
Fractal::fill(b);
b = NULL;
dx.unmap(constantBuffer);
// QJulia
dx.setComputeShader(qjulia);
dx.setUAV(0, 1, juliaOut.getUAV());
dx.setConstantBuffer(0, 1, constantBuffer);
dx.runShader(WINWIDTH / THREADSX, WINHEIGHT / THREADSY, 1);
dx.resetShader();
// Sort each block
dx.setComputeShader(shader);
dx.setUAV(0, 1, backBuffer.getUAV()); //output
dx.setConstantBuffer(0, 1, constantBuffer);
dx.setSRV(0, 1, juliaOut.getSRV()); //input
dx.runShader(WINWIDTH / THREADSX, WINHEIGHT / THREADSY, 1);
dx.resetShader();
dx.present();
__noop;
}
// release buffers and shaders automatically with destructors
return msg.wParam;
}