Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve the description of an image #568

Closed
jojolatina opened this issue Oct 4, 2021 · 3 comments
Closed

Retrieve the description of an image #568

jojolatina opened this issue Oct 4, 2021 · 3 comments

Comments

@jojolatina
Copy link

When we create an image with sg_make_image, we pass it a sg_image_desc with the width/height and other parameters. As far as I can see, it's not possible to retrieve it. The only thing that we can retrieve is an sg_image_info which gives us the width/height but why can't we get back the original desc structure with all the fields? Isn't is useful sometimes to know the other parameters? (maybe I'm dumb and we just don't care, but this seems strange to me)

@floooh
Copy link
Owner

floooh commented Oct 4, 2021

Yep, that's an area where I haven't made up my mind yet :)

Some background: originally, sokol-gfx was going to be a strict "input-only" API, if you wanted to retrive information about resources, you'd have to store this information yourself somewhere. But this was too 'extreme', so at some point I added the sg_query_*_info() functions with very little information in them (because at that time, the internal backend data was structured differently and there wasn't much data kept in the 'backend-agnostic' parts.

At some point this was cleaned up, and every resource type now has a backend-agnostic _sg_*_common_t struct, for instance:

sokol/sokol_gfx.h

Lines 3008 to 3028 in 896497a

typedef struct {
sg_image_type type;
bool render_target;
int width;
int height;
int num_slices;
int num_mipmaps;
sg_usage usage;
sg_pixel_format pixel_format;
int sample_count;
sg_filter min_filter;
sg_filter mag_filter;
sg_wrap wrap_u;
sg_wrap wrap_v;
sg_wrap wrap_w;
sg_border_color border_color;
uint32_t max_anisotropy;
uint32_t upd_frame_index;
int num_slots;
int active_slot;
} _sg_image_common_t;

After this cleanup it would make sense to return the data in those common-structs.

There are some counter-points though:

  • the data in the common-structs is mostly needed in the validation layer, in release-mode where the validation layer is deactived, most of this data is dead-weight and those structs could be a lot smaller (and thus waste less memory in the resource pools)
  • returning such big structs by value (just to query one or two items) would also be quite wasteful, but by value is the only option because one of sokol-gfx's 'hard rules' is to not return pointers (even const pointers) to internal data structures
  • and finally: it should be a separate sg_*_info struct, not the original sg_*_desc struct, because those desc structs can be (a) quite a bit bigger indeed, and (b) contained "borrowed" pointers to transient external data, at least those references to external data would need to be cleared.

...that's my current thinking... so basically: yes, it's very likely that the query-functions will return more information, but it won't be the original desc-structs :)

@jojolatina
Copy link
Author

Ok, thanks, it makes sense

@floooh
Copy link
Owner

floooh commented Feb 20, 2023

This is now fixed via #796

@floooh floooh closed this as completed Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants