Skip to content

Commit b21ebbf

Browse files
committed
DXFramework warnings fixed
1 parent 6ddc983 commit b21ebbf

File tree

10 files changed

+80
-78
lines changed

10 files changed

+80
-78
lines changed

Core/Math/Vectors.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,12 @@ Vector<T> operator/(float n, Vector<T> v)
282282
return v;
283283
}
284284

285-
template<typename T>
286-
Vector<T> operator/(Vector<T> v, float n)
285+
template<typename T, typename T2>
286+
Vector<T> operator/(Vector<T> v, T2 n)
287287
{
288-
v /= n;
288+
for (int i = 0; i < T::N; ++i)
289+
v[i] = static_cast<typename T::Format>(static_cast<T2>(v[i])/n);
290+
289291
return v;
290292
}
291293

DirectXFramework/DX12/Buffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace DX12
4545
srv.Buffer.FirstElement = 0;
4646
srv.Buffer.Flags = D3D12_BUFFER_SRV_FLAGS::D3D12_BUFFER_SRV_FLAG_NONE;
4747
srv.Buffer.StructureByteStride = 0;
48-
srv.Buffer.NumElements = count / sizeof(vec4);
48+
srv.Buffer.NumElements = static_cast<UINT>(count / sizeof(vec4));
4949
Device::get().get_native_device()->CreateShaderResourceView(get_native().Get(), &srv, handle.cpu);
5050
}
5151

@@ -54,7 +54,7 @@ namespace DX12
5454
D3D12_UNORDERED_ACCESS_VIEW_DESC desc = {};
5555
desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
5656
desc.Format = DXGI_FORMAT_UNKNOWN;
57-
desc.Buffer.NumElements = count;
57+
desc.Buffer.NumElements = static_cast<UINT>(count);
5858
desc.Buffer.StructureByteStride = stride;
5959
desc.Buffer.CounterOffsetInBytes = offset;
6060
desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
@@ -74,7 +74,7 @@ namespace DX12
7474
{
7575
return static_uav;
7676
}
77-
UINT GPUBuffer::get_count()
77+
UINT64 GPUBuffer::get_count()
7878
{
7979
return count;
8080
}
@@ -99,7 +99,7 @@ namespace DX12
9999
D3D12_UNORDERED_ACCESS_VIEW_DESC desc = {};
100100
desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
101101
desc.Format = DXGI_FORMAT_R32_TYPELESS;
102-
desc.Buffer.NumElements = count / 4;
102+
desc.Buffer.NumElements = static_cast<UINT>(count / 4);
103103
desc.Buffer.StructureByteStride = 0;
104104
desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
105105
Device::get().get_native_device()->CreateUnorderedAccessView(get_native().Get(), nullptr, &desc, h.cpu);
@@ -111,7 +111,7 @@ namespace DX12
111111
desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
112112
desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
113113
desc.Format = DXGI_FORMAT_R32_TYPELESS;
114-
desc.Buffer.NumElements = count / 4;
114+
desc.Buffer.NumElements = static_cast<UINT>(count / 4);
115115
desc.Buffer.StructureByteStride = 0;
116116
desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
117117
Device::get().get_native_device()->CreateShaderResourceView(get_native().Get(), &desc, h.cpu);
@@ -129,7 +129,7 @@ namespace DX12
129129
D3D12_INDEX_BUFFER_VIEW view;
130130
view.BufferLocation = get_gpu_address() + offset;
131131
view.Format = is_32 ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT;
132-
view.SizeInBytes = size ? size : this->size;
132+
view.SizeInBytes = static_cast<UINT>(size ? size : this->size);
133133
return view;
134134
}
135135

DirectXFramework/DX12/Buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace DX12
7474
const HandleTable& get_srv();
7575
const HandleTable& get_uav();
7676
const HandleTable& get_static_uav();
77-
UINT get_count();
77+
UINT64 get_count();
7878

7979
template<class T>
8080
void set_raw_data(std::vector<T>& v)

DirectXFramework/DX12/CommandList.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ namespace DX12
353353
{
354354
base.flush_transitions();
355355
D3D12_RESOURCE_DESC Desc = resource->get_desc();
356-
int rows_count = box.y;
356+
UINT rows_count = box.y;
357357

358358
if (Desc.Format == DXGI_FORMAT_BC7_UNORM_SRGB || Desc.Format == DXGI_FORMAT_BC7_UNORM)
359359
rows_count /= 4;
@@ -458,8 +458,8 @@ namespace DX12
458458
return str.get_future();
459459
}
460460

461-
int res_stride = RowSizesInBytes + (D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (RowSizesInBytes) % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
462-
int size = res_stride * box.y * box.z;
461+
UINT res_stride = static_cast<UINT>(RowSizesInBytes + (D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (RowSizesInBytes) % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT));
462+
UINT size = res_stride * box.y * box.z;
463463
auto info = base.read_data(size);
464464
CD3DX12_TEXTURE_COPY_LOCATION source(resource->get_native().Get(), sub_resource);
465465
CD3DX12_TEXTURE_COPY_LOCATION dest;
@@ -1226,7 +1226,7 @@ void ComputeContext::dispach(int x,int y,int z)
12261226
{
12271227
m_commandAllocator->Reset();
12281228
m_commandList->Reset(m_commandAllocator.Get(), nullptr);
1229-
m_commandList->ResourceBarrier(transitions.size(), transitions.data());
1229+
m_commandList->ResourceBarrier(static_cast<UINT>(transitions.size()), transitions.data());
12301230
m_commandList->Close();
12311231
}
12321232

DirectXFramework/DX12/Resource.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace DX12
44
{
5-
static std::atomic_int counter[3] = {0, 0, 0};
6-
std::atomic_int counter_id;
5+
static std::atomic_size_t counter[3] = {0, 0, 0};
6+
std::atomic_size_t counter_id;
77
DescriptorHeap::DescriptorHeap(UINT num, DescriptorHeapType type, DescriptorHeapFlags flags)
88
{
99
max_count = num;
@@ -251,47 +251,47 @@ namespace DX12
251251

252252
pages.clear();
253253
}
254-
void DynamicDescriptorManager::set(int i, int offset, std::vector<Handle>& h)
254+
void DynamicDescriptorManager::set(UINT i, UINT offset, std::vector<Handle>& h)
255255
{
256256

257257
if (h.size() == 0) return;
258258
if (!root_tables[i].fixed)
259259
root_tables[i].handles.resize(h.size());
260260

261-
for(int j=0;j<h.size();j++)
261+
for(size_t j=0;j<h.size();j++)
262262
root_tables[i].handles[offset+j] = h[j];
263263
root_tables[i].changed = true;
264264
}
265-
void DynamicDescriptorManager::set(int i, int offset, Handle h)
265+
void DynamicDescriptorManager::set(UINT i, UINT offset, Handle h)
266266
{
267267
if ((!root_tables[i].fixed)&&root_tables[i].handles.size()<=offset)
268268
root_tables[i].handles.resize(offset+1);
269269

270270
root_tables[i].handles[offset] = h;
271271
root_tables[i].changed = true;
272272
}
273-
void DynamicDescriptorManager::set(int i, int offset, HandleTable h)
273+
void DynamicDescriptorManager::set(UINT i, UINT offset, HandleTable h)
274274
{
275275
if (h.get_count() == 0) return;
276276
if ((!root_tables[i].fixed)&&root_tables[i].handles.size() <= offset+h.get_count())
277277
root_tables[i].handles.resize(offset + h.get_count() + 1);
278278

279-
for(int j=0;j<std::min(root_tables[i].handles.size(),size_t(offset+h.get_count()))- offset;j++)
279+
for(UINT j=0;j<std::min(static_cast<UINT>(root_tables[i].handles.size()),offset+h.get_count())- offset;j++)
280280
root_tables[i].handles[offset+j] = h[j];
281281
root_tables[i].changed = true;
282282
}
283-
bool DynamicDescriptorManager::has_free_size(int count)
283+
bool DynamicDescriptorManager::has_free_size(UINT count)
284284
{
285-
return (!pages.empty() && offset + count < pages.back()->size());
285+
return (!pages.empty() && (offset + count < pages.back()->size()));
286286
}
287287

288-
int DynamicDescriptorManager::calculate_needed_size()
288+
UINT DynamicDescriptorManager::calculate_needed_size()
289289
{
290-
int size = 0;
290+
UINT size = 0;
291291
for (auto &e : root_tables)
292292
{
293293
if (!e.second.changed) continue;
294-
size += e.second.handles.size();
294+
size += static_cast<UINT>(e.second.handles.size());
295295
}
296296
return size;
297297
}
@@ -327,7 +327,7 @@ namespace DX12
327327
return table[0];
328328
}
329329

330-
void DynamicDescriptorManager::bind(CommandList * list, std::function<void(int, Handle)> f)
330+
void DynamicDescriptorManager::bind(CommandList * list, std::function<void(UINT, Handle)> f)
331331
{
332332
int needed_size = calculate_needed_size();
333333

@@ -349,22 +349,22 @@ namespace DX12
349349
{
350350
if (!e.second.changed) continue;
351351

352-
auto table = heap->get_table_view(offset, e.second.handles.size());
352+
auto table = heap->get_table_view(offset, static_cast<UINT>(e.second.handles.size()));
353353

354354
for (unsigned int j = 0; j < e.second.handles.size(); j++)
355355
if (e.second.handles[j].is_valid())
356356
table[j].place(e.second.handles[j]);
357357

358358
e.second.changed = false;
359359
f(e.first, table[0]);
360-
offset += e.second.handles.size();
360+
offset += static_cast<UINT>(e.second.handles.size());
361361

362362
// if (!e.second.fixed)
363363
// e.second.handles.resize(e.second.count);
364364
}
365365
}
366366

367-
void DynamicDescriptorManager::bind_table(int i, std::vector<Handle>& h)
367+
void DynamicDescriptorManager::bind_table(UINT i, std::vector<Handle>& h)
368368
{
369369
// root_tables[i].changed = true;
370370
// swap(root_tables[i].handles, h);

DirectXFramework/DX12/Resource.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ namespace DX12
131131
ComPtr<ID3D12DescriptorHeap> m_rtvHeap;
132132

133133
UINT descriptor_size;
134-
int current_offset = 0;
135-
int max_count;
134+
UINT current_offset = 0;
135+
UINT max_count;
136136
std::mutex m;
137-
std::map<int, std::deque<int>> frees;
138-
HandleTable make_table(int count, int offset)
137+
std::map<UINT, std::deque<UINT>> frees;
138+
HandleTable make_table(UINT count, UINT offset)
139139
{
140140
HandleTable res;
141141
std::weak_ptr<DescriptorHeap> ptr = shared_from_this();
@@ -155,13 +155,13 @@ namespace DX12
155155
return res;
156156
}
157157
template<class T>
158-
void place(HandleTable& table, int i, T smth)
158+
void place(HandleTable& table, UINT i, T smth)
159159
{
160160
smth(table[i]);
161161
}
162162

163163
template<class T, class ...Args>
164-
void place(HandleTable& table, int i, T smth, Args...args)
164+
void place(HandleTable& table, UINT i, T smth, Args...args)
165165
{
166166
place(table, i, smth);
167167
place(table, i + 1, args...);
@@ -183,7 +183,7 @@ namespace DX12
183183
current_offset = 0;
184184
}
185185

186-
int size()
186+
size_t size()
187187
{
188188
return max_count;
189189
}
@@ -196,7 +196,7 @@ namespace DX12
196196
if (frees[count].size())
197197
{
198198
auto&& list = frees[count];
199-
int offset = list.front();
199+
UINT offset = list.front();
200200
list.pop_front();
201201
return make_table(count, offset);
202202
}
@@ -213,13 +213,13 @@ namespace DX12
213213
template<class ...Args>
214214
HandleTable create_table(Args... t)
215215
{
216-
const int count = sizeof...(t);
216+
const size_t count = sizeof...(t);
217217
std::lock_guard<std::mutex> g(m);
218218

219219
if (frees[count].size())
220220
{
221221
auto&& list = frees[count];
222-
int offset = list.front();
222+
size_t offset = list.front();
223223
list.pop_front();
224224
return make_table(count, offset);
225225
}
@@ -236,7 +236,7 @@ namespace DX12
236236
CD3DX12_CPU_DESCRIPTOR_HANDLE get_handle(UINT i);
237237
CD3DX12_GPU_DESCRIPTOR_HANDLE get_gpu_handle(UINT i);
238238

239-
HandleTable get_table_view(int offset, int count)
239+
HandleTable get_table_view(UINT offset, UINT count)
240240
{
241241
assert((offset + count) <= max_count && "Not enought handles");
242242
HandleTable res;
@@ -300,7 +300,7 @@ namespace DX12
300300
{
301301
std::vector<DescriptorHeap::ptr> pages;
302302

303-
unsigned int offset;
303+
UINT offset;
304304
// std::vector<bool> setted;
305305
// std::vector<int> offsets;
306306

@@ -310,10 +310,10 @@ namespace DX12
310310
std::vector<Handle> handles;
311311
bool changed;
312312
bool fixed;
313-
int count;
313+
UINT count;
314314
};
315315

316-
std::map<int, row> root_tables;
316+
std::map<UINT, row> root_tables;
317317
//static std::mutex free_mutex;
318318

319319
static DescriptorHeap::ptr get_free_table();
@@ -330,24 +330,24 @@ namespace DX12
330330

331331
void reset();
332332

333-
void set(int i, int offset, Handle h);
334-
void set(int i, int offset, HandleTable h);
335-
void set(int i, int offset, std::vector<Handle>& h);
336-
Handle& get(int i, int offset)
333+
void set(UINT i, UINT offset, Handle h);
334+
void set(UINT i, UINT offset, HandleTable h);
335+
void set(UINT i, UINT offset, std::vector<Handle>& h);
336+
Handle& get(UINT i, UINT offset)
337337
{
338338
return root_tables[i].handles[offset];
339339
}
340340

341341
Handle place(const Handle &h);
342-
bool has_free_size(int count);
342+
bool has_free_size(UINT count);
343343

344344

345-
int calculate_needed_size();
345+
UINT calculate_needed_size();
346346

347347
void unbind_all();
348-
void bind(CommandList * list, std::function<void(int, Handle)> f);
348+
void bind(CommandList * list, std::function<void(UINT, Handle)> f);
349349
void bind(CommandList * list);
350-
void bind_table(int i, std::vector<Handle>& h);
350+
void bind_table(UINT i, std::vector<Handle>& h);
351351
/*void set(int i, int offset, HandleTable h)
352352
{
353353
handles[i][offset] = h;
@@ -560,7 +560,7 @@ namespace DX12
560560
D3D12_GPU_VIRTUAL_ADDRESS gpu_adress;
561561
HeapType heap_type;
562562
// std::vector< unsigned int> states;
563-
int id=0;
563+
size_t id=0;
564564

565565
/*unsigned int states;*/
566566
protected:

DirectXFramework/DX12/RootSignature.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ namespace DX12
124124
{
125125
CD3DX12_ROOT_PARAMETER& param;
126126
CD3DX12_DESCRIPTOR_RANGE& range;
127-
std::map<size_t, table_info>& tables;
128-
size_t index;
127+
std::map<UINT, table_info>& tables;
128+
UINT index;
129129

130130

131131
void operator=(const DescriptorTable& table)
@@ -156,7 +156,7 @@ namespace DX12
156156
{
157157
param.InitAsConstants(table.count, table.buffer_offset, 0, static_cast<D3D12_SHADER_VISIBILITY>(table.visibility));
158158
}
159-
helper(size_t index, CD3DX12_ROOT_PARAMETER& _param, CD3DX12_DESCRIPTOR_RANGE& _range, std::map<size_t, table_info>& tables): index(index), param(_param), range(_range), tables(tables)
159+
helper(UINT index, CD3DX12_ROOT_PARAMETER& _param, CD3DX12_DESCRIPTOR_RANGE& _range, std::map<UINT, table_info>& tables): index(index), param(_param), range(_range), tables(tables)
160160
{
161161
}
162162

@@ -165,7 +165,7 @@ namespace DX12
165165
}
166166
};
167167

168-
helper operator[](size_t i)
168+
helper operator[](UINT i)
169169
{
170170
if (i >= parameters.size())
171171
parameters.resize(i + 1);
@@ -217,7 +217,7 @@ namespace DX12
217217
sampler.RegisterSpace = space;
218218
sampler.ShaderRegister = i;
219219
}
220-
std::map<size_t, table_info> tables;
220+
std::map<UINT, table_info> tables;
221221

222222
private:
223223
std::vector<CD3DX12_ROOT_PARAMETER> parameters;

0 commit comments

Comments
 (0)