From 099aa57f23fd20ffc499ebc32e49559bab805814 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 24 Sep 2021 08:10:12 +0300 Subject: [PATCH] d3d10/effect: Validate shared constant buffer types against the pool. Signed-off-by: Nikolay Sivov Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- dlls/d3d10/d3d10_private.h | 2 +- dlls/d3d10/effect.c | 103 +++++++++++++++++++++++++------------ dlls/d3d10/tests/effect.c | 42 +++++++++------ 3 files changed, 95 insertions(+), 52 deletions(-) diff --git a/dlls/d3d10/d3d10_private.h b/dlls/d3d10/d3d10_private.h index 7f64e811e9f..3c3c6fa7f58 100644 --- a/dlls/d3d10/d3d10_private.h +++ b/dlls/d3d10/d3d10_private.h @@ -269,7 +269,7 @@ struct d3d10_effect DWORD local_buffer_count; DWORD variable_count; DWORD local_variable_count; - DWORD sharedbuffers_count; + DWORD shared_buffer_count; DWORD shared_object_count; DWORD technique_count; DWORD index_offset; diff --git a/dlls/d3d10/effect.c b/dlls/d3d10/effect.c index 1913d621ecc..8246f288369 100644 --- a/dlls/d3d10/effect.c +++ b/dlls/d3d10/effect.c @@ -2013,7 +2013,7 @@ static HRESULT parse_fx10_technique(const char *data, size_t data_size, } static HRESULT parse_fx10_numeric_variable(const char *data, size_t data_size, - const char **ptr, struct d3d10_effect_variable *v) + const char **ptr, BOOL local, struct d3d10_effect_variable *v) { DWORD offset, default_value_offset; HRESULT hr; @@ -2039,17 +2039,20 @@ static HRESULT parse_fx10_numeric_variable(const char *data, size_t data_size, read_dword(ptr, &v->flag); TRACE("Variable flag: %#x.\n", v->flag); - if (default_value_offset) - FIXME("Set default variable value.\n"); - - read_dword(ptr, &v->annotation_count); - TRACE("Variable has %u annotations.\n", v->annotation_count); - - if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, v->effect, - v->annotation_count, &v->annotations))) + if (local) { - ERR("Failed to parse variable annotations, hr %#x.\n", hr); - return hr; + if (default_value_offset) + FIXME("Set default variable value.\n"); + + read_dword(ptr, &v->annotation_count); + TRACE("Variable has %u annotations.\n", v->annotation_count); + + if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, v->effect, + v->annotation_count, &v->annotations))) + { + ERR("Failed to parse variable annotations, hr %#x.\n", hr); + return hr; + } } if (v->flag & D3D10_EFFECT_VARIABLE_EXPLICIT_BIND_POINT) @@ -2313,9 +2316,10 @@ static HRESULT create_variable_buffer(struct d3d10_effect_variable *v, D3D10_CBU return S_OK; } -static HRESULT parse_fx10_local_buffer(const char *data, size_t data_size, - const char **ptr, struct d3d10_effect_variable *l) +static HRESULT parse_fx10_buffer(const char *data, size_t data_size, const char **ptr, + BOOL local, struct d3d10_effect_variable *l) { + const char *prefix = local ? "Local" : "Shared"; unsigned int i; DWORD offset; D3D10_CBUFFER_TYPE d3d10_cbuffer_type; @@ -2333,20 +2337,20 @@ static HRESULT parse_fx10_local_buffer(const char *data, size_t data_size, l->type->effect = l->effect; read_dword(ptr, &offset); - TRACE("Local buffer name at offset %#x.\n", offset); + TRACE("%s buffer name at offset %#x.\n", prefix, offset); if (!fx10_copy_string(data, data_size, offset, &l->name)) { ERR("Failed to copy name.\n"); return E_OUTOFMEMORY; } - TRACE("Local buffer name: %s.\n", debugstr_a(l->name)); + TRACE("%s buffer name: %s.\n", prefix, debugstr_a(l->name)); read_dword(ptr, &l->data_size); - TRACE("Local buffer data size: %#x.\n", l->data_size); + TRACE("%s buffer data size: %#x.\n", prefix, l->data_size); read_dword(ptr, &d3d10_cbuffer_type); - TRACE("Local buffer type: %#x.\n", d3d10_cbuffer_type); + TRACE("%s buffer type: %#x.\n", prefix, d3d10_cbuffer_type); switch(d3d10_cbuffer_type) { @@ -2374,19 +2378,22 @@ static HRESULT parse_fx10_local_buffer(const char *data, size_t data_size, } read_dword(ptr, &l->type->member_count); - TRACE("Local buffer member count: %#x.\n", l->type->member_count); + TRACE("%s buffer member count: %#x.\n", prefix, l->type->member_count); read_dword(ptr, &l->explicit_bind_point); - TRACE("Local buffer explicit bind point: %#x.\n", l->explicit_bind_point); + TRACE("%s buffer explicit bind point: %#x.\n", prefix, l->explicit_bind_point); - read_dword(ptr, &l->annotation_count); - TRACE("Local buffer has %u annotations.\n", l->annotation_count); - - if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, l->effect, - l->annotation_count, &l->annotations))) + if (local) { - ERR("Failed to parse buffer annotations, hr %#x.\n", hr); - return hr; + read_dword(ptr, &l->annotation_count); + TRACE("Local buffer has %u annotations.\n", l->annotation_count); + + if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, l->effect, + l->annotation_count, &l->annotations))) + { + ERR("Failed to parse buffer annotations, hr %#x.\n", hr); + return hr; + } } if (!(l->members = heap_calloc(l->type->member_count, sizeof(*l->members)))) @@ -2409,7 +2416,7 @@ static HRESULT parse_fx10_local_buffer(const char *data, size_t data_size, v->buffer = l; v->effect = l->effect; - if (FAILED(hr = parse_fx10_numeric_variable(data, data_size, ptr, v))) + if (FAILED(hr = parse_fx10_numeric_variable(data, data_size, ptr, local, v))) return hr; /* @@ -2480,7 +2487,7 @@ static HRESULT parse_fx10_local_buffer(const char *data, size_t data_size, } l->type->stride = l->type->size_unpacked = (stride + 0xf) & ~0xf; - TRACE("Constant buffer:\n"); + TRACE("%s constant buffer:\n", prefix); TRACE("\tType name: %s.\n", debugstr_a(l->type->name)); TRACE("\tElement count: %u.\n", l->type->element_count); TRACE("\tMember count: %u.\n", l->type->member_count); @@ -2490,7 +2497,7 @@ 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 (local && l->type->size_unpacked) { if (FAILED(hr = create_variable_buffer(l, d3d10_cbuffer_type))) return hr; @@ -2565,7 +2572,18 @@ static BOOL d3d10_effect_types_match(const struct d3d10_effect_type *t1, static HRESULT d3d10_effect_validate_shared_variable(const struct d3d10_effect *effect, const struct d3d10_effect_variable *v) { - ID3D10EffectVariable *sv = effect->pool->lpVtbl->GetVariableByName(effect->pool, v->name); + ID3D10EffectVariable *sv; + + switch (v->type->basetype) + { + case D3D10_SVT_CBUFFER: + case D3D10_SVT_TBUFFER: + sv = (ID3D10EffectVariable *)effect->pool->lpVtbl->GetConstantBufferByName( + effect->pool, v->name); + break; + default: + sv = effect->pool->lpVtbl->GetVariableByName(effect->pool, v->name); + } if (!sv->lpVtbl->IsValid(sv)) { @@ -2632,7 +2650,7 @@ static HRESULT parse_fx10_body(struct d3d10_effect *e, const char *data, DWORD d l->effect = e; l->buffer = &null_local_buffer; - if (FAILED(hr = parse_fx10_local_buffer(data, data_size, &ptr, l))) + if (FAILED(hr = parse_fx10_buffer(data, data_size, &ptr, TRUE, l))) return hr; } @@ -2648,6 +2666,23 @@ static HRESULT parse_fx10_body(struct d3d10_effect *e, const char *data, DWORD d return hr; } + for (i = 0; i < e->shared_buffer_count; ++i) + { + struct d3d10_effect_variable b = { 0 }; + + b.effect = e; + + if (FAILED(hr = parse_fx10_buffer(data, data_size, &ptr, FALSE, &b))) + { + d3d10_effect_variable_destroy(&b); + return hr; + } + + hr = d3d10_effect_validate_shared_variable(e, &b); + d3d10_effect_variable_destroy(&b); + if (FAILED(hr)) return hr; + } + for (i = 0; i < e->shared_object_count; ++i) { struct d3d10_effect_variable o = { 0 }; @@ -2703,8 +2738,8 @@ static HRESULT parse_fx10(struct d3d10_effect *e, const char *data, DWORD data_s read_dword(&ptr, &e->local_variable_count); TRACE("Object count: %u\n", e->local_variable_count); - read_dword(&ptr, &e->sharedbuffers_count); - TRACE("Pool buffer count: %u\n", e->sharedbuffers_count); + read_dword(&ptr, &e->shared_buffer_count); + TRACE("Pool buffer count: %u\n", e->shared_buffer_count); read_dword(&ptr, &unused); TRACE("Pool variable count: %u\n", unused); @@ -2748,7 +2783,7 @@ static HRESULT parse_fx10(struct d3d10_effect *e, const char *data, DWORD data_s read_dword(&ptr, &e->anonymous_shader_count); TRACE("Anonymous shader count: %u\n", e->anonymous_shader_count); - if (!e->pool && e->shared_object_count) + if (!e->pool && (e->shared_object_count || e->shared_buffer_count)) { WARN("Effect requires a pool to load.\n"); return E_FAIL; diff --git a/dlls/d3d10/tests/effect.c b/dlls/d3d10/tests/effect.c index 5e54925abb2..29773fc4582 100644 --- a/dlls/d3d10/tests/effect.c +++ b/dlls/d3d10/tests/effect.c @@ -6330,6 +6330,12 @@ cbuffer l_cb float f0 : COLOR0; }; +shared cbuffer s_cb +{ + float f1 : COLOR0; + float f2 : COLOR1; +}; + cbuffer l_cb2 { float f3; @@ -6351,25 +6357,27 @@ technique10 tech_child #endif static DWORD fx_test_pool_child[] = { - 0x43425844, 0x22800afa, 0xe318151b, 0xcb3e7d52, 0x186ecbe3, 0x00000001, 0x00000249, 0x00000001, - 0x00000024, 0x30315846, 0x0000021d, 0xfeff1001, 0x00000002, 0x00000002, 0x00000000, 0x00000000, - 0x00000000, 0x00000003, 0x00000001, 0x000000f1, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x43425844, 0xa11d7cb2, 0x41f20697, 0x14a62983, 0x43b9f39c, 0x00000001, 0x0000029f, 0x00000001, + 0x00000024, 0x30315846, 0x00000273, 0xfeff1001, 0x00000002, 0x00000002, 0x00000000, 0x00000001, + 0x00000002, 0x00000003, 0x00000001, 0x00000103, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x62635f6c, 0x6f6c6600, 0x09007461, 0x01000000, 0x00000000, 0x04000000, 0x10000000, 0x04000000, 0x09000000, - 0x66000009, 0x4f430030, 0x30524f4c, 0x635f6c00, 0x66003262, 0x6c420033, 0x53646e65, 0x65746174, - 0x00003e00, 0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000200, 0x625f7300, - 0x646e656c, 0x74617473, 0x65740065, 0x72757478, 0x00720065, 0x00020000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00090000, 0x5f730000, 0x74786574, 0x00657275, 0x65786950, 0x6168536c, - 0x00726564, 0x000000a0, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000005, - 0x74007370, 0x5f686365, 0x6c696863, 0x30500064, 0x00000100, 0x00000200, 0x00000000, 0x00000100, - 0x00000200, 0x00000000, 0x00000400, 0x00001000, 0x00000000, 0x00000100, 0xffffff00, 0x000000ff, - 0x00002b00, 0x00000f00, 0x00002e00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00003500, - 0x00001000, 0x00000000, 0x00000100, 0xffffff00, 0x000000ff, 0x00003b00, 0x00000f00, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00006500, 0x00004900, 0x00000000, 0xffffff00, - 0x000096ff, 0x00007a00, 0x00000000, 0xffffff00, 0x0000c8ff, 0x0000ac00, 0x00000000, 0xffffff00, - 0x0000cbff, 0x00000100, 0x00000000, 0x0000d600, 0x00000300, 0x00000000, 0x00000700, 0x00000000, - 0x00000200, 0x0000c800, 0x00000600, 0x00000000, 0x00000100, 0x0000d900, 0x00000800, 0x00000000, - 0x00000100, 0x0000e500, 0x00000000, + 0x66000009, 0x4f430030, 0x30524f4c, 0x635f6c00, 0x66003262, 0x5f730033, 0x66006263, 0x32660031, + 0x4c4f4300, 0x0031524f, 0x6e656c42, 0x61745364, 0x50006574, 0x02000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x02000000, 0x73000000, 0x656c625f, 0x7473646e, 0x00657461, 0x74786574, + 0x00657275, 0x00000084, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000009, + 0x65745f73, 0x72757478, 0x69500065, 0x536c6578, 0x65646168, 0x00b20072, 0x00020000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00050000, 0x73700000, 0x63657400, 0x68635f68, 0x00646c69, + 0x01003050, 0x02000000, 0x00000000, 0x01000000, 0x02000000, 0x00000000, 0x04000000, 0x10000000, + 0x00000000, 0x01000000, 0xff000000, 0x00ffffff, 0x2b000000, 0x0f000000, 0x2e000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x35000000, 0x10000000, 0x00000000, 0x01000000, 0xff000000, + 0x00ffffff, 0x3b000000, 0x0f000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x3e000000, 0x10000000, 0x00000000, 0x02000000, 0xff000000, 0x43ffffff, 0x0f000000, 0x2e000000, + 0x00000000, 0x00000000, 0x00000000, 0x46000000, 0x0f000000, 0x49000000, 0x04000000, 0x00000000, + 0x00000000, 0x77000000, 0x5b000000, 0x00000000, 0xff000000, 0xa8ffffff, 0x8c000000, 0x00000000, + 0xff000000, 0xdaffffff, 0xbe000000, 0x00000000, 0xff000000, 0xddffffff, 0x01000000, 0x00000000, + 0xe8000000, 0x03000000, 0x00000000, 0x07000000, 0x00000000, 0x02000000, 0xda000000, 0x06000000, + 0x00000000, 0x01000000, 0xeb000000, 0x08000000, 0x00000000, 0x01000000, 0xf7000000, 0x00000000, }; static void test_effect_pool(void)