From: Mikko Rasa Date: Sat, 30 Oct 2021 19:25:15 +0000 (+0300) Subject: Use size_t to store sizes of buffers and such X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=be6ffe96ecb4707599fe1a6f620c348760213d46;p=libs%2Fgl.git Use size_t to store sizes of buffers and such Shader reflection data can stick to 32-bit sizes, since SPIR-V's decorations only take 32-bit operands. --- diff --git a/source/backends/opengl/buffer_backend.cpp b/source/backends/opengl/buffer_backend.cpp index e1bced73..a0404e7b 100644 --- a/source/backends/opengl/buffer_backend.cpp +++ b/source/backends/opengl/buffer_backend.cpp @@ -33,7 +33,7 @@ OpenGLBuffer::~OpenGLBuffer() void OpenGLBuffer::allocate() { - unsigned size = static_cast(this)->size; + size_t size = static_cast(this)->size; if(ARB_buffer_storage) { @@ -55,7 +55,7 @@ void OpenGLBuffer::allocate() } } -void OpenGLBuffer::sub_data(unsigned off, unsigned sz, const void *d) +void OpenGLBuffer::sub_data(size_t off, size_t sz, const void *d) { if(ARB_direct_state_access) glNamedBufferSubData(id, off, sz, d); @@ -70,7 +70,7 @@ void *OpenGLBuffer::map() { static Require _req(ARB_map_buffer_range); - unsigned size = static_cast(this)->size; + size_t size = static_cast(this)->size; if(ARB_direct_state_access) return glMapNamedBufferRange(id, 0, size, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT); diff --git a/source/backends/opengl/buffer_backend.h b/source/backends/opengl/buffer_backend.h index 5db516fb..f435e868 100644 --- a/source/backends/opengl/buffer_backend.h +++ b/source/backends/opengl/buffer_backend.h @@ -21,7 +21,7 @@ protected: ~OpenGLBuffer(); void allocate(); - void sub_data(unsigned, unsigned, const void *); + void sub_data(size_t, size_t, const void *); void *map(); bool unmap(); diff --git a/source/core/batch.cpp b/source/core/batch.cpp index fa28e956..9192b673 100644 --- a/source/core/batch.cpp +++ b/source/core/batch.cpp @@ -167,12 +167,12 @@ void Batch::append_index(unsigned i) ::append(data, i); } -unsigned Batch::get_index_size() const +size_t Batch::get_index_size() const { return (index_type==UNSIGNED_INT ? sizeof(uint32_t) : sizeof(uint16_t)); } -unsigned Batch::get_index(unsigned i) const +unsigned Batch::get_index(size_t i) const { if(index_type==UNSIGNED_INT) return *(uint32_t *)&data[i*sizeof(uint32_t)]; diff --git a/source/core/batch.h b/source/core/batch.h index 9577a542..1e0b4c47 100644 --- a/source/core/batch.h +++ b/source/core/batch.h @@ -52,14 +52,14 @@ public: Batch &append(const Batch &); private: void append_index(unsigned); - virtual unsigned get_data_size() const { return data.size(); } + virtual std::size_t get_data_size() const { return data.size(); } virtual const void *get_data_pointer() const { return &data[0]; } - virtual unsigned get_alignment() const { return get_index_size(); } - unsigned get_index_size() const; + virtual std::size_t get_alignment() const { return get_index_size(); } + std::size_t get_index_size() const; public: - unsigned size() const { return data.size()/get_index_size(); } + std::size_t size() const { return data.size()/get_index_size(); } - unsigned get_index(unsigned) const; + unsigned get_index(std::size_t) const; }; } // namespace GL diff --git a/source/core/buffer.cpp b/source/core/buffer.cpp index 523b737d..557e576d 100644 --- a/source/core/buffer.cpp +++ b/source/core/buffer.cpp @@ -8,7 +8,7 @@ using namespace std; namespace Msp { namespace GL { -void Buffer::storage(unsigned sz) +void Buffer::storage(size_t sz) { if(size>0) { @@ -29,7 +29,7 @@ void Buffer::data(const void *d) return sub_data(0, size, d); } -void Buffer::sub_data(unsigned off, unsigned sz, const void *d) +void Buffer::sub_data(size_t off, size_t sz, const void *d) { if(size==0) throw invalid_operation("Buffer::sub_data"); @@ -37,7 +37,7 @@ void Buffer::sub_data(unsigned off, unsigned sz, const void *d) BufferBackend::sub_data(off, sz, d); } -void Buffer::require_size(unsigned req_sz) const +void Buffer::require_size(size_t req_sz) const { if(sizenext_in_buffer; last=last->next_in_buffer) ; @@ -77,11 +77,11 @@ void Bufferable::unlink_from_buffer() void Bufferable::update_offset() { - unsigned new_offset = 0; + size_t new_offset = 0; if(prev_in_buffer) new_offset = prev_in_buffer->offset+prev_in_buffer->get_data_size(); - unsigned align = get_alignment(); + size_t align = get_alignment(); new_offset += align-1; new_offset -= new_offset%align; if(new_offset!=offset) @@ -105,7 +105,7 @@ void Bufferable::upload_data(char *target) const if(!buffer) throw invalid_operation("Bufferable::upload_data"); - unsigned data_size = get_data_size(); + size_t data_size = get_data_size(); if(location_dirty) { buffer->require_size(offset+data_size); diff --git a/source/core/bufferable.h b/source/core/bufferable.h index f1d52fb3..60ce3072 100644 --- a/source/core/bufferable.h +++ b/source/core/bufferable.h @@ -30,7 +30,7 @@ public: private: Buffer *buffer = 0; - unsigned offset = 0; + std::size_t offset = 0; Bufferable *next_in_buffer = 0; Bufferable *prev_in_buffer = 0; mutable bool location_dirty = false; @@ -50,7 +50,7 @@ public: /** Returns the total amount of storage required by this object and others in the same chain, including any alignment between objects. */ - unsigned get_required_buffer_size() const; + std::size_t get_required_buffer_size() const; /** Uploads new data into the buffer if necessary. */ void refresh() const { if(dirty) upload_data(0); } @@ -67,7 +67,7 @@ public: const Buffer *get_buffer() const { return buffer; } /** Returns the size of the data, in bytes. */ - virtual unsigned get_data_size() const = 0; + virtual std::size_t get_data_size() const = 0; protected: /** Returns a pointer to the start of data in client memory. */ @@ -75,7 +75,7 @@ protected: /** Returns the alignment required for the data, in bytes. The offset is guaranteed to be a multiple of this. */ - virtual unsigned get_alignment() const { return 1; } + virtual std::size_t get_alignment() const { return 1; } /** Updates the offsets for the chain so that data from different objects does not overlap. Should be called if either data size or alignment @@ -84,7 +84,7 @@ protected: public: /** Returns the offset of the data from the beginning of the buffer. */ - unsigned get_offset() const { return offset; } + std::size_t get_offset() const { return offset; } private: /** Uploads data to the buffer. Receives pointer to mapped buffer memory as diff --git a/source/core/datatype.h b/source/core/datatype.h index 8111dd77..a03b6bda 100644 --- a/source/core/datatype.h +++ b/source/core/datatype.h @@ -91,7 +91,7 @@ enum DataType SAMPLER_CUBE_ARRAY_SHADOW = 0x3C0304 }; -inline unsigned get_type_size(DataType t) { return t&0xFF; } +inline std::size_t get_type_size(DataType t) { return t&0xFF; } inline bool is_float(DataType t) { return t&0x200; } inline bool is_matrix(DataType t) { return t&0xC000; } inline bool is_vector(DataType t) { return !is_matrix(t) && (t&0x3000); } diff --git a/source/core/mesh.cpp b/source/core/mesh.cpp index 4679e3a3..ec5bd18c 100644 --- a/source/core/mesh.cpp +++ b/source/core/mesh.cpp @@ -80,12 +80,12 @@ void Mesh::check_buffers(unsigned mask) } } -unsigned Mesh::get_n_vertices() const +size_t Mesh::get_n_vertices() const { return vertices.size(); } -char *Mesh::modify_vertex(unsigned i) +char *Mesh::modify_vertex(size_t i) { if(vertices.get_format().empty()) throw invalid_operation("Mesh::modify_vertex"); diff --git a/source/core/mesh.h b/source/core/mesh.h index 2d56193d..14b08a96 100644 --- a/source/core/mesh.h +++ b/source/core/mesh.h @@ -89,8 +89,8 @@ public: const VertexArray &get_vertices() const { return vertices; } const VertexSetup &get_vertex_setup() const { return vtx_setup; } const Buffer *get_index_buffer() const { return ibuf; } - unsigned get_n_vertices() const; - char *modify_vertex(unsigned); + std::size_t get_n_vertices() const; + char *modify_vertex(std::size_t); void add_batch(const Batch &b); const std::vector &get_batches() const { return batches; } diff --git a/source/core/texture.h b/source/core/texture.h index 154a8c03..c593c0ad 100644 --- a/source/core/texture.h +++ b/source/core/texture.h @@ -94,7 +94,7 @@ public: with the defined storage. Semantics depend on the type of texture. */ virtual void image(const Graphics::Image &, unsigned = 0) = 0; - virtual std::uint64_t get_data_size() const { return 0; } + virtual std::size_t get_data_size() const { return 0; } using TextureBackend::set_debug_name; diff --git a/source/core/texture1d.h b/source/core/texture1d.h index 3823513d..c4230d31 100644 --- a/source/core/texture1d.h +++ b/source/core/texture1d.h @@ -44,7 +44,7 @@ private: public: virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::uint64_t get_data_size() const; + virtual std::size_t get_data_size() const; virtual void unload() { } }; diff --git a/source/core/texture2d.h b/source/core/texture2d.h index 6ae600e7..c6654df6 100644 --- a/source/core/texture2d.h +++ b/source/core/texture2d.h @@ -70,7 +70,7 @@ private: public: virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0); - virtual std::uint64_t get_data_size() const; + virtual std::size_t get_data_size() const; using Texture2DBackend::unload; }; diff --git a/source/core/texture2dmultisample.h b/source/core/texture2dmultisample.h index 8c3275c0..77f4c542 100644 --- a/source/core/texture2dmultisample.h +++ b/source/core/texture2dmultisample.h @@ -25,7 +25,7 @@ public: unsigned get_samples() const { return samples; } virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::uint64_t get_data_size() const; + virtual std::size_t get_data_size() const; virtual void unload() { } }; diff --git a/source/core/texture3d.h b/source/core/texture3d.h index 2498c526..d791633d 100644 --- a/source/core/texture3d.h +++ b/source/core/texture3d.h @@ -73,7 +73,7 @@ protected: public: virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::uint64_t get_data_size() const; + virtual std::size_t get_data_size() const; virtual void unload() { } }; diff --git a/source/core/texturecube.h b/source/core/texturecube.h index e5a0d04f..e738ab53 100644 --- a/source/core/texturecube.h +++ b/source/core/texturecube.h @@ -98,7 +98,7 @@ public: Vector3 get_texel_direction(TextureCubeFace, unsigned, unsigned); virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::uint64_t get_data_size() const; + virtual std::size_t get_data_size() const; virtual void unload() { } }; diff --git a/source/core/uniformblock.cpp b/source/core/uniformblock.cpp index 18580149..89032b5c 100644 --- a/source/core/uniformblock.cpp +++ b/source/core/uniformblock.cpp @@ -12,14 +12,14 @@ UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info): data(info.data_size) { } -unsigned UniformBlock::get_alignment() const +size_t UniformBlock::get_alignment() const { return DeviceInfo::get_global().limits.uniform_buffer_alignment; } -void UniformBlock::store(const ReflectData::UniformInfo &info, unsigned array_size, const void *value) +void UniformBlock::store(const ReflectData::UniformInfo &info, size_t array_size, const void *value) { - array_size = min(array_size, max(info.array_size, 1U)); + array_size = min(array_size, max(info.array_size, 1U)); char *store_ptr; bool packed; diff --git a/source/core/uniformblock.h b/source/core/uniformblock.h index de8b90e4..5e88f0f8 100644 --- a/source/core/uniformblock.h +++ b/source/core/uniformblock.h @@ -22,13 +22,13 @@ private: public: UniformBlock(const ReflectData::UniformBlockInfo &); - virtual unsigned get_data_size() const { return data.size(); } + virtual std::size_t get_data_size() const { return data.size(); } virtual const void *get_data_pointer() const { return &data[0]; } private: - virtual unsigned get_alignment() const; + virtual std::size_t get_alignment() const; public: - void store(const ReflectData::UniformInfo &, unsigned, const void *); + void store(const ReflectData::UniformInfo &, std::size_t, const void *); }; } // namespace GL diff --git a/source/core/vertexarray.cpp b/source/core/vertexarray.cpp index 796bef80..db88e13c 100644 --- a/source/core/vertexarray.cpp +++ b/source/core/vertexarray.cpp @@ -24,7 +24,7 @@ void VertexArray::clear() data.clear(); } -void VertexArray::reserve(unsigned n) +void VertexArray::reserve(size_t n) { if(format.empty()) throw invalid_operation("VertexArray::reserve"); @@ -41,7 +41,7 @@ char *VertexArray::append() return &*(data.end()-stride); } -char *VertexArray::modify(unsigned i) +char *VertexArray::modify(size_t i) { if(format.empty()) throw invalid_operation("VertexArray::modify"); @@ -49,7 +49,7 @@ char *VertexArray::modify(unsigned i) return &data[0]+i*stride; } -unsigned VertexArray::get_data_size() const +size_t VertexArray::get_data_size() const { return data.size(); } diff --git a/source/core/vertexarray.h b/source/core/vertexarray.h index d80b2786..60e035f9 100644 --- a/source/core/vertexarray.h +++ b/source/core/vertexarray.h @@ -51,21 +51,21 @@ public: void clear(); /// Reserve space for vertices. - void reserve(unsigned); + void reserve(std::size_t n); /// Append a new vertex at the end of the array and return its location. char *append(); /// Returns the location of a vertex for modification. - char *modify(unsigned); + char *modify(std::size_t); private: - virtual unsigned get_data_size() const; + virtual std::size_t get_data_size() const; virtual const void *get_data_pointer() const { return &data[0]; } public: - unsigned size() const { return data.size()/stride; } + std::size_t size() const { return data.size()/stride; } const std::vector &get_data() const { return data; } - const char *operator[](unsigned i) const { return &data[0]+i*stride; } + const char *operator[](std::size_t i) const { return &data[0]+i*stride; } }; } // namespace GL diff --git a/source/resources/resource.h b/source/resources/resource.h index 1fdbb3ef..d763ac44 100644 --- a/source/resources/resource.h +++ b/source/resources/resource.h @@ -41,7 +41,7 @@ public: /** Returns the amount of graphics memory used by this resource. The returned value must not change while the resource is loaded. */ - virtual std::uint64_t get_data_size() const = 0; + virtual std::size_t get_data_size() const = 0; virtual void unload() = 0; };