0. Requirements


 Sample code named 'D3D12HelloTriangle' which was downloaded in lecture 1. (Link)


1. Intro


   In the file 'D3D12HelloTriangle.cpp', we can find many functions. Among them, following four functions form a basic framework: 


- Oninit(): initialize the directx12 rendering environment. 

- OnUpdate(): update frame-based values such as animation matrix. 

- OnRender(): render the scene.

- OnDestroy(): release resources.


 Let's look at the components one by one. 



2. Oninit function


  Oninitfunction contains two additional sub-functions. LoadPipeline() and LoadAssets(). Let's take a closer look at the Loadpipeline() function. 


1) Loadpipeline()

1-1) Enabling the debug layer

  First, the code enables the debug layer by using Microsoft::WRL::ComPtr. 


1-2) CreateFactory

  Next, create a DXGI factory. It is an object that is capable of creating other DXGI objects. 


1-3) CreateDevice

  Then, DXGI device is created. To create device, adapter, and feature level is required. In the sample code, two types of adapter (warpAdapter and hardwareAdapter) and feature level 11 are used. 


1-4) Command Queue

  Command queue is the ordering of the commands. In the D3D11, both the immediate context and deferred context are supported. However, the immediate context is no longer supported by D3D12,  In the concept of deferred context, commands are queued up and run at a later time. For example, in multi-thread application, each threads can generate commands in parallel, and the commands are mounted on an API object called 'Command Queue'. We call it as a command parallelism. 


  Let's take a closer look at command queues and command lists. In D3D12, the process of transferring commands differes from D3D11 in three important ways: (For more details, you can visit the page: (Link) https://msdn.microsoft.com/en-us/library/windows/desktop/dn899114(v=vs.85).aspx


 1. Elimination of the immediate context. This enables multi-threading. 

 2. Apps own how rendering calls are grouped into GPU work items. This enables re-use.

 3. Apps explicitly control when work is transferred to the GPU. This enables item 1 and 2. 


   As mentioned above, D3D12 no longer supports immediate context. Instead, to render, command lists are used. A command list looks similar to the immediate context which is used in D3D11. Actually, they are similar. They contains commands such as drawing primitives or changing rendering state. However, command lists can be recorded to command queue concurrently, which takes advantage of multi-core processors. If the same process repeats over and over, a command list can be executed multiple times. 






'Cat.Storage > SubCat.Practice' 카테고리의 다른 글

[Directx12] 1. Settings  (0) 2017.04.13
[Matlab] Define 2D sinc() function  (0) 2016.09.21
C++ binary read/write sample  (0) 2016.03.15
D3D11 Rendertarget setting example.  (0) 2016.01.06
Magnitude and Phase Information of the FFT  (0) 2015.10.10
Posted by Cat.IanKang
,

0. Requirements

 

- Windows 10 (please keep your windows up to date.)

- Visual studio 2017 with the windows 10 creator update SDK  (previous version also maybe programmable, but 2017 is recommended.)


1. Intro


 The simplest way to learn new language is to run sample code. Therefore, let's download dx12 sample code from git. Following link allows to download many samples.


https://github.com/Microsoft/DirectX-Graphics-Samples


2. Run sample


  Now, let's run the sample code. In this posting, we are going to execute 'D3D12HelloTriangle'. Let's open it. The code sample is placed in the following URL.


  \anydirectoryyouwant\Directx12\Samples\Desktop\D3D12HelloWorld\src


Then, you can find the 'D3D12HelloWorld.sin'. Open it. There are several sample projects.  Now, please follow the instructions:


1) Click the mouse right button on the project named 'D3D12HelloTriangle' and select the 'Set as startup project'. 

2) Press the F5 button *^^*! (If it does not work, please follow further instructions)

3) If you have problems, maybe some requirements are missed or properties are set wrong. check followings

  3-1)  Does your operating system (windows 10) provides the latest windows SDK version? (The latest version on 2017.04.13 is  10.0.15063.0.) You can identify it from  Right click on Projects->property->Configuration Properties->General->Windows SDK Version. (You can change the SDK version by clicking its panel.)

  3-2)  Does your project use right platform toolset? You can identify it from  Projects->property->Configuration Properties->General->Platform Toolset.  You can use v120 for Visual studio 2015 and v141 for Visual studio 2017. 


 

