| 896 | return res; |
| 897 | } |
| 898 | id define_sampler(const location &loc, const texture &tex_info, sampler &info) override |
| 899 | { |
| 900 | const id res = info.id = create_block(); |
| 901 | define_name<naming::unique>(res, info.unique_name); |
| 902 | |
| 903 | std::string &code = _blocks.at(res); |
| 904 | |
| 905 | // Default to a register index equivalent to the entry in the sampler list (this is later overwritten in 'finalize_code_for_entry_point' to a more optimal placement) |
| 906 | const uint32_t default_binding = static_cast<uint32_t>(_module.samplers.size()); |
| 907 | uint32_t sampler_state_binding = 0; |
| 908 | |
| 909 | if (_shader_model >= 40) |
| 910 | { |
| 911 | // Try and reuse a sampler binding with the same sampler description |
| 912 | const auto existing_sampler_it = std::find_if(_sampler_lookup.begin(), _sampler_lookup.end(), |
| 913 | [this, &info](const sampler_binding &existing_binding) { |
| 914 | const sampler_desc &existing_info = _module.samplers[existing_binding.index]; |
| 915 | return |
| 916 | existing_info.filter == info.filter && |
| 917 | existing_info.address_u == info.address_u && |
| 918 | existing_info.address_v == info.address_v && |
| 919 | existing_info.address_w == info.address_w && |
| 920 | existing_info.min_lod == info.min_lod && |
| 921 | existing_info.max_lod == info.max_lod && |
| 922 | existing_info.lod_bias == info.lod_bias; |
| 923 | }); |
| 924 | if (existing_sampler_it != _sampler_lookup.end()) |
| 925 | { |
| 926 | sampler_state_binding = existing_sampler_it->entry_point_binding; |
| 927 | } |
| 928 | else |
| 929 | { |
| 930 | sampler_state_binding = static_cast<uint32_t>(_sampler_lookup.size()); |
| 931 | |
| 932 | sampler_binding s; |
| 933 | s.index = default_binding; |
| 934 | s.entry_point_binding = sampler_state_binding; |
| 935 | _sampler_lookup.push_back(std::move(s)); |
| 936 | |
| 937 | if (_shader_model >= 60) |
| 938 | _blocks.at(0) += "[[vk::binding(" + std::to_string(sampler_state_binding) + ", 1)]] "; // Descriptor set 1 |
| 939 | |
| 940 | _blocks.at(0) += "SamplerState __s" + std::to_string(sampler_state_binding) + " : register(s" + std::to_string(sampler_state_binding) + ");\n"; |
| 941 | } |
| 942 | |
| 943 | if (_shader_model >= 60) |
| 944 | code += "[[vk::binding(" + std::to_string(default_binding) + ", 2)]] "; // Descriptor set 2 |
| 945 | |
| 946 | code += "Texture"; |
| 947 | code += to_digit(static_cast<unsigned int>(tex_info.type)); |
| 948 | code += "D<"; |
| 949 | write_texture_format(code, tex_info.format); |
| 950 | code += "> __" + info.unique_name + "_t : register(t" + std::to_string(default_binding) + "); \n"; |
| 951 | |
| 952 | write_location(code, loc); |
| 953 | |
| 954 | code += "static const "; |
| 955 | write_type(code, info.type, tex_info.format); |
nothing calls this directly
no test coverage detected