-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathEsramVisualizeEffect.cpp
98 lines (75 loc) · 3.55 KB
/
EsramVisualizeEffect.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
96
97
98
//--------------------------------------------------------------------------------------
// EsramVisualizeEffect.cpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "EsramVisualizeEffect.h"
using namespace DirectX;
using namespace Microsoft::WRL;
namespace ATG
{
const wchar_t* EsramVisualizeEffect::s_shaderFilename = L"EsramVisualize_CS.cso";
const XMINT2 EsramVisualizeEffect::s_groupSize = XMINT2(8, 8);
EsramVisualizeEffect::EsramVisualizeEffect(ID3D12Device* device)
{
assert(device != nullptr);
auto shaderBlob = DX::ReadData(s_shaderFilename);
// Xbox One best practice is to use HLSL-based root signatures to support shader precompilation.
DX::ThrowIfFailed(
device->CreateRootSignature(0, shaderBlob.data(), shaderBlob.size(),
IID_GRAPHICS_PPV_ARGS(m_rootSignature.ReleaseAndGetAddressOf())));
SetDebugObjectName(m_rootSignature.Get(), L"EsramVisualizeEffect");
D3D12_COMPUTE_PIPELINE_STATE_DESC desc = {};
desc.pRootSignature = m_rootSignature.Get();
desc.CS = { shaderBlob.data(), shaderBlob.size() };
DX::ThrowIfFailed(device->CreateComputePipelineState(&desc, IID_GRAPHICS_PPV_ARGS(m_pipelineState.GetAddressOf())));
SetDebugObjectName(m_pipelineState.Get(), L"EsramVisualizeEffect");
}
void EsramVisualizeEffect::Process(ID3D12GraphicsCommandList* commandList)
{
// Set pipeline
commandList->SetComputeRootSignature(m_rootSignature.Get());
commandList->SetPipelineState(m_pipelineState.Get());
// Set constant buffer
if (m_dirtyFlag)
{
ComPtr<ID3D12Device> device;
commandList->GetDevice(IID_GRAPHICS_PPV_ARGS(device.GetAddressOf()));
m_dirtyFlag = false;
m_constantBuffer = GraphicsMemory::Get(device.Get()).AllocateConstant(m_constants);
}
commandList->SetComputeRootConstantBufferView(RootParameterIndex::ConstantBuffer, m_constantBuffer.GpuAddress());
// Set UAV texture
commandList->SetComputeRootDescriptorTable(RootParameterIndex::TextureUAV, m_texture);
// Dispatch
int width = m_constants.bounds.z - m_constants.bounds.x;
int height = m_constants.bounds.w - m_constants.bounds.y;
int threadGroupX = (width - 1) / s_groupSize.x + 1;
int threadGroupY = (height - 1) / s_groupSize.y + 1;
commandList->Dispatch(threadGroupX, threadGroupY, 1);
}
void EsramVisualizeEffect::SetConstants(const Constants& constants)
{
// Do some good ol' validation.
assert(constants.bounds.x < constants.bounds.z && constants.bounds.y < constants.bounds.w);
assert(constants.selectedIndex >= 0 && constants.selectedIndex < _countof(Constants::textures));
for (int i = 0; i < _countof(Constants::textures); ++i)
{
auto& tex = constants.textures[i];
assert(tex.timeRange.x <= tex.timeRange.y);
assert(tex.pageRangeCount >= 0 && tex.pageRangeCount < _countof(Constants::Texture::pageRanges));
for (int j = 0; j < tex.pageRangeCount; ++j)
{
assert(tex.pageRanges[j].x < tex.pageRanges[j].y);
}
}
m_dirtyFlag = true;
m_constants = constants;
}
void EsramVisualizeEffect::SetTexture(D3D12_GPU_DESCRIPTOR_HANDLE handle)
{
m_texture = handle;
}
}