diff options
| author | Andre Weissflog <floooh@gmail.com> | 2022-11-23 20:07:00 +0100 |
|---|---|---|
| committer | Andre Weissflog <floooh@gmail.com> | 2022-11-23 20:07:00 +0100 |
| commit | 950c70f2a00ec3d9bccb74a82d182cdd95de03cb (patch) | |
| tree | 167668113e4f4d7dcc7025b8e4537de5600bd371 | |
| parent | 3c3b065261aee1df86cbbdbe0455def913419dbb (diff) | |
sokol_gfx.h: remove hard asserts when creating pass with invalid image
Trying to create a pass with invalid images (and disabled validation
layer) now creates a pass in FAILED resource state, instead of
asserting.
| -rw-r--r-- | sokol_gfx.h | 12 | ||||
| -rw-r--r-- | tests/functional/sokol_gfx_test.c | 39 |
2 files changed, 47 insertions, 4 deletions
diff --git a/sokol_gfx.h b/sokol_gfx.h index 07152093..17381228 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -15423,8 +15423,10 @@ _SOKOL_PRIVATE void _sg_init_pass(_sg_pass_t* pass, const sg_pass_desc* desc) { for (int i = 0; i < SG_MAX_COLOR_ATTACHMENTS; i++) { if (desc->color_attachments[i].image.id) { att_imgs[i] = _sg_lookup_image(&_sg.pools, desc->color_attachments[i].image.id); - /* FIXME: this shouldn't be an assertion, but result in a SG_RESOURCESTATE_FAILED pass */ - SOKOL_ASSERT(att_imgs[i] && att_imgs[i]->slot.state == SG_RESOURCESTATE_VALID); + if (!(att_imgs[i] && att_imgs[i]->slot.state == SG_RESOURCESTATE_VALID)) { + pass->slot.state = SG_RESOURCESTATE_FAILED; + return; + } } else { att_imgs[i] = 0; @@ -15433,8 +15435,10 @@ _SOKOL_PRIVATE void _sg_init_pass(_sg_pass_t* pass, const sg_pass_desc* desc) { const int ds_att_index = SG_MAX_COLOR_ATTACHMENTS; if (desc->depth_stencil_attachment.image.id) { att_imgs[ds_att_index] = _sg_lookup_image(&_sg.pools, desc->depth_stencil_attachment.image.id); - /* FIXME: this shouldn't be an assertion, but result in a SG_RESOURCESTATE_FAILED pass */ - SOKOL_ASSERT(att_imgs[ds_att_index] && att_imgs[ds_att_index]->slot.state == SG_RESOURCESTATE_VALID); + if (!(att_imgs[ds_att_index] && att_imgs[ds_att_index]->slot.state == SG_RESOURCESTATE_VALID)) { + pass->slot.state = SG_RESOURCESTATE_FAILED; + return; + } } else { att_imgs[ds_att_index] = 0; diff --git a/tests/functional/sokol_gfx_test.c b/tests/functional/sokol_gfx_test.c index b7c86354..8d8f6eef 100644 --- a/tests/functional/sokol_gfx_test.c +++ b/tests/functional/sokol_gfx_test.c @@ -1293,3 +1293,42 @@ UTEST(sokol_gfx, alloc_destroy_pass_is_ok) { T(sg_query_pass_state(pass) == SG_RESOURCESTATE_INVALID); sg_shutdown(); } + +UTEST(sokol_gfx, make_pipeline_with_nonvalid_shader) { + sg_setup(&(sg_desc){ + .disable_validation = true, + }); + sg_shader shd = sg_alloc_shader(); + T(sg_query_shader_state(shd) == SG_RESOURCESTATE_ALLOC); + sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){ + .shader = shd, + .layout = { + .attrs[0].format = SG_VERTEXFORMAT_FLOAT3 + }, + }); + T(sg_query_pipeline_state(pip) == SG_RESOURCESTATE_FAILED); + sg_shutdown(); +} + +UTEST(sokol_gfx, make_pass_with_nonvalid_color_images) { + sg_setup(&(sg_desc){ + .disable_validation = true, + }); + sg_pass pass = sg_make_pass(&(sg_pass_desc){ + .color_attachments = { + [0].image = sg_alloc_image(), + [1].image = sg_alloc_image(), + }, + .depth_stencil_attachment = { + .image = sg_make_image(&(sg_image_desc){ + .render_target = true, + .width = 128, + .height = 128 + }) + } + }); + T(sg_query_pass_state(pass) == SG_RESOURCESTATE_FAILED); + sg_destroy_pass(pass); + T(sg_query_pass_state(pass) == SG_RESOURCESTATE_INVALID); + sg_shutdown(); +} |