Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/directx.c | 2 ++ dlls/wined3d/glsl_shader.c | 43 ++++++++++++++++++++++++++++++++++++++++++- dlls/wined3d/shader.c | 3 ++- dlls/wined3d/wined3d_gl.h | 1 + 4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 7deefaf82dcd..44dcf048535e 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -162,6 +162,7 @@ static const struct wined3d_extension_map gl_extension_map[] = {"GL_ARB_shader_image_load_store", ARB_SHADER_IMAGE_LOAD_STORE }, {"GL_ARB_shader_image_size", ARB_SHADER_IMAGE_SIZE }, {"GL_ARB_shader_storage_buffer_object", ARB_SHADER_STORAGE_BUFFER_OBJECT}, + {"GL_ARB_shader_texture_image_samples", ARB_SHADER_TEXTURE_IMAGE_SAMPLES}, {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD }, {"GL_ARB_shading_language_100", ARB_SHADING_LANGUAGE_100 }, {"GL_ARB_shading_language_420pack", ARB_SHADING_LANGUAGE_420PACK }, @@ -3934,6 +3935,7 @@ static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter, {ARB_CLIP_CONTROL, MAKEDWORD_VERSION(4, 5)}, {ARB_CULL_DISTANCE, MAKEDWORD_VERSION(4, 5)}, {ARB_DERIVATIVE_CONTROL, MAKEDWORD_VERSION(4, 5)}, + {ARB_SHADER_TEXTURE_IMAGE_SAMPLES, MAKEDWORD_VERSION(4, 5)},
{ARB_PIPELINE_STATISTICS_QUERY, MAKEDWORD_VERSION(4, 6)}, {ARB_TEXTURE_FILTER_ANISOTROPIC, MAKEDWORD_VERSION(4, 6)}, diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index a9af9acd31f4..b8112ac87bf1 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -6021,6 +6021,45 @@ static void shader_glsl_resinfo(const struct wined3d_shader_instruction *ins) shader_addline(buffer, ")%s);\n", dst_swizzle); }
+static void shader_glsl_sample_info(const struct wined3d_shader_instruction *ins) +{ + const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps; + const struct wined3d_gl_info *gl_info = ins->ctx->gl_info; + struct wined3d_string_buffer *buffer = ins->ctx->buffer; + enum wined3d_shader_resource_type resource_type; + enum wined3d_data_type dst_data_type; + unsigned int resource_idx, bind_idx; + char dst_swizzle[6]; + DWORD write_mask; + + if (!gl_info->supported[ARB_SHADER_TEXTURE_IMAGE_SAMPLES]) + { + FIXME("textureSamples() is not supported.\n"); + return; + } + + dst_data_type = ins->dst[0].reg.data_type; + if (ins->flags == WINED3DSI_SAMPLE_INFO_UINT) + dst_data_type = WINED3D_DATA_UINT; + else if (ins->flags) + FIXME("Unhandled flags %#x.\n", ins->flags); + + resource_idx = ins->src[0].reg.idx[0].offset; + resource_type = reg_maps->resource_info[resource_idx].type; + if (resource_type >= ARRAY_SIZE(resource_type_info)) + { + ERR("Unexpected resource type %#x.\n", resource_type); + return; + } + bind_idx = shader_glsl_find_sampler(®_maps->sampler_map, resource_idx, WINED3D_SAMPLER_DEFAULT); + + write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], dst_data_type); + shader_glsl_get_swizzle(&ins->src[0], FALSE, write_mask, dst_swizzle); + shader_addline(buffer, "%s(textureSamples(%s_sampler%u), 0, 0, 0)%s);\n", + dst_data_type == WINED3D_DATA_UINT ? "uvec4" : "vec4", + shader_glsl_get_prefix(reg_maps->shader_version.type), bind_idx, dst_swizzle); +} + static void shader_glsl_ld(const struct wined3d_shader_instruction *ins) { const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps; @@ -7513,6 +7552,8 @@ static void shader_glsl_enable_extensions(struct wined3d_string_buffer *buffer, shader_addline(buffer, "#extension GL_ARB_shader_image_size : enable\n"); if (gl_info->supported[ARB_SHADER_STORAGE_BUFFER_OBJECT]) shader_addline(buffer, "#extension GL_ARB_shader_storage_buffer_object : enable\n"); + if (gl_info->supported[ARB_SHADER_TEXTURE_IMAGE_SAMPLES]) + shader_addline(buffer, "#extension GL_ARB_shader_texture_image_samples : enable\n"); if (gl_info->supported[ARB_SHADING_LANGUAGE_420PACK]) shader_addline(buffer, "#extension GL_ARB_shading_language_420pack : enable\n"); if (gl_info->supported[ARB_SHADING_LANGUAGE_PACKING]) @@ -11308,7 +11349,7 @@ static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TAB /* WINED3DSIH_SAMPLE_C */ shader_glsl_sample_c, /* WINED3DSIH_SAMPLE_C_LZ */ shader_glsl_sample_c, /* WINED3DSIH_SAMPLE_GRAD */ shader_glsl_sample, - /* WINED3DSIH_SAMPLE_INFO */ NULL, + /* WINED3DSIH_SAMPLE_INFO */ shader_glsl_sample_info, /* WINED3DSIH_SAMPLE_LOD */ shader_glsl_sample, /* WINED3DSIH_SAMPLE_POS */ NULL, /* WINED3DSIH_SETP */ NULL, diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 3750deea148a..be1b5962ed5d 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -1712,7 +1712,8 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co shader_record_sample(reg_maps, ins.src[2].reg.idx[0].offset, ins.src[3].reg.idx[0].offset, reg_maps->sampler_map.count); } - else if (ins.handler_idx == WINED3DSIH_BUFINFO && ins.src[0].reg.type == WINED3DSPR_RESOURCE) + else if ((ins.handler_idx == WINED3DSIH_BUFINFO && ins.src[0].reg.type == WINED3DSPR_RESOURCE) + || ins.handler_idx == WINED3DSIH_SAMPLE_INFO) { shader_record_sample(reg_maps, ins.src[0].reg.idx[0].offset, WINED3D_SAMPLER_DEFAULT, reg_maps->sampler_map.count); diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h index 49205f9c1205..db1929dbcbce 100644 --- a/dlls/wined3d/wined3d_gl.h +++ b/dlls/wined3d/wined3d_gl.h @@ -95,6 +95,7 @@ enum wined3d_gl_extension ARB_SHADER_IMAGE_LOAD_STORE, ARB_SHADER_IMAGE_SIZE, ARB_SHADER_STORAGE_BUFFER_OBJECT, + ARB_SHADER_TEXTURE_IMAGE_SAMPLES, ARB_SHADER_TEXTURE_LOD, ARB_SHADING_LANGUAGE_100, ARB_SHADING_LANGUAGE_420PACK,
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/texture.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index dadcd0323a0f..0b0545394cc7 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1919,15 +1919,20 @@ void wined3d_texture_upload_data(struct wined3d_texture *texture, unsigned int s target = wined3d_texture_get_sub_resource_target(texture, sub_resource_idx); level = sub_resource_idx % texture->level_count;
- if (target == GL_TEXTURE_1D_ARRAY) - { - dst_y = sub_resource_idx / texture->level_count; - update_h = 1; - } - else if (target == GL_TEXTURE_2D_ARRAY) + switch (target) { - dst_z = sub_resource_idx / texture->level_count; - update_d = 1; + case GL_TEXTURE_1D_ARRAY: + dst_y = sub_resource_idx / texture->level_count; + update_h = 1; + break; + case GL_TEXTURE_2D_ARRAY: + dst_z = sub_resource_idx / texture->level_count; + update_d = 1; + break; + case GL_TEXTURE_2D_MULTISAMPLE: + case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: + FIXME("Not supported for multisample textures.\n"); + return; }
bo.buffer_object = data->buffer_object;
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 63f964a46140..35341d79af84 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -26567,6 +26567,143 @@ static void test_multisample_resolve(void) release_test_context(&test_context); }
+static void test_sampleinfo_instruction(void) +{ + ID3D11Texture2D *float_rt_texture, *uint_rt_texture; + ID3D11RenderTargetView *float_rtv, *uint_rtv; + struct d3d11_test_context test_context; + ID3D11PixelShader *ps_float, *ps_uint; + unsigned int sample_count, quality; + D3D11_TEXTURE2D_DESC texture_desc; + ID3D11RenderTargetView *rtvs[2]; + ID3D11ShaderResourceView *srv; + ID3D11DeviceContext *context; + struct uvec4 expected_uint; + struct vec4 expected_float; + ID3D11Resource *texture; + ID3D11Device *device; + HRESULT hr; + + static const DWORD ps_uint_code[] = + { +#if 0 + Texture2DMS<float> t; + + uint4 main() : SV_Target1 + { + uint width, height, sample_count; + t.GetDimensions(width, height, sample_count); + return sample_count; + } +#endif + 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017, + 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001, + 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036, + 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e, + }; + static const DWORD ps_float_code[] = + { +#if 0 + Texture2DMS<float> t; + + float4 main() : SV_Target + { + uint width, height, sample_count; + t.GetDimensions(width, height, sample_count); + return sample_count; + } +#endif + 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010, + 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, + 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e, + }; + static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0; + + if (!init_test_context(&test_context, &feature_level)) + return; + + device = test_context.device; + context = test_context.immediate_context; + + texture_desc.Width = 64; + texture_desc.Height = 64; + texture_desc.MipLevels = 1; + texture_desc.ArraySize = 1; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.Usage = D3D11_USAGE_DEFAULT; + texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture); + ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr); + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv); + ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr); + texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT; + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture); + ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr); + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv); + ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr); + + rtvs[0] = float_rtv; + rtvs[1] = uint_rtv; + ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL); + + hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float); + ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr); + hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint); + ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr); + + for (sample_count = 2; sample_count <= 8; sample_count *= 2) + { + texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + texture_desc.SampleDesc.Count = sample_count; + texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; + + if (FAILED(hr = ID3D11Device_CheckMultisampleQualityLevels(device, + texture_desc.Format, sample_count, &quality))) + { + skip("Sample count %u not supported.\n", sample_count); + continue; + } + + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture); + ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count); + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv); + ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr); + ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv); + + ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0); + draw_quad(&test_context); + ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0); + draw_quad(&test_context); + + expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count; + check_texture_vec4(float_rt_texture, &expected_float, 0); + expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count; + check_texture_uvec4(uint_rt_texture, &expected_uint); + + ID3D11Resource_Release(texture); + ID3D11ShaderResourceView_Release(srv); + } + + ID3D11RenderTargetView_Release(float_rtv); + ID3D11RenderTargetView_Release(uint_rtv); + ID3D11Texture2D_Release(float_rt_texture); + ID3D11Texture2D_Release(uint_rt_texture); + ID3D11PixelShader_Release(ps_float); + ID3D11PixelShader_Release(ps_uint); + release_test_context(&test_context); +} + START_TEST(d3d11) { unsigned int argc, i; @@ -26704,4 +26841,5 @@ START_TEST(d3d11) test_unbound_multisample_texture(); test_multiple_viewports(); test_multisample_resolve(); + test_sampleinfo_instruction(); }