mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
VideoCommon: Expose SamplerState to shaders
The benefit to exposing this over the raw BP state is that adjustments Dolphin makes, such as LOD biases from arbitrary mipmap detection, will work properly.
This commit is contained in:
@ -315,28 +315,28 @@ VkSampler ObjectCache::GetSampler(const SamplerState& info)
|
||||
VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT}};
|
||||
|
||||
VkSamplerCreateInfo create_info = {
|
||||
VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void* pNext
|
||||
0, // VkSamplerCreateFlags flags
|
||||
filters[static_cast<u32>(info.mag_filter.Value())], // VkFilter magFilter
|
||||
filters[static_cast<u32>(info.min_filter.Value())], // VkFilter minFilter
|
||||
mipmap_modes[static_cast<u32>(info.mipmap_filter.Value())], // VkSamplerMipmapMode mipmapMode
|
||||
address_modes[static_cast<u32>(info.wrap_u.Value())], // VkSamplerAddressMode addressModeU
|
||||
address_modes[static_cast<u32>(info.wrap_v.Value())], // VkSamplerAddressMode addressModeV
|
||||
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeW
|
||||
info.lod_bias / 256.0f, // float mipLodBias
|
||||
VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void* pNext
|
||||
0, // VkSamplerCreateFlags flags
|
||||
filters[u32(info.tm0.mag_filter.Value())], // VkFilter magFilter
|
||||
filters[u32(info.tm0.min_filter.Value())], // VkFilter minFilter
|
||||
mipmap_modes[u32(info.tm0.mipmap_filter.Value())], // VkSamplerMipmapMode mipmapMode
|
||||
address_modes[u32(info.tm0.wrap_u.Value())], // VkSamplerAddressMode addressModeU
|
||||
address_modes[u32(info.tm0.wrap_v.Value())], // VkSamplerAddressMode addressModeV
|
||||
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeW
|
||||
info.tm0.lod_bias / 256.0f, // float mipLodBias
|
||||
VK_FALSE, // VkBool32 anisotropyEnable
|
||||
0.0f, // float maxAnisotropy
|
||||
VK_FALSE, // VkBool32 compareEnable
|
||||
VK_COMPARE_OP_ALWAYS, // VkCompareOp compareOp
|
||||
info.min_lod / 16.0f, // float minLod
|
||||
info.max_lod / 16.0f, // float maxLod
|
||||
info.tm1.min_lod / 16.0f, // float minLod
|
||||
info.tm1.max_lod / 16.0f, // float maxLod
|
||||
VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, // VkBorderColor borderColor
|
||||
VK_FALSE // VkBool32 unnormalizedCoordinates
|
||||
};
|
||||
|
||||
// Can we use anisotropic filtering with this sampler?
|
||||
if (info.anisotropic_filtering && g_vulkan_context->SupportsAnisotropicFiltering())
|
||||
if (info.tm0.anisotropic_filtering && g_vulkan_context->SupportsAnisotropicFiltering())
|
||||
{
|
||||
// Cap anisotropy to device limits.
|
||||
create_info.anisotropyEnable = VK_TRUE;
|
||||
|
@ -49,7 +49,7 @@ Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale
|
||||
{
|
||||
UpdateActiveConfig();
|
||||
for (SamplerState& m_sampler_state : m_sampler_states)
|
||||
m_sampler_state.hex = RenderState::GetPointSamplerState().hex;
|
||||
m_sampler_state = RenderState::GetPointSamplerState();
|
||||
}
|
||||
|
||||
Renderer::~Renderer() = default;
|
||||
@ -545,7 +545,7 @@ void Renderer::SetTexture(u32 index, const AbstractTexture* texture)
|
||||
void Renderer::SetSamplerState(u32 index, const SamplerState& state)
|
||||
{
|
||||
// Skip lookup if the state hasn't changed.
|
||||
if (m_sampler_states[index].hex == state.hex)
|
||||
if (m_sampler_states[index] == state)
|
||||
return;
|
||||
|
||||
// Look up new state and replace in state tracker.
|
||||
@ -557,7 +557,7 @@ void Renderer::SetSamplerState(u32 index, const SamplerState& state)
|
||||
}
|
||||
|
||||
StateTracker::GetInstance()->SetSampler(index, sampler);
|
||||
m_sampler_states[index].hex = state.hex;
|
||||
m_sampler_states[index] = state;
|
||||
}
|
||||
|
||||
void Renderer::SetComputeImageTexture(AbstractTexture* texture, bool read, bool write)
|
||||
@ -588,7 +588,7 @@ void Renderer::ResetSamplerStates()
|
||||
// Invalidate all sampler states, next draw will re-initialize them.
|
||||
for (u32 i = 0; i < m_sampler_states.size(); i++)
|
||||
{
|
||||
m_sampler_states[i].hex = RenderState::GetPointSamplerState().hex;
|
||||
m_sampler_states[i] = RenderState::GetPointSamplerState();
|
||||
StateTracker::GetInstance()->SetSampler(i, g_object_cache->GetPointSampler());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user