Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/wined3d/context.c | 1 + dlls/wined3d/device.c | 4 +++- dlls/wined3d/directx.c | 14 ++++++++++++++ dlls/wined3d/resource.c | 1 + dlls/wined3d/utils.c | 1 + include/wine/wined3d.h | 5 +++-- 6 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index ccfe630e1f..f8419f063c 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -1017,6 +1017,7 @@ void context_resource_released(const struct wined3d_device *device,
switch (type) { + case WINED3D_RTYPE_TEXTURE_1D: case WINED3D_RTYPE_TEXTURE_2D: case WINED3D_RTYPE_TEXTURE_3D: texture = texture_from_resource(resource); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 2d1603f0b0..096f4010fb 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4239,7 +4239,8 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str height = 1; depth = 1; } - else if (resource->type == WINED3D_RTYPE_TEXTURE_2D || resource->type == WINED3D_RTYPE_TEXTURE_3D) + else if (resource->type == WINED3D_RTYPE_TEXTURE_1D || resource->type == WINED3D_RTYPE_TEXTURE_2D + || resource->type == WINED3D_RTYPE_TEXTURE_3D) { struct wined3d_texture *texture = texture_from_resource(resource); unsigned int level; @@ -5006,6 +5007,7 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso
switch (type) { + case WINED3D_RTYPE_TEXTURE_1D: case WINED3D_RTYPE_TEXTURE_2D: case WINED3D_RTYPE_TEXTURE_3D: for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i) diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 000d0b7546..e1b064d030 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -5312,6 +5312,20 @@ HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT ad gl_type_end = WINED3D_GL_RES_TYPE_TEX_3D; break;
+ case WINED3D_RTYPE_TEXTURE_1D: + allowed_usage = WINED3DUSAGE_AUTOGENMIPMAP + | WINED3DUSAGE_DYNAMIC + | WINED3DUSAGE_SOFTWAREPROCESSING + | WINED3DUSAGE_TEXTURE + | WINED3DUSAGE_QUERY_FILTER + | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING + | WINED3DUSAGE_QUERY_SRGBREAD + | WINED3DUSAGE_QUERY_SRGBWRITE + | WINED3DUSAGE_QUERY_VERTEXTEXTURE + | WINED3DUSAGE_QUERY_WRAPANDMIP; + gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_1D; + break; + case WINED3D_RTYPE_TEXTURE_2D: allowed_usage = WINED3DUSAGE_DEPTHSTENCIL | WINED3DUSAGE_RENDERTARGET diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c index 61ff20679b..82a0082f6d 100644 --- a/dlls/wined3d/resource.c +++ b/dlls/wined3d/resource.c @@ -76,6 +76,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * resource_types[] = { {WINED3D_RTYPE_BUFFER, 0, WINED3D_GL_RES_TYPE_BUFFER}, + {WINED3D_RTYPE_TEXTURE_1D, 0, WINED3D_GL_RES_TYPE_TEX_1D}, {WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_2D}, {WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_RECT}, {WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_RB}, diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index a31baa43a7..c1cceebb58 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -4262,6 +4262,7 @@ const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type) #define WINED3D_TO_STR(x) case x: return #x WINED3D_TO_STR(WINED3D_RTYPE_NONE); WINED3D_TO_STR(WINED3D_RTYPE_BUFFER); + WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_1D); WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D); WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D); #undef WINED3D_TO_STR diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 72168e5fa7..16ea11d8b1 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -676,8 +676,9 @@ enum wined3d_resource_type { WINED3D_RTYPE_NONE = 0, WINED3D_RTYPE_BUFFER = 1, - WINED3D_RTYPE_TEXTURE_2D = 2, - WINED3D_RTYPE_TEXTURE_3D = 3, + WINED3D_RTYPE_TEXTURE_1D = 2, + WINED3D_RTYPE_TEXTURE_2D = 3, + WINED3D_RTYPE_TEXTURE_3D = 4, };
enum wined3d_pool
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/wined3d/view.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index b06daccca1..dce585f6e2 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -59,6 +59,11 @@ static GLenum get_texture_view_target(const struct wined3d_gl_info *gl_info, {GL_TEXTURE_2D_MULTISAMPLE, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_2D_MULTISAMPLE_ARRAY}, {GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0, GL_TEXTURE_2D_MULTISAMPLE}, {GL_TEXTURE_2D_MULTISAMPLE_ARRAY, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_2D_MULTISAMPLE_ARRAY}, + + {GL_TEXTURE_1D, 0, GL_TEXTURE_1D}, + {GL_TEXTURE_1D, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_1D_ARRAY}, + {GL_TEXTURE_1D_ARRAY, 0, GL_TEXTURE_1D}, + {GL_TEXTURE_1D_ARRAY, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_1D_ARRAY}, }; unsigned int i;
2018-02-07 16:35 GMT+01:00 Sven Hesse shesse@codeweavers.com:
Signed-off-by: Sven Hesse shesse@codeweavers.com
dlls/wined3d/view.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index b06daccca1..dce585f6e2 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -59,6 +59,11 @@ static GLenum get_texture_view_target(const struct wined3d_gl_info *gl_info, {GL_TEXTURE_2D_MULTISAMPLE, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_2D_MULTISAMPLE_ARRAY}, {GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0, GL_TEXTURE_2D_MULTISAMPLE}, {GL_TEXTURE_2D_MULTISAMPLE_ARRAY, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_2D_MULTISAMPLE_ARRAY},
{GL_TEXTURE_1D, 0, GL_TEXTURE_1D},
{GL_TEXTURE_1D, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_1D_ARRAY},
{GL_TEXTURE_1D_ARRAY, 0, GL_TEXTURE_1D},
}; unsigned int i;{GL_TEXTURE_1D_ARRAY, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_1D_ARRAY},
Just putting it out there for consideration: what about using GL_TEXTURE_2D and GL_TEXTURE_2D_ARRAY for 1D d3d textures instead? OpenGL ES doesn't support 1D textures so we'd have to add a code path using 2D textures anyway at some point. Also AFAIU 1D textures aren't supported in HW at least on AMD Vega, which means that, in some cases at least, they are emulated on top of 2D textures anyway.
I think that should be mostly a matter of using 2D GL textures and samplers and fixing up texture coordinates in GLSL sample instructions. I haven't put too much thought into it though so there might be some caveat I don't see at the moment.
On 7 February 2018 at 21:55, Matteo Bruni matteo.mystral@gmail.com wrote:
Just putting it out there for consideration: what about using GL_TEXTURE_2D and GL_TEXTURE_2D_ARRAY for 1D d3d textures instead? OpenGL ES doesn't support 1D textures so we'd have to add a code path using 2D textures anyway at some point. Also AFAIU 1D textures aren't supported in HW at least on AMD Vega, which means that, in some cases at least, they are emulated on top of 2D textures anyway.
Yeah. The question is going to be whether on GPUs that do have dedicated hardware for 1D textures there's any advantage to using them. That seems likely, since well, silicon isn't quite free either, but it's not clear to me what the advantage would be.
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/wined3d/context.c | 21 ++++++++++++++++++++- dlls/wined3d/device.c | 26 ++++++++++++++++++++++++++ dlls/wined3d/glsl_shader.c | 7 +++++++ dlls/wined3d/wined3d_private.h | 2 ++ 4 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index f8419f063c..63e2b620b8 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -139,7 +139,8 @@ static void context_attach_gl_texture_fbo(struct wined3d_context *context, gl_info->fbo_ops.glFramebufferTexture(fbo_target, attachment, resource->object, resource->level); } - else if (resource->target == GL_TEXTURE_2D_ARRAY || resource->target == GL_TEXTURE_3D) + else if (resource->target == GL_TEXTURE_1D_ARRAY || resource->target == GL_TEXTURE_2D_ARRAY + || resource->target == GL_TEXTURE_3D) { if (!gl_info->fbo_ops.glFramebufferTextureLayer) { @@ -150,6 +151,12 @@ static void context_attach_gl_texture_fbo(struct wined3d_context *context, gl_info->fbo_ops.glFramebufferTextureLayer(fbo_target, attachment, resource->object, resource->level, resource->layer); } + else if (resource->target == GL_TEXTURE_1D) + { + gl_info->fbo_ops.glFramebufferTexture1D(fbo_target, attachment, + resource->target, resource->object, resource->level); + checkGLcall("glFramebufferTexture1D()"); + } else { gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, attachment, @@ -1708,6 +1715,7 @@ void context_bind_dummy_textures(const struct wined3d_device *device, const stru GL_EXTCALL(glActiveTexture(GL_TEXTURE0 + i)); checkGLcall("glActiveTexture");
+ gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, device->dummy_textures.tex_1d); gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_textures.tex_2d);
if (gl_info->supported[ARB_TEXTURE_RECTANGLE]) @@ -1723,7 +1731,10 @@ void context_bind_dummy_textures(const struct wined3d_device *device, const stru gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, device->dummy_textures.tex_cube_array);
if (gl_info->supported[EXT_TEXTURE_ARRAY]) + { + gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D_ARRAY, device->dummy_textures.tex_1d_array); gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D_ARRAY, device->dummy_textures.tex_2d_array); + }
if (gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT]) gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_BUFFER, device->dummy_textures.tex_buffer); @@ -2704,6 +2715,14 @@ void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint case GL_NONE: /* nothing to do */ break; + case GL_TEXTURE_1D: + gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, device->dummy_textures.tex_1d); + checkGLcall("glBindTexture"); + break; + case GL_TEXTURE_1D_ARRAY: + gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D_ARRAY, device->dummy_textures.tex_1d_array); + checkGLcall("glBindTexture"); + break; case GL_TEXTURE_2D: gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, device->dummy_textures.tex_2d); checkGLcall("glBindTexture"); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 096f4010fb..8558f9018b 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -620,6 +620,17 @@ static void create_dummy_textures(struct wined3d_device *device, struct wined3d_ * to each texture stage when the currently set D3D texture is NULL. */ context_active_texture(context, gl_info, 0);
+ gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_1d); + checkGLcall("glGenTextures"); + TRACE("Dummy 1D texture given name %u.\n", device->dummy_textures.tex_1d); + + gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, device->dummy_textures.tex_1d); + checkGLcall("glBindTexture"); + + gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA8, 1, 0, + GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color); + checkGLcall("glTexImage1D"); + gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_2d); checkGLcall("glGenTextures"); TRACE("Dummy 2D texture given name %u.\n", device->dummy_textures.tex_2d); @@ -696,6 +707,17 @@ static void create_dummy_textures(struct wined3d_device *device, struct wined3d_
if (gl_info->supported[EXT_TEXTURE_ARRAY]) { + gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_1d_array); + checkGLcall("glGenTextures"); + TRACE("Dummy 1D array texture given name %u.\n", device->dummy_textures.tex_1d_array); + + gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D_ARRAY, device->dummy_textures.tex_1d_array); + checkGLcall("glBindTexture"); + + gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA8, 1, 1, 0, + GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, &color); + checkGLcall("glTexImage2D"); + gl_info->gl_ops.gl.p_glGenTextures(1, &device->dummy_textures.tex_2d_array); checkGLcall("glGenTextures"); TRACE("Dummy 2D array texture given name %u.\n", device->dummy_textures.tex_2d_array); @@ -743,7 +765,10 @@ static void destroy_dummy_textures(struct wined3d_device *device, struct wined3d gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_buffer);
if (gl_info->supported[EXT_TEXTURE_ARRAY]) + { + gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_1d_array); gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_2d_array); + }
if (gl_info->supported[ARB_TEXTURE_CUBE_MAP_ARRAY]) gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_cube_array); @@ -757,6 +782,7 @@ static void destroy_dummy_textures(struct wined3d_device *device, struct wined3d if (gl_info->supported[ARB_TEXTURE_RECTANGLE]) gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_rect);
+ gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_1d); gl_info->gl_ops.gl.p_glDeleteTextures(1, &device->dummy_textures.tex_2d);
checkGLcall("Delete dummy textures"); diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 6f54b3177f..d599d68d06 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -2577,6 +2577,13 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont sampler_type = "samplerCube"; break;
+ case WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY: + if (shadow_sampler) + sampler_type = "sampler1DArrayShadow"; + else + sampler_type = "sampler1DArray"; + break; + case WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY: if (shadow_sampler) sampler_type = "sampler2DArrayShadow"; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 334724514d..3d81be359b 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2919,11 +2919,13 @@ struct wined3d_device /* Textures for when no other textures are mapped */ struct { + GLuint tex_1d; GLuint tex_2d; GLuint tex_rect; GLuint tex_3d; GLuint tex_cube; GLuint tex_cube_array; + GLuint tex_1d_array; GLuint tex_2d_array; GLuint tex_buffer; } dummy_textures;
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/wined3d/texture.c | 90 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 20 deletions(-)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index ed1ca21117..99bcfdf888 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1629,6 +1629,41 @@ void wined3d_texture_upload_data(struct wined3d_texture *texture, unsigned int s context, box, data, row_pitch, slice_pitch); }
+/* This call just uploads data, the caller is responsible for binding the + * correct texture. */ +/* Context activation is done by the caller. */ +static void texture1d_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx, + const struct wined3d_context *context, const struct wined3d_box *box, + const struct wined3d_const_bo_address *data, unsigned int row_pitch, unsigned int slice_pitch) +{ + FIXME("Not implemented.\n"); +} + +/* Context activation is done by the caller. */ +static BOOL texture1d_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, + struct wined3d_context *context, DWORD location) +{ + FIXME("Not implemented.\n"); + return FALSE; +} + +static void texture1d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) +{ + FIXME("Not implemented.\n"); +} + +static void texture1d_cleanup_sub_resources(struct wined3d_texture *texture) +{ +} + +static const struct wined3d_texture_ops texture1d_ops = +{ + texture1d_upload_data, + texture1d_load_location, + texture1d_prepare_texture, + texture1d_cleanup_sub_resources, +}; + static void texture2d_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx, const struct wined3d_context *context, const struct wined3d_box *box, const struct wined3d_const_bo_address *data, unsigned int row_pitch, unsigned int slice_pitch) @@ -2050,6 +2085,7 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3 { struct wined3d_device_parent *device_parent = device->device_parent; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; + const struct wined3d_texture_ops *texture_ops; struct wined3d_surface *surfaces; UINT pow2_width, pow2_height; unsigned int i, j; @@ -2160,40 +2196,53 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3 } }
- if (FAILED(hr = wined3d_texture_init(texture, &texture2d_ops, layer_count, level_count, desc, + texture_ops = (desc->resource_type == WINED3D_RTYPE_TEXTURE_1D) ? &texture1d_ops : &texture2d_ops; + if (FAILED(hr = wined3d_texture_init(texture, texture_ops, layer_count, level_count, desc, flags, device, parent, parent_ops, &texture_resource_ops))) { WARN("Failed to initialize texture, returning %#x.\n", hr); return hr; }
- /* Precalculated scaling for 'faked' non power of two texture coords. */ - if (texture->resource.gl_type == WINED3D_GL_RES_TYPE_TEX_RECT) + if (desc->resource_type == WINED3D_RTYPE_TEXTURE_1D) { - texture->pow2_matrix[0] = (float)desc->width; - texture->pow2_matrix[5] = (float)desc->height; - texture->flags &= ~(WINED3D_TEXTURE_POW2_MAT_IDENT | WINED3D_TEXTURE_NORMALIZED_COORDS); - texture->target = GL_TEXTURE_RECTANGLE_ARB; + texture->pow2_matrix[0] = 1.0f; + texture->pow2_matrix[5] = 1.0f; + if (layer_count > 1) + texture->target = GL_TEXTURE_1D_ARRAY; + else + texture->target = GL_TEXTURE_1D; } - else + else if (desc->resource_type == WINED3D_RTYPE_TEXTURE_2D) { - if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED) + /* Precalculated scaling for 'faked' non power of two texture coords. */ + if (texture->resource.gl_type == WINED3D_GL_RES_TYPE_TEX_RECT) { - texture->pow2_matrix[0] = (((float)desc->width) / ((float)pow2_width)); - texture->pow2_matrix[5] = (((float)desc->height) / ((float)pow2_height)); - texture->flags &= ~WINED3D_TEXTURE_POW2_MAT_IDENT; + texture->pow2_matrix[0] = (float)desc->width; + texture->pow2_matrix[5] = (float)desc->height; + texture->flags &= ~(WINED3D_TEXTURE_POW2_MAT_IDENT | WINED3D_TEXTURE_NORMALIZED_COORDS); + texture->target = GL_TEXTURE_RECTANGLE_ARB; } else { - texture->pow2_matrix[0] = 1.0f; - texture->pow2_matrix[5] = 1.0f; + if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED) + { + texture->pow2_matrix[0] = (((float)desc->width) / ((float)pow2_width)); + texture->pow2_matrix[5] = (((float)desc->height) / ((float)pow2_height)); + texture->flags &= ~WINED3D_TEXTURE_POW2_MAT_IDENT; + } + else + { + texture->pow2_matrix[0] = 1.0f; + texture->pow2_matrix[5] = 1.0f; + } + if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) + texture->target = GL_TEXTURE_CUBE_MAP_ARB; + else if (layer_count > 1) + texture->target = GL_TEXTURE_2D_ARRAY; + else + texture->target = GL_TEXTURE_2D; } - if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) - texture->target = GL_TEXTURE_CUBE_MAP_ARB; - else if (layer_count > 1) - texture->target = GL_TEXTURE_2D_ARRAY; - else - texture->target = GL_TEXTURE_2D; } texture->pow2_matrix[10] = 1.0f; texture->pow2_matrix[15] = 1.0f; @@ -2974,6 +3023,7 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct
switch (desc->resource_type) { + case WINED3D_RTYPE_TEXTURE_1D: case WINED3D_RTYPE_TEXTURE_2D: hr = texture_init(object, desc, layer_count, level_count, flags, device, parent, parent_ops); break;
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/wined3d/texture.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 99bcfdf888..d2bc70fae1 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1649,7 +1649,50 @@ static BOOL texture1d_load_location(struct wined3d_texture *texture, unsigned in
static void texture1d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) { - FIXME("Not implemented.\n"); + const struct wined3d_format *format = texture->resource.format; + GLenum internal = srgb ? format->glGammaInternal : format->glInternal; + unsigned int sub_count = texture->level_count * texture->layer_count; + const struct wined3d_gl_info *gl_info = context->gl_info; + unsigned int i; + + wined3d_texture_bind_and_dirtify(texture, context, srgb); + + if (wined3d_texture_use_immutable_storage(texture, gl_info)) + { + if (texture->target == GL_TEXTURE_1D_ARRAY) + { + GL_EXTCALL(glTexStorage2D(GL_TEXTURE_1D_ARRAY, texture->level_count, internal, + wined3d_texture_get_level_width(texture, 0), texture->layer_count)); + checkGLcall("glTexStorage2D"); + } + else + { + GL_EXTCALL(glTexStorage1D(GL_TEXTURE_1D, texture->level_count, internal, + wined3d_texture_get_level_width(texture, 0))); + checkGLcall("glTexStorage1D"); + } + } + else + { + for (i = 0; i < sub_count; ++i) + { + struct wined3d_surface *surface = texture->sub_resources[i].u.surface; + + if (texture->target == GL_TEXTURE_1D_ARRAY) + { + gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_1D_ARRAY, surface->texture_level, internal, + wined3d_texture_get_level_width(texture, i), texture->layer_count, 0, + format->glFormat, format->glType, NULL); + checkGLcall("glTexImage2D"); + } + else + { + gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, surface->texture_level, internal, + wined3d_texture_get_level_width(texture, i), 0, format->glFormat, format->glType, NULL); + checkGLcall("glTexImage1D"); + } + } + } }
static void texture1d_cleanup_sub_resources(struct wined3d_texture *texture)
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/wined3d/texture.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index d2bc70fae1..ff52a820a2 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1636,7 +1636,77 @@ static void texture1d_upload_data(struct wined3d_texture *texture, unsigned int const struct wined3d_context *context, const struct wined3d_box *box, const struct wined3d_const_bo_address *data, unsigned int row_pitch, unsigned int slice_pitch) { - FIXME("Not implemented.\n"); + const struct wined3d_format *format = texture->resource.format; + unsigned int level = sub_resource_idx % texture->level_count; + const struct wined3d_gl_info *gl_info = context->gl_info; + unsigned int x, update_w; + unsigned int dst_row_pitch, dst_slice_pitch; + unsigned int width; + const void *mem = data->addr; + void *converted_mem = NULL; + struct wined3d_surface *surface = texture->sub_resources[sub_resource_idx].u.surface; + + TRACE("texture %p, sub_resource_idx %u, context %p, box %s, data {%#x:%p}, row_pitch %#x, slice_pitch %#x.\n", + texture, sub_resource_idx, context, debug_box(box), + data->buffer_object, data->addr, row_pitch, slice_pitch); + + width = wined3d_texture_get_level_width(texture, level); + + if (!box) + { + x = 0; + update_w = width; + } + else + { + x = box->left; + update_w = box->right - box->left; + } + + if (format->conv_byte_count) + { + if (data->buffer_object) + ERR("Loading a converted texture from a PBO.\n"); + if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS) + ERR("Converting a block-based format.\n"); + + dst_row_pitch = update_w * format->conv_byte_count; + + converted_mem = wined3d_calloc(1, dst_row_pitch); + format->upload(data->addr, converted_mem, row_pitch, slice_pitch, dst_row_pitch, dst_row_pitch, update_w, 1, 1); + mem = converted_mem; + } + else + { + wined3d_texture_get_pitch(texture, sub_resource_idx, &dst_row_pitch, &dst_slice_pitch); + if (row_pitch != dst_row_pitch || slice_pitch != dst_slice_pitch) + FIXME("Ignoring row/slice pitch (%u/%u).\n", row_pitch, slice_pitch); + } + + if (data->buffer_object) + { + GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object)); + checkGLcall("glBindBuffer"); + } + + if (surface->texture_target == GL_TEXTURE_1D_ARRAY) + { + gl_info->gl_ops.gl.p_glTexSubImage2D(GL_TEXTURE_1D_ARRAY, level, x, surface->texture_layer, update_w, 1, format->glFormat, format->glType, mem); + checkGLcall("glTexSubImage2D"); + } + else + { + gl_info->gl_ops.gl.p_glTexSubImage1D(GL_TEXTURE_1D, level, x, update_w, format->glFormat, format->glType, mem); + checkGLcall("glTexSubImage1D"); + } + + if (data->buffer_object) + { + GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0)); + checkGLcall("glBindBuffer"); + } + + HeapFree(GetProcessHeap(), 0, converted_mem); }
/* Context activation is done by the caller. */
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/wined3d/texture.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index ff52a820a2..b9aa477d05 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1709,12 +1709,124 @@ static void texture1d_upload_data(struct wined3d_texture *texture, unsigned int HeapFree(GetProcessHeap(), 0, converted_mem); }
+/* Context activation is done by the caller. */ +static void texture1d_download_data(struct wined3d_texture *texture, unsigned int sub_resource_idx, + const struct wined3d_context *context, const struct wined3d_bo_address *data) +{ + const struct wined3d_format *format = texture->resource.format; + const struct wined3d_gl_info *gl_info = context->gl_info; + struct wined3d_surface *surface = texture->sub_resources[sub_resource_idx].u.surface; + + if (format->conv_byte_count) + { + FIXME("Attempting to download a converted 1d texture, format %s.\n", + debug_d3dformat(format->id)); + return; + } + + if (data->buffer_object) + { + GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object)); + checkGLcall("glBindBuffer"); + } + + gl_info->gl_ops.gl.p_glGetTexImage(surface->texture_target, sub_resource_idx, + format->glFormat, format->glType, data->addr); + checkGLcall("glGetTexImage"); + + if (data->buffer_object) + { + GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0)); + checkGLcall("glBindBuffer"); + } +} + /* Context activation is done by the caller. */ static BOOL texture1d_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location) { - FIXME("Not implemented.\n"); - return FALSE; + struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx]; + unsigned int row_pitch, slice_pitch; + + if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location)) + return FALSE; + + switch (location) + { + case WINED3D_LOCATION_TEXTURE_RGB: + case WINED3D_LOCATION_TEXTURE_SRGB: + if (sub_resource->locations & WINED3D_LOCATION_SYSMEM) + { + struct wined3d_const_bo_address data = {0, texture->resource.heap_memory}; + data.addr += sub_resource->offset; + wined3d_texture_bind_and_dirtify(texture, context, location == WINED3D_LOCATION_TEXTURE_SRGB); + wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch); + texture1d_upload_data(texture, sub_resource_idx, context, NULL, &data, row_pitch, slice_pitch); + } + else if (sub_resource->locations & WINED3D_LOCATION_BUFFER) + { + struct wined3d_const_bo_address data = {sub_resource->buffer_object, NULL}; + wined3d_texture_bind_and_dirtify(texture, context, + location == WINED3D_LOCATION_TEXTURE_SRGB); + wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch); + texture1d_upload_data(texture, sub_resource_idx, context, NULL, &data, row_pitch, slice_pitch); + } + else + { + FIXME("Implement 1d texture loading from %s.\n", wined3d_debug_location(sub_resource->locations)); + return FALSE; + } + break; + + case WINED3D_LOCATION_SYSMEM: + if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB)) + { + struct wined3d_bo_address data = {0, texture->resource.heap_memory}; + + data.addr += sub_resource->offset; + if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB) + wined3d_texture_bind_and_dirtify(texture, context, FALSE); + else + wined3d_texture_bind_and_dirtify(texture, context, TRUE); + + texture1d_download_data(texture, sub_resource_idx, context, &data); + ++texture->download_count; + } + else + { + FIXME("Implement WINED3D_LOCATION_SYSMEM loading from %s.\n", + wined3d_debug_location(sub_resource->locations)); + return FALSE; + } + break; + + case WINED3D_LOCATION_BUFFER: + if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB)) + { + struct wined3d_bo_address data = {sub_resource->buffer_object, NULL}; + + if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB) + wined3d_texture_bind_and_dirtify(texture, context, FALSE); + else + wined3d_texture_bind_and_dirtify(texture, context, TRUE); + + texture1d_download_data(texture, sub_resource_idx, context, &data); + } + else + { + FIXME("Implement WINED3D_LOCATION_BUFFER loading from %s.\n", + wined3d_debug_location(sub_resource->locations)); + return FALSE; + } + break; + + default: + FIXME("Implement %s loading from %s.\n", wined3d_debug_location(location), + wined3d_debug_location(sub_resource->locations)); + return FALSE; + } + + return TRUE; }
static void texture1d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/d3d11/d3d11_private.h | 19 ++ dlls/d3d11/device.c | 13 +- dlls/d3d11/texture.c | 489 +++++++++++++++++++++++++++++++++++++++++++++ dlls/d3d11/utils.c | 8 + 4 files changed, 527 insertions(+), 2 deletions(-)
diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h index 1030b96e7c..567b817457 100644 --- a/dlls/d3d11/d3d11_private.h +++ b/dlls/d3d11/d3d11_private.h @@ -111,6 +111,25 @@ void skip_dword_unknown(const char **ptr, unsigned int count) DECLSPEC_HIDDEN; 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;
+/* ID3D11Texture1D, ID3D10Texture1D */ +struct d3d_texture1d +{ + ID3D11Texture1D ID3D11Texture1D_iface; + ID3D10Texture1D ID3D10Texture1D_iface; + LONG refcount; + + struct wined3d_private_store private_store; + IUnknown *dxgi_surface; + struct wined3d_texture *wined3d_texture; + D3D11_TEXTURE1D_DESC desc; + ID3D11Device *device; +}; + +HRESULT d3d_texture1d_create(struct d3d_device *device, const D3D11_TEXTURE1D_DESC *desc, + const D3D11_SUBRESOURCE_DATA *data, struct d3d_texture1d **texture) DECLSPEC_HIDDEN; +struct d3d_texture1d *unsafe_impl_from_ID3D11Texture1D(ID3D11Texture1D *iface) DECLSPEC_HIDDEN; +struct d3d_texture1d *unsafe_impl_from_ID3D10Texture1D(ID3D10Texture1D *iface) DECLSPEC_HIDDEN; + /* ID3D11Texture2D, ID3D10Texture2D */ struct d3d_texture2d { diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c index b14c3862a1..5fa0df7315 100644 --- a/dlls/d3d11/device.c +++ b/dlls/d3d11/device.c @@ -2739,9 +2739,18 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface, const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture) { - FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture); + struct d3d_device *device = impl_from_ID3D11Device(iface); + struct d3d_texture1d *object; + HRESULT hr;
- return E_NOTIMPL; + TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture); + + if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object))) + return hr; + + *texture = &object->ID3D11Texture1D_iface; + + return S_OK; }
static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface, diff --git a/dlls/d3d11/texture.c b/dlls/d3d11/texture.c index 4d500c9847..6c81f68aa7 100644 --- a/dlls/d3d11/texture.c +++ b/dlls/d3d11/texture.c @@ -25,6 +25,495 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
+/* ID3D11Texture1D methods */ + +static inline struct d3d_texture1d *impl_from_ID3D11Texture1D(ID3D11Texture1D *iface) +{ + return CONTAINING_RECORD(iface, struct d3d_texture1d, ID3D11Texture1D_iface); +} + +static HRESULT STDMETHODCALLTYPE d3d11_texture1d_QueryInterface(ID3D11Texture1D *iface, REFIID riid, void **object) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + if (IsEqualGUID(riid, &IID_ID3D11Texture1D) + || IsEqualGUID(riid, &IID_ID3D11Resource) + || IsEqualGUID(riid, &IID_ID3D11DeviceChild) + || IsEqualGUID(riid, &IID_IUnknown)) + { + *object = &texture->ID3D11Texture1D_iface; + IUnknown_AddRef((IUnknown *)*object); + return S_OK; + } + else if (IsEqualGUID(riid, &IID_ID3D10Texture1D) + || IsEqualGUID(riid, &IID_ID3D10Resource) + || IsEqualGUID(riid, &IID_ID3D10DeviceChild)) + { + *object = &texture->ID3D10Texture1D_iface; + IUnknown_AddRef((IUnknown *)*object); + return S_OK; + } + + if (texture->dxgi_surface) + { + TRACE("Forwarding to dxgi surface.\n"); + return IUnknown_QueryInterface(texture->dxgi_surface, riid, object); + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); + + *object = NULL; + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE d3d11_texture1d_AddRef(ID3D11Texture1D *iface) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + ULONG refcount = InterlockedIncrement(&texture->refcount); + + TRACE("%p increasing refcount to %u.\n", texture, refcount); + + if (refcount == 1) + { + ID3D11Device_AddRef(texture->device); + wined3d_mutex_lock(); + wined3d_texture_incref(texture->wined3d_texture); + wined3d_mutex_unlock(); + } + + return refcount; +} + +static ULONG STDMETHODCALLTYPE d3d11_texture1d_Release(ID3D11Texture1D *iface) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + ULONG refcount = InterlockedDecrement(&texture->refcount); + + TRACE("%p decreasing refcount to %u.\n", texture, refcount); + + if (!refcount) + { + ID3D11Device *device = texture->device; + + wined3d_mutex_lock(); + wined3d_texture_decref(texture->wined3d_texture); + wined3d_mutex_unlock(); + /* Release the device last, it may cause the wined3d device to be + * destroyed. */ + ID3D11Device_Release(device); + } + + return refcount; +} + +static void STDMETHODCALLTYPE d3d11_texture1d_GetDevice(ID3D11Texture1D *iface, ID3D11Device **device) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + + TRACE("iface %p, device %p.\n", iface, device); + + *device = texture->device; + ID3D11Device_AddRef(*device); +} + +static HRESULT STDMETHODCALLTYPE d3d11_texture1d_GetPrivateData(ID3D11Texture1D *iface, + REFGUID guid, UINT *data_size, void *data) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + IDXGISurface *dxgi_surface; + HRESULT hr; + + TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data); + + if (texture->dxgi_surface + && SUCCEEDED(IUnknown_QueryInterface(texture->dxgi_surface, &IID_IDXGISurface, (void **)&dxgi_surface))) + { + hr = IDXGISurface_GetPrivateData(dxgi_surface, guid, data_size, data); + IDXGISurface_Release(dxgi_surface); + return hr; + } + + return d3d_get_private_data(&texture->private_store, guid, data_size, data); +} + +static HRESULT STDMETHODCALLTYPE d3d11_texture1d_SetPrivateData(ID3D11Texture1D *iface, + REFGUID guid, UINT data_size, const void *data) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + IDXGISurface *dxgi_surface; + HRESULT hr; + + TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data); + + if (texture->dxgi_surface + && SUCCEEDED(IUnknown_QueryInterface(texture->dxgi_surface, &IID_IDXGISurface, (void **)&dxgi_surface))) + { + hr = IDXGISurface_SetPrivateData(dxgi_surface, guid, data_size, data); + IDXGISurface_Release(dxgi_surface); + return hr; + } + + return d3d_set_private_data(&texture->private_store, guid, data_size, data); +} + +static HRESULT STDMETHODCALLTYPE d3d11_texture1d_SetPrivateDataInterface(ID3D11Texture1D *iface, + REFGUID guid, const IUnknown *data) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + IDXGISurface *dxgi_surface; + HRESULT hr; + + TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data); + + if (texture->dxgi_surface + && SUCCEEDED(IUnknown_QueryInterface(texture->dxgi_surface, &IID_IDXGISurface, (void **)&dxgi_surface))) + { + hr = IDXGISurface_SetPrivateDataInterface(dxgi_surface, guid, data); + IDXGISurface_Release(dxgi_surface); + return hr; + } + + return d3d_set_private_data_interface(&texture->private_store, guid, data); +} + +static void STDMETHODCALLTYPE d3d11_texture1d_GetType(ID3D11Texture1D *iface, + D3D11_RESOURCE_DIMENSION *resource_dimension) +{ + TRACE("iface %p, resource_dimension %p.\n", iface, resource_dimension); + + *resource_dimension = D3D11_RESOURCE_DIMENSION_TEXTURE1D; +} + +static void STDMETHODCALLTYPE d3d11_texture1d_SetEvictionPriority(ID3D11Texture1D *iface, UINT eviction_priority) +{ + FIXME("iface %p, eviction_priority %#x stub!\n", iface, eviction_priority); +} + +static UINT STDMETHODCALLTYPE d3d11_texture1d_GetEvictionPriority(ID3D11Texture1D *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +static void STDMETHODCALLTYPE d3d11_texture1d_GetDesc(ID3D11Texture1D *iface, D3D11_TEXTURE1D_DESC *desc) +{ + struct d3d_texture1d *texture = impl_from_ID3D11Texture1D(iface); + + TRACE("iface %p, desc %p.\n", iface, desc); + + *desc = texture->desc; +} + +static const struct ID3D11Texture1DVtbl d3d11_texture1d_vtbl = +{ + /* IUnknown methods */ + d3d11_texture1d_QueryInterface, + d3d11_texture1d_AddRef, + d3d11_texture1d_Release, + /* ID3D11DeviceChild methods */ + d3d11_texture1d_GetDevice, + d3d11_texture1d_GetPrivateData, + d3d11_texture1d_SetPrivateData, + d3d11_texture1d_SetPrivateDataInterface, + /* ID3D11Resource methods */ + d3d11_texture1d_GetType, + d3d11_texture1d_SetEvictionPriority, + d3d11_texture1d_GetEvictionPriority, + /* ID3D11Texture1D methods */ + d3d11_texture1d_GetDesc, +}; + +struct d3d_texture1d *unsafe_impl_from_ID3D11Texture1D(ID3D11Texture1D *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d11_texture1d_vtbl); + return CONTAINING_RECORD(iface, struct d3d_texture1d, ID3D11Texture1D_iface); +} + +static inline struct d3d_texture1d *impl_from_ID3D10Texture1D(ID3D10Texture1D *iface) +{ + return CONTAINING_RECORD(iface, struct d3d_texture1d, ID3D10Texture1D_iface); +} + +/* IUnknown methods */ + +static HRESULT STDMETHODCALLTYPE d3d10_texture1d_QueryInterface(ID3D10Texture1D *iface, REFIID riid, void **object) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + return d3d11_texture1d_QueryInterface(&texture->ID3D11Texture1D_iface, riid, object); +} + +static ULONG STDMETHODCALLTYPE d3d10_texture1d_AddRef(ID3D10Texture1D *iface) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p.\n", iface); + + return d3d11_texture1d_AddRef(&texture->ID3D11Texture1D_iface); +} + +static void STDMETHODCALLTYPE d3d_texture1d_wined3d_object_released(void *parent) +{ + struct d3d_texture1d *texture = parent; + + if (texture->dxgi_surface) IUnknown_Release(texture->dxgi_surface); + wined3d_private_store_cleanup(&texture->private_store); + HeapFree(GetProcessHeap(), 0, texture); +} + +static ULONG STDMETHODCALLTYPE d3d10_texture1d_Release(ID3D10Texture1D *iface) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p.\n", iface); + + return d3d11_texture1d_Release(&texture->ID3D11Texture1D_iface); +} + +/* ID3D10DeviceChild methods */ + +static void STDMETHODCALLTYPE d3d10_texture1d_GetDevice(ID3D10Texture1D *iface, ID3D10Device **device) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p, device %p.\n", iface, device); + + ID3D11Device_QueryInterface(texture->device, &IID_ID3D10Device, (void **)device); +} + +static HRESULT STDMETHODCALLTYPE d3d10_texture1d_GetPrivateData(ID3D10Texture1D *iface, + REFGUID guid, UINT *data_size, void *data) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data); + + return d3d11_texture1d_GetPrivateData(&texture->ID3D11Texture1D_iface, guid, data_size, data); +} + +static HRESULT STDMETHODCALLTYPE d3d10_texture1d_SetPrivateData(ID3D10Texture1D *iface, + REFGUID guid, UINT data_size, const void *data) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data); + + return d3d11_texture1d_SetPrivateData(&texture->ID3D11Texture1D_iface, guid, data_size, data); +} + +static HRESULT STDMETHODCALLTYPE d3d10_texture1d_SetPrivateDataInterface(ID3D10Texture1D *iface, + REFGUID guid, const IUnknown *data) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data); + + return d3d11_texture1d_SetPrivateDataInterface(&texture->ID3D11Texture1D_iface, guid, data); +} + +/* ID3D10Resource methods */ + +static void STDMETHODCALLTYPE d3d10_texture1d_GetType(ID3D10Texture1D *iface, + D3D10_RESOURCE_DIMENSION *resource_dimension) +{ + TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension); + + *resource_dimension = D3D10_RESOURCE_DIMENSION_TEXTURE1D; +} + +static void STDMETHODCALLTYPE d3d10_texture1d_SetEvictionPriority(ID3D10Texture1D *iface, UINT eviction_priority) +{ + FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority); +} + +static UINT STDMETHODCALLTYPE d3d10_texture1d_GetEvictionPriority(ID3D10Texture1D *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +/* ID3D10Texture1D methods */ + +static HRESULT STDMETHODCALLTYPE d3d10_texture1d_Map(ID3D10Texture1D *iface, UINT sub_resource_idx, + D3D10_MAP map_type, UINT map_flags, void **ppData) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + struct wined3d_map_desc wined3d_map_desc; + HRESULT hr; + + TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, ppData %p.\n", + iface, sub_resource_idx, map_type, map_flags, ppData); + + if (map_flags) + FIXME("Ignoring map_flags %#x.\n", map_flags); + + wined3d_mutex_lock(); + if (SUCCEEDED(hr = wined3d_resource_map(wined3d_texture_get_resource(texture->wined3d_texture), sub_resource_idx, + &wined3d_map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type)))) + { + *ppData = wined3d_map_desc.data; + } + wined3d_mutex_unlock(); + + return hr; +} + +static void STDMETHODCALLTYPE d3d10_texture1d_Unmap(ID3D10Texture1D *iface, UINT sub_resource_idx) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + + TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx); + + wined3d_mutex_lock(); + wined3d_resource_unmap(wined3d_texture_get_resource(texture->wined3d_texture), sub_resource_idx); + wined3d_mutex_unlock(); +} + +static void STDMETHODCALLTYPE d3d10_texture1d_GetDesc(ID3D10Texture1D *iface, D3D10_TEXTURE1D_DESC *desc) +{ + struct d3d_texture1d *texture = impl_from_ID3D10Texture1D(iface); + D3D11_TEXTURE1D_DESC d3d11_desc; + + TRACE("iface %p, desc %p\n", iface, desc); + + d3d11_texture1d_GetDesc(&texture->ID3D11Texture1D_iface, &d3d11_desc); + + desc->Width = d3d11_desc.Width; + desc->MipLevels = d3d11_desc.MipLevels; + desc->ArraySize = d3d11_desc.ArraySize; + desc->Format = d3d11_desc.Format; + desc->Usage = d3d10_usage_from_d3d11_usage(d3d11_desc.Usage); + desc->BindFlags = d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc.BindFlags); + desc->CPUAccessFlags = d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc.CPUAccessFlags); + desc->MiscFlags = d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc.MiscFlags); +} + +static const struct ID3D10Texture1DVtbl d3d10_texture1d_vtbl = +{ + /* IUnknown methods */ + d3d10_texture1d_QueryInterface, + d3d10_texture1d_AddRef, + d3d10_texture1d_Release, + /* ID3D10DeviceChild methods */ + d3d10_texture1d_GetDevice, + d3d10_texture1d_GetPrivateData, + d3d10_texture1d_SetPrivateData, + d3d10_texture1d_SetPrivateDataInterface, + /* ID3D10Resource methods */ + d3d10_texture1d_GetType, + d3d10_texture1d_SetEvictionPriority, + d3d10_texture1d_GetEvictionPriority, + /* ID3D10Texture1D methods */ + d3d10_texture1d_Map, + d3d10_texture1d_Unmap, + d3d10_texture1d_GetDesc, +}; + +struct d3d_texture1d *unsafe_impl_from_ID3D10Texture1D(ID3D10Texture1D *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d10_texture1d_vtbl); + return CONTAINING_RECORD(iface, struct d3d_texture1d, ID3D10Texture1D_iface); +} + +static const struct wined3d_parent_ops d3d_texture1d_wined3d_parent_ops = +{ + d3d_texture1d_wined3d_object_released, +}; + +HRESULT d3d_texture1d_create(struct d3d_device *device, const D3D11_TEXTURE1D_DESC *desc, + const D3D11_SUBRESOURCE_DATA *data, struct d3d_texture1d **out) +{ + struct wined3d_resource_desc wined3d_desc; + struct d3d_texture1d *texture; + unsigned int levels; + DWORD flags = 0; + HRESULT hr; + + if (!(texture = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*texture)))) + return E_OUTOFMEMORY; + + texture->ID3D11Texture1D_iface.lpVtbl = &d3d11_texture1d_vtbl; + texture->ID3D10Texture1D_iface.lpVtbl = &d3d10_texture1d_vtbl; + texture->refcount = 1; + wined3d_mutex_lock(); + wined3d_private_store_init(&texture->private_store); + texture->desc = *desc; + + wined3d_desc.resource_type = WINED3D_RTYPE_TEXTURE_1D; + wined3d_desc.format = wined3dformat_from_dxgi_format(desc->Format); + wined3d_desc.multisample_type = WINED3D_MULTISAMPLE_NONE; + wined3d_desc.multisample_quality = 0; + wined3d_desc.usage = wined3d_usage_from_d3d11(desc->BindFlags, desc->Usage); + wined3d_desc.access = WINED3D_RESOURCE_ACCESS_GPU; + wined3d_desc.width = desc->Width; + wined3d_desc.height = 1; + wined3d_desc.depth = 1; + wined3d_desc.size = 0; + + levels = desc->MipLevels ? desc->MipLevels : wined3d_log2i(desc->Width) + 1; + + if (desc->MiscFlags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE) + flags |= WINED3D_TEXTURE_CREATE_GET_DC; + + if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &wined3d_desc, + desc->ArraySize, levels, flags, (struct wined3d_sub_resource_data *)data, + texture, &d3d_texture1d_wined3d_parent_ops, &texture->wined3d_texture))) + { + WARN("Failed to create wined3d texture, hr %#x.\n", hr); + wined3d_private_store_cleanup(&texture->private_store); + HeapFree(GetProcessHeap(), 0, texture); + wined3d_mutex_unlock(); + if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DERR_INVALIDCALL) + hr = E_INVALIDARG; + return hr; + } + texture->desc.MipLevels = levels; + + if (desc->MipLevels == 1 && desc->ArraySize == 1) + { + IWineDXGIDevice *wine_device; + + if (FAILED(hr = ID3D10Device1_QueryInterface(&device->ID3D10Device1_iface, &IID_IWineDXGIDevice, + (void **)&wine_device))) + { + ERR("Device should implement IWineDXGIDevice.\n"); + wined3d_texture_decref(texture->wined3d_texture); + wined3d_mutex_unlock(); + return E_FAIL; + } + + hr = IWineDXGIDevice_create_surface(wine_device, texture->wined3d_texture, 0, NULL, + (IUnknown *)&texture->ID3D10Texture1D_iface, (void **)&texture->dxgi_surface); + IWineDXGIDevice_Release(wine_device); + if (FAILED(hr)) + { + ERR("Failed to create DXGI surface, returning %#.x\n", hr); + texture->dxgi_surface = NULL; + wined3d_texture_decref(texture->wined3d_texture); + wined3d_mutex_unlock(); + return hr; + } + } + wined3d_mutex_unlock(); + + ID3D11Device_AddRef(texture->device = &device->ID3D11Device_iface); + + TRACE("Created texture %p.\n", texture); + *out = texture; + + return S_OK; +} + /* ID3D11Texture2D methods */
static HRESULT STDMETHODCALLTYPE d3d11_texture2d_QueryInterface(ID3D11Texture2D *iface, REFIID riid, void **object) diff --git a/dlls/d3d11/utils.c b/dlls/d3d11/utils.c index b3894bbfa5..84a146042a 100644 --- a/dlls/d3d11/utils.c +++ b/dlls/d3d11/utils.c @@ -710,6 +710,10 @@ struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *re return wined3d_buffer_get_resource(unsafe_impl_from_ID3D11Buffer( (ID3D11Buffer *)resource)->wined3d_buffer);
+ case D3D11_RESOURCE_DIMENSION_TEXTURE1D: + return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture1D( + (ID3D11Texture1D *)resource)->wined3d_texture); + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture2D( (ID3D11Texture2D *)resource)->wined3d_texture); @@ -736,6 +740,10 @@ struct wined3d_resource *wined3d_resource_from_d3d10_resource(ID3D10Resource *re return wined3d_buffer_get_resource(unsafe_impl_from_ID3D10Buffer( (ID3D10Buffer *)resource)->wined3d_buffer);
+ case D3D10_RESOURCE_DIMENSION_TEXTURE1D: + return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture1D( + (ID3D10Texture1D *)resource)->wined3d_texture); + case D3D10_RESOURCE_DIMENSION_TEXTURE2D: return wined3d_texture_get_resource(unsafe_impl_from_ID3D10Texture2D( (ID3D10Texture2D *)resource)->wined3d_texture);
Signed-off-by: Sven Hesse shesse@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 787 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 787 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index c0cb9a2400..77159c9e81 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -1824,6 +1824,790 @@ static void test_get_immediate_context(void) ok(!refcount, "Device has %u references left.\n", refcount); }
+static void test_create_texture1d(void) +{ + ULONG refcount, expected_refcount; + D3D11_SUBRESOURCE_DATA data = {0}; + ID3D11Device *device, *tmp; + D3D11_TEXTURE1D_DESC desc; + ID3D11Texture1D *texture; + unsigned int i; + HRESULT hr; + + static const struct + { + DXGI_FORMAT format; + UINT array_size; + D3D11_BIND_FLAG bind_flags; + UINT misc_flags; + BOOL succeeds; + BOOL todo; + } + tests[] = + { + {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE}, + {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE}, + {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE}, + {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE}, + }; + + if (!(device = create_device(NULL))) + { + skip("Failed to create device.\n"); + return; + } + + desc.Width = 512; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + + hr = ID3D11Device_CreateTexture1D(device, &desc, &data, &texture); + ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + + expected_refcount = get_refcount(device) + 1; + hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr); + refcount = get_refcount(device); + ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount); + tmp = NULL; + expected_refcount = refcount + 1; + ID3D11Texture1D_GetDevice(texture, &tmp); + ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device); + refcount = get_refcount(device); + ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount); + ID3D11Device_Release(tmp); + + check_interface(texture, &IID_IDXGISurface, TRUE, FALSE); + ID3D11Texture1D_Release(texture); + + desc.MipLevels = 0; + expected_refcount = get_refcount(device) + 1; + hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr); + refcount = get_refcount(device); + ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount); + tmp = NULL; + expected_refcount = refcount + 1; + ID3D11Texture1D_GetDevice(texture, &tmp); + ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device); + refcount = get_refcount(device); + ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount); + ID3D11Device_Release(tmp); + + ID3D11Texture1D_GetDesc(texture, &desc); + ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width); + ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels); + ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize); + ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format); + ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage); + ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags); + ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags); + ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags); + + check_interface(texture, &IID_IDXGISurface, FALSE, FALSE); + ID3D11Texture1D_Release(texture); + + desc.MipLevels = 1; + desc.ArraySize = 2; + hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr); + + check_interface(texture, &IID_IDXGISurface, FALSE, FALSE); + ID3D11Texture1D_Release(texture); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG; + BOOL todo = tests[i].todo; + + desc.ArraySize = tests[i].array_size; + desc.Format = tests[i].format; + desc.BindFlags = tests[i].bind_flags; + desc.MiscFlags = tests[i].misc_flags; + hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, (ID3D11Texture1D **)&texture); + + todo_wine_if(todo) + ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n", + i, hr, desc.Format); + + if (SUCCEEDED(hr)) + ID3D11Texture1D_Release(texture); + } + + refcount = ID3D11Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +} + +static void test_texture1d_interfaces(void) +{ + ID3D10Texture1D *d3d10_texture; + D3D11_TEXTURE1D_DESC desc; + ID3D11Texture1D *texture; + ID3D11Device *device; + unsigned int i; + ULONG refcount; + HRESULT hr; + + static const struct test + { + BOOL implements_d3d10_interfaces; + UINT bind_flags; + UINT misc_flags; + UINT expected_bind_flags; + UINT expected_misc_flags; + } + desc_conversion_tests[] = + { + { + TRUE, + D3D11_BIND_SHADER_RESOURCE, 0, + D3D10_BIND_SHADER_RESOURCE, 0 + }, + { + TRUE, + D3D11_BIND_UNORDERED_ACCESS, 0, + D3D11_BIND_UNORDERED_ACCESS, 0 + }, + { + FALSE, + 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP, + 0, 0 + }, + { + TRUE, + 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, + 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX + }, + }; + + if (!(device = create_device(NULL))) + { + skip("Failed to create ID3D11Device, skipping tests.\n"); + return; + } + + desc.Width = 512; + desc.MipLevels = 0; + desc.ArraySize = 1; + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_RENDER_TARGET; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + + hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture); + ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr); + check_interface(texture, &IID_IDXGISurface, FALSE, FALSE); + hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */ + ID3D11Texture1D_Release(texture); + if (FAILED(hr)) + { + win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n"); + ID3D11Device_Release(device); + return; + } + + for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i) + { + const struct test *current = &desc_conversion_tests[i]; + D3D10_TEXTURE1D_DESC d3d10_desc; + ID3D10Device *d3d10_device; + + desc.Width = 512; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = current->bind_flags; + desc.CPUAccessFlags = 0; + desc.MiscFlags = current->misc_flags; + + hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture); + /* Shared resources are not supported by REF and WARP devices. */ + ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), + "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr); + if (FAILED(hr)) + { + win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i); + continue; + } + + check_interface(texture, &IID_IDXGISurface, TRUE, FALSE); + + hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture); + ID3D11Texture1D_Release(texture); + + if (current->implements_d3d10_interfaces) + { + ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i); + } + else + { + todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i); + if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture); + continue; + } + + ID3D10Texture1D_GetDesc(d3d10_texture, &d3d10_desc); + + ok(d3d10_desc.Width == desc.Width, + "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width); + ok(d3d10_desc.MipLevels == desc.MipLevels, + "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels); + ok(d3d10_desc.ArraySize == desc.ArraySize, + "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize); + ok(d3d10_desc.Format == desc.Format, + "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format); + ok(d3d10_desc.BindFlags == current->expected_bind_flags, + "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags); + ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags, + "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags); + ok(d3d10_desc.MiscFlags == current->expected_misc_flags, + "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags); + + d3d10_device = (ID3D10Device *)0xdeadbeef; + ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device); + todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device); + if (d3d10_device) ID3D10Device_Release(d3d10_device); + + ID3D10Texture1D_Release(d3d10_texture); + } + + refcount = ID3D11Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +} + +static void test_texture1d(void) +{ + struct shader + { + const DWORD *code; + size_t size; + }; + struct texture + { + UINT width; + UINT miplevel_count; + UINT array_size; + DXGI_FORMAT format; + D3D11_SUBRESOURCE_DATA data[3]; + }; + + D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc; + struct d3d11_test_context test_context; + const struct texture *current_texture; + D3D11_TEXTURE1D_DESC texture_desc; + D3D11_SAMPLER_DESC sampler_desc; + const struct shader *current_ps; + D3D_FEATURE_LEVEL feature_level; + ID3D11ShaderResourceView *srv; + ID3D11DeviceContext *context; + ID3D11SamplerState *sampler; + struct resource_readback rb; + ID3D11Texture1D *texture; + struct vec4 ps_constant; + ID3D11PixelShader *ps; + ID3D11Device *device; + unsigned int i, x; + ID3D11Buffer *cb; + DWORD color; + HRESULT hr; + + static const DWORD ps_ld_code[] = + { +#if 0 + Texture1D t; + + float miplevel; + + float4 main(float4 position : SV_POSITION) : SV_TARGET + { + float2 p; + t.GetDimensions(miplevel, p.x, p.y); + p.y = miplevel; + p *= float2(position.x / 640.0f, 1.0f); + return t.Load(int2(p)); + } +#endif + 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, + 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000, + 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, + 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, + 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, + 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2, + 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, + 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2, + 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, + 0x00107e46, 0x00000000, 0x0100003e, + }; + static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)}; + static const DWORD ps_ld_sint8_code[] = + { +#if 0 + Texture1D<int4> t; + + float4 main(float4 position : SV_POSITION) : SV_TARGET + { + float2 p, s; + int4 c; + + p = float2(position.x / 640.0f, 0.0f); + t.GetDimensions(0, s.x, s.y); + p *= s; + + c = t.Load(int2(p)); + return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f; + } +#endif + 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040, + 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000, + 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, + 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001, + 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6, + 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, + 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b, + 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, + 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2, + 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000, + 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, + 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, + 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e, + }; + static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)}; + static const DWORD ps_ld_uint8_code[] = + { +#if 0 + Texture1D<uint4> t; + + float4 main(float4 position : SV_POSITION) : SV_TARGET + { + float2 p, s; + + p = float2(position.x / 640.0f, 0.0f); + t.GetDimensions(0, s.x, s.y); + p *= s; + + return t.Load(int2(p)) / (float4)255; + } +#endif + 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040, + 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000, + 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, + 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001, + 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6, + 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, + 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, + 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, + 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e, + }; + static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)}; + static DWORD ps_ld_array_code[] = + { +#if 0 + Texture1DArray t; + + float miplevel; + + float4 main(float4 position : SV_POSITION) : SV_TARGET + { + float3 p; + t.GetDimensions(miplevel, p.x, p.y, p.z); + p.y = 1; + p.z = miplevel; + p *= float3(position.x / 640.0f, 1.0f, 1.0f); + return t.Load(int3(p)); + } +#endif + 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003, + 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040, + 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000, + 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, + 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, + 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, + 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2, + 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386, + 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2, + 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001, + 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, + }; + static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)}; + + static const DWORD rgba_level_0[] = + { + 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00, + }; + static const DWORD rgba_level_1[] = + { + 0xffffffff, 0xff0000ff, + }; + static const DWORD rgba_level_2[] = + { + 0xffff0000, + }; + static const DWORD srgb_data[] = + { + 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f, + }; + static const DWORD r32_uint[] = + { + 0, 1, 2, 3, + }; + static const DWORD r9g9b9e5_data[] = + { + 0x80000100, 0x80020000, 0x84000000, 0x84000100, + }; + static const DWORD array_data0[] = + { + 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00, + }; + static const DWORD array_data1[] = + { + 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff, + }; + static const DWORD array_data2[] = + { + 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000, + }; + static const struct texture rgba_texture = + { + 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM, + { + {rgba_level_0, 4 * sizeof(*rgba_level_0), 0}, + {rgba_level_1, 2 * sizeof(*rgba_level_1), 0}, + {rgba_level_2, sizeof(*rgba_level_2), 0}, + } + }; + static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, + {{srgb_data, 4 * sizeof(*srgb_data)}}}; + static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT, + {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}}; + static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT, + {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}}; + static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS, + {{r32_uint, 4 * sizeof(*r32_uint)}}}; + static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, + {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}}; + static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, + { + {array_data0, 4 * sizeof(*array_data0)}, + {array_data1, 4 * sizeof(*array_data1)}, + {array_data2, 4 * sizeof(*array_data2)}, + } + }; + + static const DWORD level_1_colors[] = + { + 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff, + }; + static const DWORD level_2_colors[] = + { + 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, + }; + static const DWORD srgb_colors[] = + { + 0x00000001, 0xffffffff, 0xff000000, 0x7f363636, + }; + static const DWORD sint8_colors[] = + { + 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80, + }; + static const DWORD r32u_colors[4] = + { + 0x01000000, 0x01000001, 0x01000002, 0x01000003, + }; + static const DWORD r9g9b9e5_colors[4] = + { + 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff, + }; + static const DWORD zero_colors[4] = {0}; + static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f}; + static const struct texture_test + { + const struct shader *ps; + const struct texture *texture; + D3D11_FILTER filter; + float lod_bias; + float min_lod; + float max_lod; + float ps_constant; + const DWORD *expected_colors; + } + texture_tests[] = + { +#define POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR +#define MIP_MAX D3D11_FLOAT32_MAX + {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0}, + {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors}, + {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors}, + {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors}, + {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors}, + {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors}, + {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors}, + {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors}, + {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors}, + {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0}, + {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1}, + }; +#undef POINT +#undef POINT_LINEAR +#undef MIP_MAX + static const struct srv_test + { + const struct shader *ps; + const struct texture *texture; + struct srv_desc srv_desc; + float ps_constant; + const DWORD *expected_colors; + } + srv_tests[] = + { +#define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D +#define R32_UINT DXGI_FORMAT_R32_UINT + {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors}, +#undef TEX_1D +#undef R32_UINT +#undef FMT_UNKNOWN + }; + + if (!init_test_context(&test_context, NULL)) + return; + + device = test_context.device; + context = test_context.immediate_context; + feature_level = ID3D11Device_GetFeatureLevel(device); + + cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL); + + ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb); + + texture_desc.Usage = D3D11_USAGE_DEFAULT; + texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + sampler_desc.MipLODBias = 0.0f; + sampler_desc.MaxAnisotropy = 0; + sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER; + sampler_desc.BorderColor[0] = 0.0f; + sampler_desc.BorderColor[1] = 0.0f; + sampler_desc.BorderColor[2] = 0.0f; + sampler_desc.BorderColor[3] = 0.0f; + sampler_desc.MinLOD = 0.0f; + sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; + + ps = NULL; + srv = NULL; + sampler = NULL; + texture = NULL; + current_ps = NULL; + current_texture = NULL; + for (i = 0; i < ARRAY_SIZE(texture_tests); ++i) + { + const struct texture_test *test = &texture_tests[i]; + + if (current_ps != test->ps) + { + if (ps) + ID3D11PixelShader_Release(ps); + + current_ps = test->ps; + + hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps); + ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr); + + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + } + + if (current_texture != test->texture) + { + if (texture) + ID3D11Texture1D_Release(texture); + if (srv) + ID3D11ShaderResourceView_Release(srv); + + current_texture = test->texture; + + if (current_texture) + { + texture_desc.Width = current_texture->width; + texture_desc.MipLevels = current_texture->miplevel_count; + texture_desc.ArraySize = current_texture->array_size; + texture_desc.Format = current_texture->format; + + hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture); + ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr); + + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv); + ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr); + } + else + { + texture = NULL; + srv = NULL; + } + + ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv); + } + + if (!sampler || (sampler_desc.Filter != test->filter + || sampler_desc.MipLODBias != test->lod_bias + || sampler_desc.MinLOD != test->min_lod + || sampler_desc.MaxLOD != test->max_lod)) + { + if (sampler) + ID3D11SamplerState_Release(sampler); + + sampler_desc.Filter = test->filter; + sampler_desc.MipLODBias = test->lod_bias; + sampler_desc.MinLOD = test->min_lod; + sampler_desc.MaxLOD = test->max_lod; + + hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler); + ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr); + + ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler); + } + + ps_constant.x = test->ps_constant; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + for (x = 0; x < 4; ++x) + { + color = get_readback_color(&rb, 80 + x * 160, 0); + ok(compare_color(color, test->expected_colors[x], 2), + "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x); + } + release_resource_readback(&rb); + } + if (srv) + ID3D11ShaderResourceView_Release(srv); + ID3D11SamplerState_Release(sampler); + if (texture) + ID3D11Texture1D_Release(texture); + ID3D11PixelShader_Release(ps); + + if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0) + { + win_skip("SRV tests are broken on WARP.\n"); + ID3D11Buffer_Release(cb); + release_test_context(&test_context); + return; + } + + sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + sampler_desc.MipLODBias = 0.0f; + sampler_desc.MinLOD = 0.0f; + sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; + + hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler); + ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr); + + ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler); + + ps = NULL; + srv = NULL; + texture = NULL; + current_ps = NULL; + current_texture = NULL; + for (i = 0; i < ARRAY_SIZE(srv_tests); ++i) + { + const struct srv_test *test = &srv_tests[i]; + + if (current_ps != test->ps) + { + if (ps) + ID3D11PixelShader_Release(ps); + + current_ps = test->ps; + + hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps); + ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr); + + ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0); + } + + if (current_texture != test->texture) + { + if (texture) + ID3D11Texture1D_Release(texture); + + current_texture = test->texture; + + texture_desc.Width = current_texture->width; + texture_desc.MipLevels = current_texture->miplevel_count; + texture_desc.ArraySize = current_texture->array_size; + texture_desc.Format = current_texture->format; + + hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture); + ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr); + } + + if (srv) + ID3D11ShaderResourceView_Release(srv); + + get_srv_desc(&srv_desc, &test->srv_desc); + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv); + ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr); + + ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv); + + ps_constant.x = test->ps_constant; + ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0); + + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red); + + draw_quad(&test_context); + + get_texture_readback(test_context.backbuffer, 0, &rb); + for (x = 0; x < 4; ++x) + { + color = get_readback_color(&rb, 80 + x * 160, 0); + ok(compare_color(color, test->expected_colors[x], 1), + "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x); + } + release_resource_readback(&rb); + } + ID3D11PixelShader_Release(ps); + ID3D11Texture1D_Release(texture); + ID3D11ShaderResourceView_Release(srv); + ID3D11SamplerState_Release(sampler); + + ID3D11Buffer_Release(cb); + release_test_context(&test_context); +} + static void test_create_texture2d(void) { ULONG refcount, expected_refcount; @@ -24821,6 +25605,8 @@ START_TEST(d3d11) test_create_device(); run_for_each_feature_level(test_device_interfaces); test_get_immediate_context(); + test_create_texture1d(); + test_texture1d_interfaces(); test_create_texture2d(); test_texture2d_interfaces(); test_create_texture3d(); @@ -24845,6 +25631,7 @@ START_TEST(d3d11) test_device_context_state(); test_blend(); test_texture(); + test_texture1d(); test_cube_maps(); test_depth_stencil_sampling(); test_sample_c_lz();