Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect cached pipeline as GraphicsState not copy safe #84

Open
publicrepo opened this issue Aug 17, 2022 · 0 comments
Open

Incorrect cached pipeline as GraphicsState not copy safe #84

publicrepo opened this issue Aug 17, 2022 · 0 comments

Comments

@publicrepo
Copy link

If you have multiple pipelines where the only difference is color blend state, the pipeline cache may choose the wrong cached pipeline.
This is caused by GraphicsState hash being computed from a copy of the GraphicsState and GraphicsState not being copy safe. Specifically, the pAttachments member points to the wrong address on copy. Ideally it would always point to it's accompanied m_colorBlendAttachments[0].

One solution would be to add a copy ctor. However, since only a single copy is made, and that copy is only used by the hash function, we can simply fix the hash function.

In GraphicsState::GetHash()
Replace m_colorBlendState.pAttachments[i] with m_colorBlendAttachments[i]
eg.

        // NOTE: Copy of m_colorBlendState.pAttachments is incorrect. Use m_colorBlendAttachments instead, same as GetColorBlendAttachmentState()
        for (auto i = 0U; i < m_colorBlendState.attachmentCount; ++i)
        {
            cb->colorWriteMask = static_cast<uint32_t>(m_colorBlendAttachments[i].colorWriteMask);
            cb->blendEnable = m_colorBlendAttachments[i].blendEnable;
            cb->srcColorBlendFactor = static_cast<uint32_t>(m_colorBlendAttachments[i].srcColorBlendFactor);
            cb->dstColorBlendFactor = static_cast<uint32_t>(m_colorBlendAttachments[i].dstColorBlendFactor);
            cb->colorBlendOp = static_cast<uint32_t>(m_colorBlendAttachments[i].colorBlendOp);
            cb->srcAlphaBlendFactor = static_cast<uint32_t>(m_colorBlendAttachments[i].srcAlphaBlendFactor);
            cb->dstAlphaBlendFactor = static_cast<uint32_t>(m_colorBlendAttachments[i].dstAlphaBlendFactor);
            cb->alphaBlendOp = static_cast<uint32_t>(m_colorBlendAttachments[i].alphaBlendOp);
            ++cb;
        }
unvestigate pushed a commit to unvestigate/V-EZ that referenced this issue Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant