Skip to content

Commit

Permalink
Merge branch 'main' of github.com:kassane/sokol-d into imgui-support
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Apr 21, 2024
2 parents 74d43ca + c20da5b commit e0c7deb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/sokol/c/sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
sapp_consume_event() from inside the event handler (NOTE that
this behaviour is currently only implemented for some HTML5
events, support for other platforms and event types will
be added as needed, please open a github ticket and/or provide
be added as needed, please open a GitHub ticket and/or provide
a PR if needed).
NOTE: Do *not* call any 3D API rendering functions in the event
Expand Down
4 changes: 2 additions & 2 deletions src/sokol/c/sokol_debugtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -3849,8 +3849,8 @@ static void _sdtx_init_context(sdtx_context ctx_id, const sdtx_context_desc_t* i
pip_desc.colors[0].blend.enabled = true;
pip_desc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA;
pip_desc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
pip_desc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ZERO;
pip_desc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE;
pip_desc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE;
pip_desc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ZERO;
pip_desc.label = "sdtx-pipeline";
ctx->pip = sg_make_pipeline(&pip_desc);
SOKOL_ASSERT(SG_INVALID_ID != ctx->pip.id);
Expand Down
46 changes: 42 additions & 4 deletions src/sokol/c/sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,7 @@ typedef enum sg_image_type {
is compatible with what the shader expects. Apart from the sokol-gfx
validation layer, WebGPU is the only backend API which actually requires
matching texture and sampler type to be provided upfront for validation
(after 3D APIs treat texture/sampler type mismatches as undefined behaviour).
(other 3D APIs treat texture/sampler type mismatches as undefined behaviour).

NOTE that the following texture pixel formats require the use
of SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT, combined with a sampler
Expand Down Expand Up @@ -4756,7 +4756,7 @@ _SOKOL_PRIVATE int _sg_slot_index(uint32_t id);

// constants
enum {
_SG_STRING_SIZE = 16,
_SG_STRING_SIZE = 32,
_SG_SLOT_SHIFT = 16,
_SG_SLOT_MASK = (1<<_SG_SLOT_SHIFT)-1,
_SG_MAX_POOL_SIZE = (1<<_SG_SLOT_SHIFT),
Expand Down Expand Up @@ -9222,6 +9222,29 @@ _SOKOL_PRIVATE void _sg_gl_update_image(_sg_image_t* img, const sg_image_data* d
#define _sg_d3d11_Release(self) (self)->lpVtbl->Release(self)
#endif

// NOTE: This needs to be a macro since we can't use the polymorphism in C. It's called on many kinds of resources.
// NOTE: Based on microsoft docs, it's fine to call this with pData=NULL if DataSize is also zero.
#if defined(__cplusplus)
#define _sg_d3d11_SetPrivateData(self, guid, DataSize, pData) (self)->SetPrivateData(guid, DataSize, pData)
#else
#define _sg_d3d11_SetPrivateData(self, guid, DataSize, pData) (self)->lpVtbl->SetPrivateData(self, guid, DataSize, pData)
#endif

#if defined(__cplusplus)
#define _sg_win32_refguid(guid) guid
#else
#define _sg_win32_refguid(guid) &guid
#endif

static const GUID _sg_d3d11_WKPDID_D3DDebugObjectName = { 0x429b8c22,0x9188,0x4b0c, {0x87,0x42,0xac,0xb0,0xbf,0x85,0xc2,0x00} };

#if defined(SOKOL_DEBUG)
#define _sg_d3d11_setlabel(self, label) _sg_d3d11_SetPrivateData(self, _sg_win32_refguid(_sg_d3d11_WKPDID_D3DDebugObjectName), label ? (UINT)strlen(label) : 0, label)
#else
#define _sg_d3d11_setlabel(self, label)
#endif


//-- D3D11 C/C++ wrappers ------------------------------------------------------
static inline HRESULT _sg_d3d11_CheckFormatSupport(ID3D11Device* self, DXGI_FORMAT Format, UINT* pFormatSupport) {
#if defined(__cplusplus)
Expand Down Expand Up @@ -9991,6 +10014,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_buffer(_sg_buffer_t* buf, cons
_SG_ERROR(D3D11_CREATE_BUFFER_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(buf->d3d11.buf, desc->label);
}
return SG_RESOURCESTATE_VALID;
}
Expand Down Expand Up @@ -10097,6 +10121,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const
_SG_ERROR(D3D11_CREATE_2D_TEXTURE_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(img->d3d11.tex2d, desc->label);

// create shader-resource-view for 2D texture
// FIXME: currently we don't support setting MSAA texture as shader resource
Expand Down Expand Up @@ -10126,6 +10151,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const
_SG_ERROR(D3D11_CREATE_2D_SRV_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(img->d3d11.srv, desc->label);
}
}
SOKOL_ASSERT(img->d3d11.tex2d);
Expand Down Expand Up @@ -10167,6 +10193,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const
_SG_ERROR(D3D11_CREATE_3D_TEXTURE_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(img->d3d11.tex3d, desc->label);

// create shader-resource-view for 3D texture
if (!msaa) {
Expand All @@ -10180,6 +10207,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_image(_sg_image_t* img, const
_SG_ERROR(D3D11_CREATE_3D_SRV_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(img->d3d11.srv, desc->label);
}
}
SOKOL_ASSERT(img->d3d11.tex3d);
Expand Down Expand Up @@ -10243,6 +10271,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_sampler(_sg_sampler_t* smp, co
_SG_ERROR(D3D11_CREATE_SAMPLER_STATE_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(smp->d3d11.smp, desc->label);
}
return SG_RESOURCESTATE_VALID;
}
Expand Down Expand Up @@ -10337,6 +10366,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_shader(_sg_shader_t* shd, cons
_SG_ERROR(D3D11_CREATE_CONSTANT_BUFFER_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(d3d11_stage->cbufs[ub_index], desc->label);
}
}

Expand Down Expand Up @@ -10375,6 +10405,8 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_shader(_sg_shader_t* shd, cons
SOKOL_ASSERT(shd->d3d11.vs_blob);
memcpy(shd->d3d11.vs_blob, vs_ptr, vs_length);
result = SG_RESOURCESTATE_VALID;
_sg_d3d11_setlabel(shd->d3d11.vs, desc->label);
_sg_d3d11_setlabel(shd->d3d11.fs, desc->label);
}
}
if (vs_blob) {
Expand Down Expand Up @@ -10466,6 +10498,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip,
_SG_ERROR(D3D11_CREATE_INPUT_LAYOUT_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(pip->d3d11.il, desc->label);

// create rasterizer state
D3D11_RASTERIZER_DESC rs_desc;
Expand All @@ -10485,6 +10518,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip,
_SG_ERROR(D3D11_CREATE_RASTERIZER_STATE_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(pip->d3d11.rs, desc->label);

// create depth-stencil state
D3D11_DEPTH_STENCIL_DESC dss_desc;
Expand All @@ -10510,6 +10544,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip,
_SG_ERROR(D3D11_CREATE_DEPTH_STENCIL_STATE_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(pip->d3d11.dss, desc->label);

// create blend state
D3D11_BLEND_DESC bs_desc;
Expand Down Expand Up @@ -10544,6 +10579,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_pipeline(_sg_pipeline_t* pip,
_SG_ERROR(D3D11_CREATE_BLEND_STATE_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(pip->d3d11.bs, desc->label);
return SG_RESOURCESTATE_VALID;
}

Expand Down Expand Up @@ -10639,6 +10675,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_attachments(_sg_attachments_t*
_SG_ERROR(D3D11_CREATE_RTV_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(atts->d3d11.colors[i].view.rtv, desc->label);
}
SOKOL_ASSERT(0 == atts->d3d11.depth_stencil.view.dsv);
if (ds_desc->image.id != SG_INVALID_ID) {
Expand Down Expand Up @@ -10673,6 +10710,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_d3d11_create_attachments(_sg_attachments_t*
_SG_ERROR(D3D11_CREATE_DSV_FAILED);
return SG_RESOURCESTATE_FAILED;
}
_sg_d3d11_setlabel(atts->d3d11.depth_stencil.view.dsv, desc->label);
}
return SG_RESOURCESTATE_VALID;
}
Expand Down Expand Up @@ -10755,7 +10793,7 @@ _SOKOL_PRIVATE void _sg_d3d11_begin_pass(const sg_pass* pass) {
// perform clear action
for (int i = 0; i < num_rtvs; i++) {
if (action->colors[i].load_action == SG_LOADACTION_CLEAR) {
_sg_d3d11_ClearRenderTargetView(_sg.d3d11.ctx, rtvs[i], &action->colors[i].clear_value.r);
_sg_d3d11_ClearRenderTargetView(_sg.d3d11.ctx, rtvs[i], (float*)&action->colors[i].clear_value);
_sg_stats_add(d3d11.pass.num_clear_render_target_view, 1);
}
}
Expand Down Expand Up @@ -10872,7 +10910,7 @@ _SOKOL_PRIVATE void _sg_d3d11_apply_pipeline(_sg_pipeline_t* pip) {

_sg_d3d11_RSSetState(_sg.d3d11.ctx, pip->d3d11.rs);
_sg_d3d11_OMSetDepthStencilState(_sg.d3d11.ctx, pip->d3d11.dss, pip->d3d11.stencil_ref);
_sg_d3d11_OMSetBlendState(_sg.d3d11.ctx, pip->d3d11.bs, &pip->cmn.blend_color.r, 0xFFFFFFFF);
_sg_d3d11_OMSetBlendState(_sg.d3d11.ctx, pip->d3d11.bs, (float*)&pip->cmn.blend_color, 0xFFFFFFFF);
_sg_d3d11_IASetPrimitiveTopology(_sg.d3d11.ctx, pip->d3d11.topology);
_sg_d3d11_IASetInputLayout(_sg.d3d11.ctx, pip->d3d11.il);
_sg_d3d11_VSSetShader(_sg.d3d11.ctx, pip->shader->d3d11.vs, NULL, 0);
Expand Down

0 comments on commit e0c7deb

Please sign in to comment.