diff --git a/dlls/d3d10/d3d10_private.h b/dlls/d3d10/d3d10_private.h index f3fce9c5692..c9e6dbb8232 100644 --- a/dlls/d3d10/d3d10_private.h +++ b/dlls/d3d10/d3d10_private.h @@ -42,8 +42,6 @@ /* TRACE helper functions */ const char *debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type) DECLSPEC_HIDDEN; -const char *debug_d3d10_shader_variable_class(D3D10_SHADER_VARIABLE_CLASS c) DECLSPEC_HIDDEN; -const char *debug_d3d10_shader_variable_type(D3D10_SHADER_VARIABLE_TYPE t) DECLSPEC_HIDDEN; const char *debug_d3d10_device_state_types(D3D10_DEVICE_STATE_TYPES t) DECLSPEC_HIDDEN; enum d3d10_effect_object_type @@ -269,36 +267,4 @@ HRESULT d3d10_effect_parse(struct d3d10_effect *This, const void *data, SIZE_T d HRESULT WINAPI D3D10CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter, unsigned int flags, D3D_FEATURE_LEVEL feature_level, ID3D10Device **device); -#define MAKE_TAG(ch0, ch1, ch2, ch3) \ - ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \ - ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 )) -#define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C') -#define TAG_FX10 MAKE_TAG('F', 'X', '1', '0') -#define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N') -#define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N') -#define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R') - -HRESULT parse_dxbc(const char *data, SIZE_T data_size, - HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx) DECLSPEC_HIDDEN; - -static inline void read_dword(const char **ptr, DWORD *d) -{ - memcpy(d, *ptr, sizeof(*d)); - *ptr += sizeof(*d); -} - -static inline void write_dword(char **ptr, DWORD d) -{ - memcpy(*ptr, &d, sizeof(d)); - *ptr += sizeof(d); -} - -static inline BOOL require_space(size_t offset, size_t count, size_t size, size_t data_size) -{ - return !count || (data_size - offset) / count >= size; -} - -void skip_dword_unknown(const char *location, const char **ptr, unsigned int count) DECLSPEC_HIDDEN; -void write_dword_unknown(char **ptr, DWORD d) DECLSPEC_HIDDEN; - #endif /* __WINE_D3D10_PRIVATE_H */ diff --git a/dlls/d3d10/effect.c b/dlls/d3d10/effect.c index 439833485d6..91e713bdf54 100644 --- a/dlls/d3d10/effect.c +++ b/dlls/d3d10/effect.c @@ -24,6 +24,15 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d10); +#define MAKE_TAG(ch0, ch1, ch2, ch3) \ + ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \ + ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 )) +#define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C') +#define TAG_FX10 MAKE_TAG('F', 'X', '1', '0') +#define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N') +#define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N') +#define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R') + #define D3D10_FX10_TYPE_COLUMN_SHIFT 11 #define D3D10_FX10_TYPE_COLUMN_MASK (0x7 << D3D10_FX10_TYPE_COLUMN_SHIFT) @@ -241,6 +250,183 @@ static const struct d3d10_effect_state_storage_info d3d10_effect_state_storage_i {D3D10_SVT_SAMPLER, sizeof(default_sampler_desc), &default_sampler_desc }, }; +#define WINE_D3D10_TO_STR(x) case x: return #x + +static const char *debug_d3d10_shader_variable_class(D3D10_SHADER_VARIABLE_CLASS c) +{ + switch (c) + { + WINE_D3D10_TO_STR(D3D10_SVC_SCALAR); + WINE_D3D10_TO_STR(D3D10_SVC_VECTOR); + WINE_D3D10_TO_STR(D3D10_SVC_MATRIX_ROWS); + WINE_D3D10_TO_STR(D3D10_SVC_MATRIX_COLUMNS); + WINE_D3D10_TO_STR(D3D10_SVC_OBJECT); + WINE_D3D10_TO_STR(D3D10_SVC_STRUCT); + default: + FIXME("Unrecognised D3D10_SHADER_VARIABLE_CLASS %#x.\n", c); + return "unrecognised"; + } +} + +static const char *debug_d3d10_shader_variable_type(D3D10_SHADER_VARIABLE_TYPE t) +{ + switch (t) + { + WINE_D3D10_TO_STR(D3D10_SVT_VOID); + WINE_D3D10_TO_STR(D3D10_SVT_BOOL); + WINE_D3D10_TO_STR(D3D10_SVT_INT); + WINE_D3D10_TO_STR(D3D10_SVT_FLOAT); + WINE_D3D10_TO_STR(D3D10_SVT_STRING); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE1D); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2D); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE3D); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURECUBE); + WINE_D3D10_TO_STR(D3D10_SVT_SAMPLER); + WINE_D3D10_TO_STR(D3D10_SVT_PIXELSHADER); + WINE_D3D10_TO_STR(D3D10_SVT_VERTEXSHADER); + WINE_D3D10_TO_STR(D3D10_SVT_UINT); + WINE_D3D10_TO_STR(D3D10_SVT_UINT8); + WINE_D3D10_TO_STR(D3D10_SVT_GEOMETRYSHADER); + WINE_D3D10_TO_STR(D3D10_SVT_RASTERIZER); + WINE_D3D10_TO_STR(D3D10_SVT_DEPTHSTENCIL); + WINE_D3D10_TO_STR(D3D10_SVT_BLEND); + WINE_D3D10_TO_STR(D3D10_SVT_BUFFER); + WINE_D3D10_TO_STR(D3D10_SVT_CBUFFER); + WINE_D3D10_TO_STR(D3D10_SVT_TBUFFER); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE1DARRAY); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DARRAY); + WINE_D3D10_TO_STR(D3D10_SVT_RENDERTARGETVIEW); + WINE_D3D10_TO_STR(D3D10_SVT_DEPTHSTENCILVIEW); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DMS); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DMSARRAY); + WINE_D3D10_TO_STR(D3D10_SVT_TEXTURECUBEARRAY); + default: + FIXME("Unrecognised D3D10_SHADER_VARIABLE_TYPE %#x.\n", t); + return "unrecognised"; + } +} + +#undef WINE_D3D10_TO_STR + +static void read_dword(const char **ptr, DWORD *d) +{ + memcpy(d, *ptr, sizeof(*d)); + *ptr += sizeof(*d); +} + +static void write_dword(char **ptr, DWORD d) +{ + memcpy(*ptr, &d, sizeof(d)); + *ptr += sizeof(d); +} + +static BOOL require_space(size_t offset, size_t count, size_t size, size_t data_size) +{ + return !count || (data_size - offset) / count >= size; +} + +static void skip_dword_unknown(const char *location, const char **ptr, unsigned int count) +{ + unsigned int i; + DWORD d; + + FIXME("Skipping %u unknown DWORDs (%s):\n", count, location); + for (i = 0; i < count; ++i) + { + read_dword(ptr, &d); + FIXME("\t0x%08x\n", d); + } +} + +static void write_dword_unknown(char **ptr, DWORD d) +{ + FIXME("Writing unknown DWORD 0x%08x\n", d); + write_dword(ptr, d); +} + +static HRESULT parse_dxbc(const char *data, SIZE_T data_size, + HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx) +{ + const char *ptr = data; + HRESULT hr = S_OK; + DWORD chunk_count; + DWORD total_size; + unsigned int i; + DWORD version; + DWORD tag; + + if (!data) + { + WARN("No data supplied.\n"); + return E_FAIL; + } + + read_dword(&ptr, &tag); + TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4)); + + if (tag != TAG_DXBC) + { + WARN("Wrong tag.\n"); + return E_FAIL; + } + + skip_dword_unknown("DXBC checksum", &ptr, 4); + + read_dword(&ptr, &version); + TRACE("version: %#x.\n", version); + if (version != 0x00000001) + { + WARN("Got unexpected DXBC version %#x.\n", version); + return E_FAIL; + } + + read_dword(&ptr, &total_size); + TRACE("total size: %#x\n", total_size); + + if (data_size != total_size) + { + WARN("Wrong size supplied.\n"); + return E_FAIL; + } + + read_dword(&ptr, &chunk_count); + TRACE("chunk count: %#x\n", chunk_count); + + for (i = 0; i < chunk_count; ++i) + { + DWORD chunk_tag, chunk_size; + const char *chunk_ptr; + DWORD chunk_offset; + + read_dword(&ptr, &chunk_offset); + TRACE("chunk %u at offset %#x\n", i, chunk_offset); + + if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size)) + { + WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size); + return E_FAIL; + } + + chunk_ptr = data + chunk_offset; + + read_dword(&chunk_ptr, &chunk_tag); + read_dword(&chunk_ptr, &chunk_size); + + if (!require_space(chunk_ptr - data, 1, chunk_size, data_size)) + { + WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n", + chunk_size, data_size, chunk_offset); + return E_FAIL; + } + + if (FAILED(hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx))) + break; + } + + return hr; +} + static BOOL fx10_get_string(const char *data, size_t data_size, DWORD offset, const char **s, size_t *l) { size_t len, max_len; diff --git a/dlls/d3d10/utils.c b/dlls/d3d10/utils.c index 3b518684884..fca8994ff2e 100644 --- a/dlls/d3d10/utils.c +++ b/dlls/d3d10/utils.c @@ -38,61 +38,6 @@ const char *debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type) } } -const char *debug_d3d10_shader_variable_class(D3D10_SHADER_VARIABLE_CLASS c) -{ - switch (c) - { - WINE_D3D10_TO_STR(D3D10_SVC_SCALAR); - WINE_D3D10_TO_STR(D3D10_SVC_VECTOR); - WINE_D3D10_TO_STR(D3D10_SVC_MATRIX_ROWS); - WINE_D3D10_TO_STR(D3D10_SVC_MATRIX_COLUMNS); - WINE_D3D10_TO_STR(D3D10_SVC_OBJECT); - WINE_D3D10_TO_STR(D3D10_SVC_STRUCT); - default: - FIXME("Unrecognized D3D10_SHADER_VARIABLE_CLASS %#x.\n", c); - return "unrecognized"; - } -} - -const char *debug_d3d10_shader_variable_type(D3D10_SHADER_VARIABLE_TYPE t) -{ - switch (t) - { - WINE_D3D10_TO_STR(D3D10_SVT_VOID); - WINE_D3D10_TO_STR(D3D10_SVT_BOOL); - WINE_D3D10_TO_STR(D3D10_SVT_INT); - WINE_D3D10_TO_STR(D3D10_SVT_FLOAT); - WINE_D3D10_TO_STR(D3D10_SVT_STRING); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE1D); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2D); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE3D); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURECUBE); - WINE_D3D10_TO_STR(D3D10_SVT_SAMPLER); - WINE_D3D10_TO_STR(D3D10_SVT_PIXELSHADER); - WINE_D3D10_TO_STR(D3D10_SVT_VERTEXSHADER); - WINE_D3D10_TO_STR(D3D10_SVT_UINT); - WINE_D3D10_TO_STR(D3D10_SVT_UINT8); - WINE_D3D10_TO_STR(D3D10_SVT_GEOMETRYSHADER); - WINE_D3D10_TO_STR(D3D10_SVT_RASTERIZER); - WINE_D3D10_TO_STR(D3D10_SVT_DEPTHSTENCIL); - WINE_D3D10_TO_STR(D3D10_SVT_BLEND); - WINE_D3D10_TO_STR(D3D10_SVT_BUFFER); - WINE_D3D10_TO_STR(D3D10_SVT_CBUFFER); - WINE_D3D10_TO_STR(D3D10_SVT_TBUFFER); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE1DARRAY); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DARRAY); - WINE_D3D10_TO_STR(D3D10_SVT_RENDERTARGETVIEW); - WINE_D3D10_TO_STR(D3D10_SVT_DEPTHSTENCILVIEW); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DMS); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DMSARRAY); - WINE_D3D10_TO_STR(D3D10_SVT_TEXTURECUBEARRAY); - default: - FIXME("Unrecognized D3D10_SHADER_VARIABLE_TYPE %#x.\n", t); - return "unrecognized"; - } -} - const char *debug_d3d10_device_state_types(D3D10_DEVICE_STATE_TYPES t) { switch (t) @@ -128,104 +73,3 @@ const char *debug_d3d10_device_state_types(D3D10_DEVICE_STATE_TYPES t) } #undef WINE_D3D10_TO_STR - -void skip_dword_unknown(const char *location, const char **ptr, unsigned int count) -{ - unsigned int i; - DWORD d; - - FIXME("Skipping %u unknown DWORDs (%s):\n", count, location); - for (i = 0; i < count; ++i) - { - read_dword(ptr, &d); - FIXME("\t0x%08x\n", d); - } -} - -void write_dword_unknown(char **ptr, DWORD d) -{ - FIXME("Writing unknown DWORD 0x%08x\n", d); - write_dword(ptr, d); -} - -HRESULT parse_dxbc(const char *data, SIZE_T data_size, - HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx) -{ - const char *ptr = data; - HRESULT hr = S_OK; - DWORD chunk_count; - DWORD total_size; - unsigned int i; - DWORD version; - DWORD tag; - - if (!data) - { - WARN("No data supplied.\n"); - return E_FAIL; - } - - read_dword(&ptr, &tag); - TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4)); - - if (tag != TAG_DXBC) - { - WARN("Wrong tag.\n"); - return E_FAIL; - } - - /* checksum? */ - skip_dword_unknown("DXBC header", &ptr, 4); - - read_dword(&ptr, &version); - TRACE("version: %#x.\n", version); - if (version != 0x00000001) - { - WARN("Got unexpected DXBC version %#x.\n", version); - return E_FAIL; - } - - read_dword(&ptr, &total_size); - TRACE("total size: %#x\n", total_size); - - if (data_size != total_size) - { - WARN("Wrong size supplied.\n"); - return E_FAIL; - } - - read_dword(&ptr, &chunk_count); - TRACE("chunk count: %#x\n", chunk_count); - - for (i = 0; i < chunk_count; ++i) - { - DWORD chunk_tag, chunk_size; - const char *chunk_ptr; - DWORD chunk_offset; - - read_dword(&ptr, &chunk_offset); - TRACE("chunk %u at offset %#x\n", i, chunk_offset); - - if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size)) - { - WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size); - return E_FAIL; - } - - chunk_ptr = data + chunk_offset; - - read_dword(&chunk_ptr, &chunk_tag); - read_dword(&chunk_ptr, &chunk_size); - - if (!require_space(chunk_ptr - data, 1, chunk_size, data_size)) - { - WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n", chunk_size, data_size, chunk_offset); - return E_FAIL; - } - - hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx); - if (FAILED(hr)) break; - } - - return hr; -}