Skip to content

Commit 9440832

Browse files
Merge pull request vsg-dev#1604 from vsg-dev/mipmap_refinement
Refactored mipmap layout handling with introduction of dedicated vsg::MipmapLayout class.
2 parents c5e3c22 + 57f3ac5 commit 9440832

34 files changed

Lines changed: 806 additions & 392 deletions

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cmake_minimum_required(VERSION 3.7)
22

33
project(vsg
4-
VERSION 1.1.11
4+
VERSION 1.1.12
55
DESCRIPTION "VulkanSceneGraph library"
66
LANGUAGES CXX
77
)
8-
set(VSG_SOVERSION 14)
8+
set(VSG_SOVERSION 15)
99
SET(VSG_RELEASE_CANDIDATE 0)
1010
set(Vulkan_MIN_VERSION 1.1.70.0)
1111

include/vsg/all.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
2727
#include <vsg/core/IntrusiveAllocator.h>
2828
#include <vsg/core/Mask.h>
2929
#include <vsg/core/MemorySlots.h>
30+
#include <vsg/core/MipmapLayout.h>
3031
#include <vsg/core/Object.h>
3132
#include <vsg/core/Objects.h>
3233
#include <vsg/core/ScratchMemory.h>

include/vsg/app/RecordTraversal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ namespace vsg
170170
// clear the bins to record a new frame.
171171
void clearBins();
172172

173-
174173
// list of pairs of modelview matrix & region of interest
175174
std::vector<std::pair<dmat4, const RegionOfInterest*>> regionsOfInterest;
176175

include/vsg/app/TransferTask.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,7 @@ namespace vsg
118118
};
119119
VSG_type_name(vsg::TransferTask);
120120

121+
/// convenience function that uploads staging buffer data to device including mipmaps.
122+
extern VSG_DECLSPEC void transferImageData(ref_ptr<ImageView> imageView, VkImageLayout targetImageLayout, Data::Properties properties, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevels, ref_ptr<Buffer> stagingBuffer, VkDeviceSize stagingBufferOffset, VkCommandBuffer vk_commandBuffer, vsg::Device* device);
123+
121124
} // namespace vsg

include/vsg/commands/CopyAndReleaseImage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace vsg
4040
uint32_t width = 0;
4141
uint32_t height = 0;
4242
uint32_t depth = 0;
43-
Data::MipmapOffsets mipmapOffsets;
4443

4544
void record(CommandBuffer& commandBuffer) const;
4645
};

include/vsg/core/Array.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
3131

3232
namespace vsg
3333
{
34-
3534
template<typename T>
3635
class Array : public Data
3736
{
@@ -63,10 +62,14 @@ namespace vsg
6362
_data(_allocate(numElements)),
6463
_size(numElements) { dirty(); }
6564

66-
Array(uint32_t numElements, value_type* data, Properties in_properties = {}) :
65+
Array(uint32_t numElements, value_type* data, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr) :
6766
Data(in_properties, sizeof(value_type)),
6867
_data(data),
69-
_size(numElements) { dirty(); }
68+
_size(numElements)
69+
{
70+
setMipmapLayout(mipmapLayout);
71+
dirty();
72+
}
7073

7174
Array(uint32_t numElements, const value_type& value, Properties in_properties = {}) :
7275
Data(in_properties, sizeof(value_type)),
@@ -77,12 +80,12 @@ namespace vsg
7780
dirty();
7881
}
7982

80-
Array(ref_ptr<Data> data, uint32_t offset, uint32_t stride, uint32_t numElements, Properties in_properties = {}) :
83+
Array(ref_ptr<Data> data, uint32_t offset, uint32_t stride, uint32_t numElements, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr) :
8184
Data(),
8285
_data(nullptr),
8386
_size(0)
8487
{
85-
assign(data, offset, stride, numElements, in_properties);
88+
assign(data, offset, stride, numElements, in_properties, mipmapLayout);
8689
}
8790

8891
explicit Array(std::initializer_list<value_type> l) :
@@ -165,7 +168,10 @@ namespace vsg
165168

166169
if (input.matchPropertyName("data"))
167170
{
168-
size_t new_total_size = computeValueCountIncludingMipmaps(width_size, 1, 1, properties.maxNumMipmaps);
171+
properties.stride = sizeof(value_type);
172+
_size = width_size;
173+
_storage = nullptr;
174+
size_t new_total_size = computeValueCountIncludingMipmaps();
169175

170176
if (_data) // if data exists already may be able to reuse it
171177
{
@@ -181,10 +187,6 @@ namespace vsg
181187
_data = _allocate(new_total_size);
182188
}
183189

184-
properties.stride = sizeof(value_type);
185-
_size = width_size;
186-
_storage = nullptr;
187-
188190
if (_data) input.read(new_total_size, _data);
189191

190192
dirty();
@@ -209,7 +211,7 @@ namespace vsg
209211
output.writeEndOfLine();
210212
}
211213

212-
size_t size() const { return (properties.maxNumMipmaps <= 1) ? _size : computeValueCountIncludingMipmaps(_size, 1, 1, properties.maxNumMipmaps); }
214+
size_t size() const { return (properties.mipLevels <= 1) ? _size : computeValueCountIncludingMipmaps(); }
213215

214216
bool available() const { return _data != nullptr; }
215217
bool empty() const { return _data == nullptr; }
@@ -229,7 +231,8 @@ namespace vsg
229231

230232
clear();
231233

232-
properties = rhs.properties;
234+
_copy(rhs);
235+
233236
_size = rhs._size;
234237

235238
if (_size != 0)
@@ -244,7 +247,7 @@ namespace vsg
244247
return *this;
245248
}
246249