*Include directory and library is already set in a right way because it is a sample code. So, you may not need to configure those things. 

 *If any problem occur, please leave reply. 


Posted by Cat.IanKang
,

%Define Cartesian Coordinates

radiusSZ = floor(imSize/2);

[X, Y] = meshgrid(-radiusSZ:radiusSZ, -radiusSZ:radiusSZ);

[theta, rho] = cart2pol(X, Y);

rho = round(rho);


%2d sinc function

sincFrq = 1;

sincFilter= sin(rho*sincFrq+0.00001)./(rho*sincFrq+0.00001);

sincFilter_clamped = sincFilter; %init





%If you want to clamp the kernel,

clampDist = 4; %variable

cen = ceil(imSize/2); %variable


sincFilter_clamped = sincFilter_clamped(cen-clampDist:cen+clampDist,cen-clampDist:cen+clampDist);

Posted by Cat.IanKang
,

#include <iostream>

#include <stdlib.h> 

#include <fstream>

#include <stdio.h>



int main()

{

//initializer

float container[4096]; //16*16*4*4

for (int i = 0; i < 1024; ++i)

{

container[i * 4] = 0.1f;

container[i * 4 + 1] = 0.05f;

container[i * 4 + 2] = 0.025f;

container[i * 4 + 3] = 0.0125f;

}

std::fstream file;

file = std::fstream("file.bin", std::ios::out | std::ios::binary);

for (int i = 0; i < 32; ++i)

{

file.write((char*)&container, 4096*sizeof(float));

}

file.close();


std::fstream reader("file.bin", std::ios::binary | std::ios::in);

if (!reader)

{

return 0;

}

float containerR[4096];

reader.read((char*)&containerR, 4096 * sizeof(float));


}


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//wstring version


#include <iostream>

#include <stdlib.h> 

#include <fstream>

#include <stdio.h>

#include <Windows.h>

#include <vector>


int main()

{

const int patchNum = 1024;

const int arrSize = 4096;

float container[arrSize]; //16*16*4*4

float containerRR[arrSize]; //16*16*4*4

std::vector<float> containerR; //16*16*4*4

containerR.resize(arrSize);


for (int i = 0; i < arrSize / 4; ++i)

{


container[i * 4] = 0.1f;

container[i * 4 + 1] = 0.05f;

container[i * 4 + 2] = 0.025f;

container[i * 4 + 3] = 0.0125f;

}


//initializer

for (int allNum = 0; allNum < patchNum; ++allNum)

{

WCHAR fileDest[260];

wsprintfW(fileDest, L"C:\\TerrainData\\moon_32x32\\mass_%02d\\weights.bin", allNum);

std::ofstream outFile;

outFile = std::ofstream(fileDest, std::ios::binary);

outFile.write((char*)&container, arrSize * sizeof(float));

outFile.close();

}


//WCHAR filename[260];

//wsprintfW(filename, L"C:\\TerrainData\\moon_32x32\\mass_00\\weight.bin");

//std::ifstream ampFile(filename, std::ios::binary);

//

//

////patch->ampSetTable.reserve(ampArrSize); //The number of weights. 

//ampFile.seekg(0, std::ios::end);

//std::streampos fileSize = ampFile.tellg();

//ampFile.seekg(0, std::ios::beg);

//

//ampFile.read((char*)&containerR[0], fileSize);

//ampFile.read((char*)&containerRR, arrSize* sizeof(float));

//

//ampFile.close();

}

Posted by Cat.IanKang
,

//If you need any help, leave a message.       


      HRESULT hr = S_OK;

// Setup the render target texture description.

D3D11_TEXTURE2D_DESC rtTextureDesc;

rtTextureDesc.Width = 1280;

rtTextureDesc.Height = 960;

rtTextureDesc.MipLevels = 1;

rtTextureDesc.ArraySize = 1;

rtTextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;

rtTextureDesc.SampleDesc.Count = 1;

rtTextureDesc.SampleDesc.Quality = 0;

rtTextureDesc.Usage = D3D11_USAGE_DEFAULT;

rtTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;

