12auto clamp_non_negative(std::int64_t
bytes) -> std::uint64_t
14 return static_cast<std::uint64_t
>(std::max<std::int64_t>(0,
bytes));
17void write_formatted(std::uint64_t
bytes,
char* out, std::size_t out_size, std::uint8_t num_frac)
19 if(out ==
nullptr || out_size == 0)
25 bx::prettify(out,
static_cast<int32_t
>(out_size),
bytes, bx::Units::KibiByte);
28 const bx::FixedStringT<32> formatted = bx::toHuman<32>(
bytes, bx::Units::KibiByte, num_frac);
29 bx::strCopy(out,
static_cast<int32_t
>(out_size), formatted.getCPtr());
34 std::array<char, 32> buffer{};
35 write_formatted(
bytes, buffer.data(), buffer.size(), num_frac);
44void format_bytes(std::uint64_t
bytes,
char* out, std::size_t out_size, std::uint8_t num_frac)
46 write_formatted(
bytes, out, out_size, num_frac);
63 const std::string msg = std::string(
"Eviction: Insufficient headroom for ") + what +
" (" +
65 gfx::log(
"warning", msg, __FILE__, __LINE__);
73 const std::string msg = std::string(
"Eviction: Insufficient headroom for ") + what +
" (" +
75 gfx::log(
"warning", msg, __FILE__, __LINE__);
81 const bool gpu_generated = 0 != (flags & (BGFX_TEXTURE_RT_MASK | BGFX_TEXTURE_COMPUTE_WRITE | BGFX_TEXTURE_BLIT_DST));
88 return [flags, what,
kind](
const bgfx::TextureInfo& info) ->
bool
96 std::uint64_t estimated_size,
97 std::uint64_t load_flags,
101 auto restore = [backing,
load_flags, skip, label = std::string(label)](
texture& self) ->
bool
105 static_cast<std::uint32_t
>(backing->size()),
112 return self.is_valid();
125 std::uint64_t _flags,
130 std::uint32_t
size = 0;
131 void* data =
load(bx::FilePath(_path), &
size);
138 adopt_loaded_eviction(backing,
161 std::uint64_t _flags,
167 const char* label = (_name !=
nullptr) ? _name :
"memory texture";
171 handle_ =
loadTexture(_data, _size, _flags, _skip, &
info,
nullptr, _name, &err, make_load_precreate(_flags, label));
188 std::uint16_t _height,
190 std::uint16_t _numLayers,
192 std::uint64_t _flags ,
199 const bool can_allocate = try_make_room_for(estimated_size,
"2D texture", kind);
214 auto restore = [backing,
221 estimated_size](
texture& self) ->
bool
225 return self.is_valid();
239 std::uint16_t _height,
240 std::uint16_t _depth,
243 std::uint64_t _flags ,
250 const bool can_allocate = try_make_room_for(estimated_size,
"3D texture", kind);
266 auto restore = [backing,
273 estimated_size](
texture& self) ->
bool
277 return self.is_valid();
292 std::uint16_t _numLayers,
294 std::uint64_t _flags ,
301 const bool can_allocate = try_make_room_for(estimated_size,
"cube texture", kind);
316 auto restore = [backing,
322 estimated_size](
texture& self) ->
bool
326 return self.is_valid();
341 return {
static_cast<std::uint32_t
>(
info.width),
static_cast<std::uint32_t
>(
info.height)};
346 return 0 != (
flags & BGFX_TEXTURE_RT_MASK);
351 return 0 != (
flags & (BGFX_TEXTURE_RT_MASK | BGFX_TEXTURE_COMPUTE_WRITE | BGFX_TEXTURE_BLIT_DST));
gfx::texture_format format
void * load(bx::FileReaderI *_reader, bx::AllocatorI *_allocator, const bx::FilePath &_filePath, uint32_t *_size)
bgfx::TextureHandle loadTexture(const void *_data, uint32_t _size, uint64_t _flags, uint8_t _skip, bgfx::TextureInfo *_info, bimg::Orientation::Enum *_orientation, const char *_name, bx::Error *_err, const TexturePreCreateFn &_preCreate)
std::function< bool(const bgfx::TextureInfo &_info)> TexturePreCreateFn
auto is_valid() const -> bool
void make_evictable(std::uint64_t gpu_bytes, std::function< bool(texture &)> restore_fn, evict_class cls=evict_class::evictable)
void make_evictable_deferred(std::uint64_t gpu_bytes, std::function< bool(texture &)> restore_fn, evict_class cls=evict_class::evictable)
void note_pending_allocation(std::uint64_t bytes)
auto is_supported() -> bool
auto make_backing_ref(const backing_buffer &backing) -> const memory_view *
std::shared_ptr< std::vector< std::uint8_t > > backing_buffer
auto would_allocation_fit(std::uint64_t bytes) -> bool
auto make_backing(const void *data, std::uint32_t size) -> backing_buffer
reclaim_kind
Controls whether reclaim_for pumps the GPU command buffer after evicting.
auto reclaim_for(std::uint64_t bytes, reclaim_kind kind) -> reclaim_result
@ insufficient
Eviction could not free enough room; the allocation may exhaust device memory.
bgfx::TextureFormat::Enum texture_format
texture_handle create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, texture_format _format, uint64_t _flags, const memory_view *_mem)
texture_handle create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, texture_format _format, uint64_t _flags, const memory_view *_mem)
void log(const std::string &category, const std::string &log_msg, const char *_filePath, uint16_t _line)
bgfx::TextureHandle texture_handle
void calc_texture_size(texture_info &_info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, texture_format _format)
texture_handle create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, texture_format _format, uint64_t _flags, const memory_view *_mem)
auto fallback_texture() -> texture_handle
bgfx::TextureInfo texture_info
uint64_t estimate_texture_gpu_size(const texture_info &_info, uint64_t _flags)
Hash specialization for batch_key to enable use in std::unordered_map.
auto format_bytes(std::uint64_t bytes, std::uint8_t num_frac) -> std::string
auto is_render_target() const -> bool
auto fallback_handle() const -> texture_handle
auto is_gpu_generated() const -> bool
Whether the texture's contents are produced on the GPU (render target or compute-write) rather than u...
std::uint64_t flags
Creation flags.
auto get_size() const -> usize32_t
texture_info info
Texture detail info.
auto get_estimated_gpu_size() const -> std::uint64_t