Create ID3D10Buffer interfaces for the constant buffers within the effect shader.
Signed-off-by: Connor McAdams conmanx360@gmail.com --- v4: Add tests for Scalar/Vector array set/get offset arguments, instead of previously where it was just one of the two.
dlls/d3d10/d3d10_private.h | 10 ++++++ dlls/d3d10/effect.c | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
diff --git a/dlls/d3d10/d3d10_private.h b/dlls/d3d10/d3d10_private.h index 96020cd4a0..5c6c7a2d72 100644 --- a/dlls/d3d10/d3d10_private.h +++ b/dlls/d3d10/d3d10_private.h @@ -114,6 +114,15 @@ struct d3d10_effect_state_object_variable } object; };
+struct d3d10_effect_buffer_variable +{ + ID3D10Buffer *buffer; + ID3D10ShaderResourceView *resource_view; + + UINT changed; + char *local_buffer; +}; + /* ID3D10EffectType */ struct d3d10_effect_type { @@ -169,6 +178,7 @@ struct d3d10_effect_variable { struct d3d10_effect_state_object_variable state; struct d3d10_effect_shader_variable shader; + struct d3d10_effect_buffer_variable buffer; } u; };
diff --git a/dlls/d3d10/effect.c b/dlls/d3d10/effect.c index 91e713bdf5..b62b7c0d3a 100644 --- a/dlls/d3d10/effect.c +++ b/dlls/d3d10/effect.c @@ -2096,6 +2096,53 @@ static HRESULT parse_fx10_local_variable(const char *data, size_t data_size, return S_OK; }
+static HRESULT create_variable_buffer(struct d3d10_effect_variable *l, D3D10_CBUFFER_TYPE d3d10_cbuffer_type) +{ + D3D10_BUFFER_DESC buffer_desc; + D3D10_SUBRESOURCE_DATA subresource_data; + D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc; + ID3D10Device *device = l->effect->device; + HRESULT hr; + + if (!(l->u.buffer.local_buffer = heap_calloc(l->type->size_unpacked, sizeof(unsigned char)))) + { + ERR("Failed to allocate local constant buffer memory.\n"); + return E_OUTOFMEMORY; + } + + buffer_desc.ByteWidth = l->type->size_unpacked; + buffer_desc.Usage = D3D10_USAGE_DEFAULT; + buffer_desc.CPUAccessFlags = 0; + buffer_desc.MiscFlags = 0; + if (d3d10_cbuffer_type == D3D10_CT_CBUFFER) + buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER; + else if (d3d10_cbuffer_type == D3D10_CT_TBUFFER) + buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; + + subresource_data.pSysMem = (const void *)l->u.buffer.local_buffer; + subresource_data.SysMemPitch = 0; + subresource_data.SysMemSlicePitch = 0; + + if (FAILED(hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &subresource_data, &l->u.buffer.buffer))) + return hr; + + if (d3d10_cbuffer_type == D3D10_CT_TBUFFER) + { + srv_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT; + srv_desc.ViewDimension = D3D_SRV_DIMENSION_BUFFER; + srv_desc.Buffer.ElementOffset = 0; + srv_desc.Buffer.ElementWidth = l->type->size_unpacked / 16; + + if (FAILED(hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)l->u.buffer.buffer, + (const D3D10_SHADER_RESOURCE_VIEW_DESC *)&srv_desc, &l->u.buffer.resource_view))) + return hr; + } + else + l->u.buffer.resource_view = NULL; + + return S_OK; +} + static HRESULT parse_fx10_local_buffer(const char *data, size_t data_size, const char **ptr, struct d3d10_effect_variable *l) { @@ -2282,6 +2329,12 @@ static HRESULT parse_fx10_local_buffer(const char *data, size_t data_size, TRACE("\tBasetype: %s.\n", debug_d3d10_shader_variable_type(l->type->basetype)); TRACE("\tTypeclass: %s.\n", debug_d3d10_shader_variable_class(l->type->type_class));
+ if (l->type->size_unpacked) + { + if (FAILED(hr = create_variable_buffer(l, d3d10_cbuffer_type))) + return hr; + } + return S_OK; }
@@ -2760,6 +2813,15 @@ static void d3d10_effect_local_buffer_destroy(struct d3d10_effect_variable *l) } heap_free(l->annotations); } + + if (l->u.buffer.buffer) + ID3D10Buffer_Release(l->u.buffer.buffer); + + if (l->u.buffer.local_buffer) + heap_free(l->u.buffer.local_buffer); + + if (l->u.buffer.resource_view) + ID3D10ShaderResourceView_Release(l->u.buffer.resource_view); }
/* IUnknown methods */