247-
void assign(uint32_t numElements, value_type* data, Properties in_properties = {})
250+
void assign(uint32_t numElements, value_type* data, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr)
248251
{
249252
_delete();
250253

@@ -254,10 +257,12 @@ namespace vsg
254257
_data = data;
255258
_storage = nullptr;
256259

260+
setMipmapLayout(mipmapLayout);
261+
257262
dirty();
258263
}
259264

260-
void assign(ref_ptr<Data> storage, uint32_t offset, uint32_t stride, uint32_t numElements, Properties in_properties = {})
265+
void assign(ref_ptr<Data> storage, uint32_t offset, uint32_t stride, uint32_t numElements, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr)
261266
{
262267
_delete();
263268

@@ -275,6 +280,8 @@ namespace vsg
275280
_size = 0;
276281
}
277282

283+
setMipmapLayout(mipmapLayout);
284+
278285
dirty();
279286
}
280287

@@ -365,6 +372,8 @@ namespace vsg
365372
else if (properties.allocatorType != 0)
366373
vsg::deallocate(_data);
367374
}
375+
376+
_clear();
368377
}
369378

370379
private:

include/vsg/core/Array2D.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1313
</editor-fold> */
1414

1515
#include <vsg/core/Data.h>
16-
1716
#include <vsg/maths/mat4.h>
1817
#include <vsg/maths/vec2.h>
1918
#include <vsg/maths/vec3.h>
@@ -68,11 +67,15 @@ namespace vsg
6867
dirty();
6968
}
7069

71-
Array2D(uint32_t width, uint32_t height, value_type* data, Properties in_properties = {}) :
70+
Array2D(uint32_t width, uint32_t height, value_type* data, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr) :
7271
Data(in_properties, sizeof(value_type)),
7372
_data(data),
7473
_width(width),
75-
_height(height) { dirty(); }
74+
_height(height)
75+
{
76+
setMipmapLayout(mipmapLayout);
77+
dirty();
78+
}
7679

7780
Array2D(uint32_t width, uint32_t height, const value_type& value, Properties in_properties = {}) :
7881
Data(in_properties, sizeof(value_type)),
@@ -88,13 +91,13 @@ namespace vsg
8891
}
8992
}
9093

91-
Array2D(ref_ptr<Data> data, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {}) :
94+
Array2D(ref_ptr<Data> data, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr) :
9295
Data(),
9396
_data(nullptr),
9497
_width(0),
9598
_height(0)
9699
{
97-
assign(data, offset, stride, width, height, in_properties);
100+
assign(data, offset, stride, width, height, in_properties, mipmapLayout);
98101
}
99102

100103
template<typename... Args>
@@ -144,7 +147,12 @@ namespace vsg
144147

145148
if (input.matchPropertyName("data"))
146149
{
147-
size_t new_size = computeValueCountIncludingMipmaps(w, h, 1, properties.maxNumMipmaps);
150+
properties.stride = sizeof(value_type);
151+
_width = w;
152+
_height = h;
153+
_storage = nullptr;
154+
155+
size_t new_size = computeValueCountIncludingMipmaps();
148156

149157
if (_data) // if data exists already may be able to reuse it
150158
{
@@ -159,11 +167,6 @@ namespace vsg
159167
_data = _allocate(new_size);
160168
}
161169

162-
properties.stride = sizeof(value_type);
163-
_width = w;
164-
_height = h;
165-
_storage = nullptr;
166-
167170
if (_data) input.read(new_size, _data);
168171

169172
dirty();
@@ -190,7 +193,7 @@ namespace vsg
190193
output.writeEndOfLine();
191194
}
192195

193-
size_t size() const { return (properties.maxNumMipmaps <= 1) ? (static_cast<size_t>(_width) * static_cast<size_t>(_height)) : computeValueCountIncludingMipmaps(_width, _height, 1, properties.maxNumMipmaps); }
196+
size_t size() const { return (properties.mipLevels <= 1) ? (static_cast<size_t>(_width) * static_cast<size_t>(_height)) : computeValueCountIncludingMipmaps(); }
194197

195198
bool available() const { return _data != nullptr; }
196199
bool empty() const { return _data == nullptr; }
@@ -211,7 +214,8 @@ namespace vsg
211214

212215
clear();
213216

214-
properties = rhs.properties;
217+
_copy(rhs);
218+
215219
_width = rhs._width;
216220
_height = rhs._height;
217221

@@ -227,7 +231,7 @@ namespace vsg
227231
return *this;
228232
}
229233

230-
void assign(uint32_t width, uint32_t height, value_type* data, Properties in_properties = {})
234+
void assign(uint32_t width, uint32_t height, value_type* data, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr)
231235
{
232236
_delete();
233237

@@ -238,10 +242,12 @@ namespace vsg
238242
_data = data;
239243
_storage = nullptr;
240244

245+
setMipmapLayout(mipmapLayout);
246+
241247
dirty();
242248
}
243249

244-
void assign(ref_ptr<Data> storage, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {})
250+
void assign(ref_ptr<Data> storage, uint32_t offset, uint32_t stride, uint32_t width, uint32_t height, Properties in_properties = {}, MipmapLayout* mipmapLayout = nullptr)
245251
{
246252
_delete();
247253

@@ -261,6 +267,8 @@ namespace vsg
261267
_height = 0;
262268
}
263269

270+
setMipmapLayout(mipmapLayout);
271+
264272
dirty();
265273
}
266274

@@ -360,6 +368,8 @@ namespace vsg
360368
else if (properties.allocatorType != 0)
361369
vsg::deallocate(_data);
362370
}
371+
372+
_clear();
363373
}
364374

365375
private:

0 commit comments

Comments
 (0)