forked from themrdemonized/xray-monolith
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputeShader.cpp
More file actions
97 lines (78 loc) · 2.35 KB
/
ComputeShader.cpp
File metadata and controls
97 lines (78 loc) · 2.35 KB
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
////////////////////////////////////////////////////////////////////////////
// Created : 21.05.2009
// Author : Mykhailo Parfeniuk
// Copyright (C) GSC Game World - 2009
////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ComputeShader.h"
void ComputeShader::Construct(
ID3D11ComputeShader* cs,
ref_ctable ctable,
xr_vector<ID3D11SamplerState*>& Samplers,
xr_vector<ID3D11ShaderResourceView*>& Textures,
xr_vector<ID3D11UnorderedAccessView*>& Outputs
)
{
m_cs = cs;
m_ctable = ctable;
m_Textures.swap(Textures);
m_Outputs.swap(Outputs);
m_Samplers.swap(Samplers);
}
ComputeShader::~ComputeShader()
{
for (size_t i = 0; i < m_Textures.size(); ++i)
m_Textures[i]->Release();
for (size_t i = 0; i < m_Outputs.size(); ++i)
m_Outputs[i]->Release();
for (size_t i = 0; i < m_Samplers.size(); ++i)
m_Samplers[i]->Release();
}
u32 GetCB(R_constant* C)
{
return (C->destination & RC_dest_pixel_cb_index_mask) >> RC_dest_pixel_cb_index_shift;
}
ComputeShader& ComputeShader::set_c(shared_str name, const Fvector4& value)
{
R_constant* c = m_ctable->get(name);
m_ctable->m_CBTable[GetCB(c)].second->set(c, c->ps, value);
return *this;
}
ComputeShader& ComputeShader::set_c(shared_str name, float x, float y, float z, float w)
{
Fvector4 vec;
vec.set(x, y, z, w);
return set_c(name, vec);
}
void ComputeShader::Dispatch(u32 dimx, u32 dimy, u32 dimz)
{
u32 count = m_ctable->m_CBTable.size();
for (u32 i = 0; i < count; ++i)
{
m_ctable->m_CBTable[i].second->Flush();
}
ID3DBuffer* tempBuffer[CBackend::MaxCBuffers];
for (u32 i = 0; i < count; ++i)
{
tempBuffer[i] = m_ctable->m_CBTable[i].second->GetBuffer();
}
// process constant-loaders
R_constant_table::c_table::iterator it = m_ctable->table.begin();
R_constant_table::c_table::iterator end = m_ctable->table.end();
for (; it != end; it++)
{
R_constant* Cs = &**it;
if (Cs->handler) Cs->handler->setup(Cs);
}
HW.pContext->CSSetConstantBuffers(0, count, tempBuffer);
if (!m_Textures.empty())
HW.pContext->CSSetShaderResources(0, m_Textures.size(), &m_Textures[0]);
if (!m_Samplers.empty())
HW.pContext->CSSetSamplers(0, m_Samplers.size(), &m_Samplers[0]);
if (!m_Outputs.empty())
{
UINT num = 0;
HW.pContext->CSSetUnorderedAccessViews(0, m_Outputs.size(), &m_Outputs[0], &num);
}
HW.pContext->Dispatch(dimx, dimy, dimz);
}