rtTextureDesc.CPUAccessFlags = 0;

rtTextureDesc.MiscFlags = 0;


// Create the render target texture.

V_RETURN(pd3dDevice->CreateTexture2D(&rtTextureDesc, NULL, &m_renderTargetTexture));


// Setup the description of the render target view.

D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;

renderTargetViewDesc.Format = rtTextureDesc.Format;

renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;

renderTargetViewDesc.Texture2D.MipSlice = 0;


// Create the render target view.

V_RETURN(pd3dDevice->CreateRenderTargetView(m_renderTargetTexture, &renderTargetViewDesc, &m_renderTargetView));


//Setup the depth stencil texture description. 

D3D11_TEXTURE2D_DESC dsTextureDesc;

dsTextureDesc.Width = 1024;

dsTextureDesc.Height = 1024;

dsTextureDesc.MipLevels = 1;

dsTextureDesc.ArraySize = 1;

dsTextureDesc.SampleDesc.Count = 1;

dsTextureDesc.SampleDesc.Quality = 0;

dsTextureDesc.Format = DXGI_FORMAT_D32_FLOAT;

dsTextureDesc.Usage = D3D11_USAGE_DEFAULT;

dsTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;

dsTextureDesc.CPUAccessFlags = 0;

dsTextureDesc.MiscFlags = 0;

V_RETURN(pd3dDevice->CreateTexture2D(&dsTextureDesc, NULL, &m_depthTexture));


// Create the depth stencil view

D3D11_DEPTH_STENCIL_VIEW_DESC DescDS;

DescDS.Format = dsTextureDesc.Format;

DescDS.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;

DescDS.Texture2D.MipSlice = 0;

DescDS.Flags = NULL;

V_RETURN(pd3dDevice->CreateDepthStencilView(m_depthTexture, &DescDS, &m_depthView));


pd3dImmediateContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthView);

return hr;

Posted by Cat.IanKang
,

Magnitude and Phase Information of the FFT

http://kr.mathworks.com/help/signal/examples/practical-introduction-to-frequency-domain-analysis.html#zmw57dd0e4405



2D shift

http://www.mathworks.com/matlabcentral/newsreader/view_thread/334354


My Code:

sz = 513;

gv = linspace(-1,1,sz);

[X,Y] = meshgrid(gv,gv);

[th,rh] = cart2pol(X,Y);


for ii=1:sz

    for jj=1:sz

        if th(ii,jj) < 0

            th(ii,jj) = th(ii,jj) + 2*pi;

        end

    end

end


m = zeros(sz);


m = m + perlinBandAnalyser(sz,1,5, @(n,noise,w) deal(w(n)*noise,0), ones(9,1));


close all;

figure, calcPSD(m, 'show', 'mesh');

figure, imshow(m, []);


ft_m = fft2(m);

ft_IanShift_m = ft_m;

%phase shift 

shiftAmount = 0.2*pi;

phase = angle(ft_IanShift_m); % Apply phase shift

amp = abs(ft_IanShift_m);

N = ceil(size(phase)/2);

  

    phase(:,2:N(2),:) = phase(:,2:N(2),:)+ shiftAmount;

    phase(:,(N(2)+1):(size(phase,2)),:) = phase(:,(N(2)+1):(size(phase,2)),:)- shiftAmount;

    

    ShiftedImage = amp.*exp(1i*phase); % Recombine magnitude and phase

    PhaseStim = real(ifft2(ShiftedImage)); % Perform inverse fourier transform

    

    Range = max(max(max(PhaseStim))) - min(min(min(PhaseStim)));

    PhaseStim = uint8(((PhaseStim - min(min(min(PhaseStim))))/Range)*255);


figure, imshow(PhaseStim,[]);



return;

'Cat.Storage > SubCat.Practice' 카테고리의 다른 글

[Directx12] 2. Anatomy of the sample code  (1) 2017.04.14
[Directx12] 1. Settings  (0) 2017.04.13
[Matlab] Define 2D sinc() function  (0) 2016.09.21
C++ binary read/write sample  (0) 2016.03.15
D3D11 Rendertarget setting example.  (0) 2016.01.06
Posted by Cat.IanKang
,