-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 247277c
Showing
14 changed files
with
518 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# compiled shader files | ||
*.sh | ||
*.cso | ||
*.asm | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
|
||
|
||
#OS junk files | ||
[Tt]humbs.db | ||
*.DS_Store | ||
|
||
#Visual Studio files | ||
*.[Oo]bj | ||
*.user | ||
*.aps | ||
*.pch | ||
*.vspscc | ||
*.vssscc | ||
*_i.c | ||
*_p.c | ||
*.ncb | ||
*.suo | ||
*.tlb | ||
*.tlh | ||
*.bak | ||
*.[Cc]ache | ||
*.ilk | ||
*.log | ||
*.lib | ||
*.sbr | ||
*.sdf | ||
*.opensdf | ||
*.unsuccessfulbuild | ||
ipch/ | ||
[Oo]bj/ | ||
[Bb]in | ||
[Dd]ebug*/ | ||
[Rr]elease*/ | ||
Ankh.NoLoad | ||
|
||
#MonoDevelop | ||
*.pidb | ||
*.userprefs | ||
|
||
#Tooling | ||
_ReSharper*/ | ||
*.resharper | ||
[Tt]est[Rr]esult* | ||
*.sass-cache | ||
|
||
#Project files | ||
[Bb]uild/ | ||
|
||
#Subversion files | ||
.svn | ||
|
||
# Office Temp Files | ||
~$* | ||
|
||
# vim Temp Files | ||
*~ | ||
|
||
#NuGet | ||
packages/ | ||
*.nupkg | ||
|
||
#ncrunch | ||
*ncrunch* | ||
*crunch*.local.xml | ||
|
||
# visual studio database projects | ||
*.dbmdl | ||
|
||
#Test files | ||
*.testsettings | ||
|
||
#blender backups | ||
*.blend1 | ||
*.blend2 | ||
|
||
#obj files in resources | ||
/resources/models/objects/*.mtl | ||
!/resources/models/objects/*.obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "DXShader.h" | ||
|
||
|
||
DXShader::DXShader(ID3D11Device* device, const BYTE* bytecode) | ||
{ | ||
device->CreateComputeShader(bytecode, sizeof(bytecode), NULL, &this->shader); | ||
} | ||
|
||
|
||
DXShader::~DXShader() | ||
{ | ||
} | ||
|
||
ID3D11ComputeShader* DXShader::getShader() { | ||
return this->shader; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <d3d11.h> | ||
|
||
class DXShader | ||
{ | ||
private: | ||
ID3D11ComputeShader* shader; | ||
public: | ||
DXShader(ID3D11Device*, const BYTE*); | ||
~DXShader(); | ||
|
||
ID3D11ComputeShader* getShader(); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "DXStructuredBuffer.h" | ||
|
||
|
||
DXStructuredBuffer::DXStructuredBuffer(ID3D11Device* d, unsigned int s, unsigned int n) | ||
{ | ||
D3D11_BUFFER_DESC sbDesc; | ||
D3D11_UNORDERED_ACCESS_VIEW_DESC sbUAVDesc; | ||
|
||
sbDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE; | ||
sbDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; | ||
sbDesc.StructureByteStride = s; | ||
sbDesc.ByteWidth = sbDesc.StructureByteStride * n; | ||
sbDesc.Usage = D3D11_USAGE_DEFAULT; | ||
d->CreateBuffer(&sbDesc, NULL, &this->buffer); | ||
|
||
// UAV | ||
sbUAVDesc.Buffer.NumElements = sbDesc.ByteWidth / sbDesc.StructureByteStride; | ||
sbUAVDesc.Format = DXGI_FORMAT_UNKNOWN; //DXGI_FORMAT_R8G8B8A8_UNORM | ||
sbUAVDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; | ||
|
||
d->CreateUnorderedAccessView((ID3D11Resource *) this->buffer, &sbUAVDesc, &this->uav); | ||
} | ||
|
||
|
||
DXStructuredBuffer::~DXStructuredBuffer() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <d3d11.h> | ||
|
||
class DXStructuredBuffer | ||
{ | ||
private: | ||
ID3D11Buffer* buffer; | ||
ID3D11UnorderedAccessView* uav; | ||
public: | ||
DXStructuredBuffer(ID3D11Device*, unsigned int, unsigned int); | ||
~DXStructuredBuffer(); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "DXTexture.h" | ||
|
||
|
||
DXTexture::DXTexture(IDXGISwapChain* sc, ID3D11Device* dev, int id) | ||
{ | ||
sc->GetBuffer(id, __uuidof(ID3D11Texture2D), (void**) &this->texture); | ||
dev->CreateUnorderedAccessView((ID3D11Resource*) this->texture, NULL, &this->uav); | ||
|
||
} | ||
|
||
|
||
DXTexture::~DXTexture() | ||
{ | ||
this->texture->Release(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <d3d11.h> | ||
|
||
class DXTexture | ||
{ | ||
private: | ||
ID3D11Texture2D* texture; | ||
ID3D11UnorderedAccessView* uav; | ||
public: | ||
DXTexture(IDXGISwapChain*, ID3D11Device*, int); | ||
~DXTexture(); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "DXWrapper.h" | ||
|
||
DXWrapper::DXWrapper(HWND window, int width, int height) | ||
{ | ||
const DXGI_SWAP_CHAIN_DESC sd = { { width, height, { 60, 1 }, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, DXGI_MODE_SCALING_UNSPECIFIED }, { 1, 0 }, DXGI_USAGE_RENDER_TARGET_OUTPUT, 1, NULL, TRUE, DXGI_SWAP_EFFECT_SEQUENTIAL, 0 }; | ||
|
||
DXGI_SWAP_CHAIN_DESC temp; | ||
temp = sd; | ||
temp.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_UNORDERED_ACCESS | DXGI_USAGE_SHADER_INPUT; | ||
temp.OutputWindow = window; | ||
|
||
|
||
D3D11CreateDeviceAndSwapChain( | ||
NULL, | ||
D3D_DRIVER_TYPE_HARDWARE, | ||
NULL, | ||
D3D11_CREATE_DEVICE_DEBUG, | ||
NULL, | ||
0, | ||
D3D11_SDK_VERSION, | ||
&temp, | ||
&(this->swapChain), | ||
&(this->device), | ||
NULL, | ||
&(this->context) | ||
); | ||
|
||
} | ||
|
||
|
||
DXWrapper::~DXWrapper() | ||
{ | ||
this->context->ClearState(); | ||
this->device->Release(); | ||
this->swapChain->Release(); | ||
} | ||
|
||
void DXWrapper::present() { | ||
this->swapChain->Present(0, 0); | ||
} | ||
|
||
DXTexture DXWrapper::getTexture(int id) { | ||
return DXTexture(this->swapChain, this->device, id); | ||
} | ||
|
||
DXStructuredBuffer DXWrapper::getStructuredBuffer(unsigned int stride, unsigned int num) { | ||
return DXStructuredBuffer(this->device, stride, num); | ||
} | ||
|
||
DXShader DXWrapper::getComputeShader(const BYTE* bytecode) { | ||
return DXShader(device, bytecode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <Windows.h> | ||
|
||
#include <d3d11.h> | ||
#include <d3dcompiler.h> | ||
|
||
#include "DXTexture.h" | ||
#include "DXStructuredBuffer.h" | ||
#include "DXShader.h" | ||
|
||
class DXWrapper | ||
{ | ||
private: | ||
ID3D11Device* device; | ||
IDXGISwapChain* swapChain; | ||
ID3D11DeviceContext* context; | ||
|
||
public: | ||
DXWrapper(HWND, int, int); | ||
~DXWrapper(); | ||
|
||
void present(); | ||
DXTexture getTexture(int id); | ||
DXStructuredBuffer getStructuredBuffer(unsigned int, unsigned int); | ||
DXShader getComputeShader(const BYTE*); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//////////////////////////////////////// | ||
// | ||
// Radix Sort in DirectCompute | ||
// by Jacob Maskiewicz | ||
// | ||
// CSE 190: GPU Programming | ||
// | ||
//////////////////////////////////////// | ||
|
||
#include <Windows.h> | ||
|
||
#include "DXWrapper.h" | ||
|
||
#include "RadixSort.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); | ||
DXStructuredBuffer& sortBuffer = dx.getStructuredBuffer(sizeof(float), WINWIDTH * WINHEIGHT); | ||
|
||
DXShader& shader = dx.getComputeShader(g_main); | ||
|
||
bool running = true; | ||
while (running) { | ||
MSG msg; | ||
PeekMessage(&msg, windowHandle, 0, 0, PM_REMOVE); | ||
|
||
//TODO - set shader | ||
//TODO - set views and buffers | ||
//TODO - dispatch shader | ||
//TODO - reset shader and resource view | ||
|
||
dx.present(); | ||
} | ||
|
||
// release buffers and shaders | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[numthreads(1, 1, 1)] | ||
void main( uint3 DTid : SV_DispatchThreadID ) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.21005.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "radix_sort", "radix_sort.vcxproj", "{F3C5DCE0-E45D-45C9-8D13-38BC935C312E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Win32 = Debug|Win32 | ||
Release|Win32 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F3C5DCE0-E45D-45C9-8D13-38BC935C312E}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
{F3C5DCE0-E45D-45C9-8D13-38BC935C312E}.Debug|Win32.Build.0 = Debug|Win32 | ||
{F3C5DCE0-E45D-45C9-8D13-38BC935C312E}.Release|Win32.ActiveCfg = Release|Win32 | ||
{F3C5DCE0-E45D-45C9-8D13-38BC935C312E}.Release|Win32.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.