This file contains hidden or 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
| static const UINT maxConstantBufferBlocks = 1000; | |
| ComPtr<ID3D12Resource> constantBuffer; | |
| struct { char buf[0x100]; } *mappedConstantBuffer = nullptr; | |
| int size = maxConstantBufferBlocks * 0x100; | |
| D3D12_HEAP_PROPERTIES prop = { D3D12_HEAP_TYPE_UPLOAD, D3D12_CPU_PAGE_PROPERTY_UNKNOWN, D3D12_MEMORY_POOL_UNKNOWN, 1, 1 }; | |
| D3D12_RESOURCE_DESC desc = { D3D12_RESOURCE_DIMENSION_BUFFER, 0, (UINT64)size, 1, 1, 1, DXGI_FORMAT_UNKNOWN, { 1, 0 }, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, D3D12_RESOURCE_FLAG_NONE }; | |
| device->CreateCommittedResource(&prop, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&constantBuffer)); |
This file contains hidden or 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
| void afSetDescriptorHeap(ComPtr<ID3D12DescriptorHeap> heap) | |
| { | |
| ID3D12GraphicsCommandList* list = deviceMan.GetCommandList(); | |
| ID3D12DescriptorHeap* ppHeaps[] = { heap.Get() }; | |
| list->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps); | |
| list->SetGraphicsRootDescriptorTable(0, heap->GetGPUDescriptorHandleForHeapStart()); | |
| } |
This file contains hidden or 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
| ComPtr<ID3D12DescriptorHeap> afCreateDescriptorHeap(int numSrvs, ComPtr<ID3D12Resource> srvs[]) | |
| { | |
| ComPtr<ID3D12DescriptorHeap> heap; | |
| D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {}; | |
| srvHeapDesc.NumDescriptors = numSrvs; | |
| srvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; | |
| srvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; | |
| HRESULT hr = deviceMan.GetDevice()->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(&heap)); | |
| assert(hr == S_OK); | |
| for (int i = 0; i < numSrvs; i++) { |
This file contains hidden or 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
| ComPtr<ID3D12RootSignature> afCreateRootSignature(int numDescriptors, D3D12_DESCRIPTOR_RANGE descriptors[], int numSamplers, D3D12_STATIC_SAMPLER_DESC samplers[]) | |
| { | |
| ComPtr<ID3D12RootSignature> rs; | |
| ComPtr<ID3DBlob> signature; | |
| ComPtr<ID3DBlob> error; | |
| D3D12_ROOT_PARAMETER rootParameter = {}; | |
| rootParameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; | |
| rootParameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; | |
| rootParameter.DescriptorTable.NumDescriptorRanges = numDescriptors; |
This file contains hidden or 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
| class CSampler : public D3D12_STATIC_SAMPLER_DESC | |
| { | |
| public: | |
| CSampler(int shaderRegister, D3D12_FILTER samplerFilter, D3D12_TEXTURE_ADDRESS_MODE wrap) | |
| { | |
| Filter = samplerFilter; | |
| AddressU = wrap; | |
| AddressV = wrap; | |
| AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP; | |
| MipLODBias = 0; |
This file contains hidden or 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
| ID3D12GraphicsCommandList* list = deviceMan.GetCommandList(); | |
| list->SetPipelineState(pipelineState.Get()); | |
| list->SetGraphicsRootSignature(rootSignature.Get()); | |
| afSetDescriptorHeap(heap); | |
| afWriteBuffer(uboId, &invVP, sizeof(invVP)); | |
| list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); |
This file contains hidden or 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
| ComPtr<ID3D12Resource> texId = afLoadTexture(texFileName, texDesc); | |
| ComPtr<ID3D12Resource> uboId = afCreateUBO(sizeof(Mat)); | |
| ComPtr<ID3D12Resource> srvs[] = { | |
| uboId, | |
| texId, | |
| }; | |
| ComPtr<ID3D12DescriptorHeap> heap = afCreateDescriptorHeap(dimof(srvs), srvs); |
This file contains hidden or 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
| D3D12_DESCRIPTOR_RANGE descriptors[] = { // The descriptor table | |
| CDescriptorCBV(0), // constant buffer view bound to register b0 | |
| CDescriptorSRV(0), // shader resource view bound to register t0 | |
| }; | |
| D3D12_STATIC_SAMPLER_DESC samplers[] = { | |
| CSampler(0, D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_TEXTURE_ADDRESS_MODE_WRAP), // sampler bound to register s0 | |
| }; | |
| ComPtr<ID3D12RootSignature> rootSignature = afCreateRootSignature(dimof(descriptors), descriptors, dimof(samplers), samplers); | |
| ComPtr<ID3D12PipelineState> pipelineState = afCreatePSO(shader, nullptr, 0, BM_NONE, DSM_DEPTH_CLOSEREQUAL_READONLY, CM_DISABLE, rootSignature); |
This file contains hidden or 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
| #version 310 es | |
| precision highp float; | |
| in vec3 POSITION; | |
| in vec2 TEXCOORD; | |
| in vec4 COLOR; | |
| out vec2 texcoord; | |
| out vec4 color; | |
| layout (binding = 0) uniform matUbo { | |
| layout (row_major) mat4 matProj; |
This file contains hidden or 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
| void afSetVertexAttributes(const InputElement elements[], int numElements, int numBuffers, GLuint const vertexBufferIds[], const int strides[]) | |
| { | |
| for (int i = 0; i < numElements; i++) { | |
| const InputElement& d = elements[i]; | |
| glBindBuffer(GL_ARRAY_BUFFER, vertexBufferIds[d.inputSlot]); | |
| GLenum r = glGetError(); | |
| if (r != GL_NO_ERROR) { | |
| aflog("glBindBuffer error! i=%d inputSlot=%d vbo=%d\n", i, d.inputSlot, vertexBufferIds[d.inputSlot].x); | |
| } | |
| afHandleGLError(glEnableVertexAttribArray(i)); |