Skip to content

Conversation

@hzqst
Copy link
Contributor

@hzqst hzqst commented Jan 2, 2026

No description provided.

@hzqst hzqst marked this pull request as ready for review January 2, 2026 04:27
@hzqst hzqst requested a review from TheMostDiligent as a code owner January 2, 2026 04:27
@hzqst hzqst changed the title Fix issues from https://github.com/DiligentGraphics/DiligentCore/pull/747 Fix issues from #747 Jan 2, 2026
Uint32 ArraySize = Attribs.ArraySize;
if (Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS)
{
VERIFY(Flags == PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS, "INLINE_CONSTANTS flag cannot be combined with other flags.");

Check warning

Code scanning / PREfast

Use 'bitwise and' to check if a flag is set. Warning

Use 'bitwise and' to check if a flag is set.
ResCI.ShaderType = pShader->GetDesc().ShaderType;
ResCI.Name = pShader->GetDesc().Name;
ResCI.CombinedSamplerSuffix = pShader->GetDesc().UseCombinedTextureSamplers ? pShader->GetDesc().CombinedSamplerSuffix : nullptr;
ResCI.LoadShaderStageInputs = pShader->GetDesc().ShaderType == SHADER_TYPE_VERTEX;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading shader stage inputs is not needed.
It is used to patch Vertex Shader inputs, which is done when the shader is created.
They are already correct in the original SPIRV, and are the same in patched.

Copy link
Contributor Author

@hzqst hzqst Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to patch Vertex Shader inputs, which is done when the shader is created.

it can be a problem when ShaderVkImpl is asynchronously loaded, SPIRVShaderResources is not available at that time in ShaderVkImpl::Initialize. The ArchiverTest said that no SPIRVShaderResources is created when shader is created.

btw isn't shader patching done in RemapOrVerifyShaderResources?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an error somewhere. Asynchronous shaders must be created first before the pipeline is created. Querying anything from the shader while it is compiled is an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, seems that after commenting out deferred SPIRVShaderResource creation everything works fine, also with ShaderResource initialized with pShader->GetShaderResource()

image image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked this code yet, but based on comment, this block is certainly not needed. InitPipelineLayout is only called after all asynchronous shader work is complete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a problem with Async PSO too

image image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflection is only stripped from the final SPIRV after all patching, push constants conversion including

nvm I skipped the validation in 34af2e6. it works fine for stripped_reflection one now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored PipelineStateVkImpl::ShaderStageInfo, but now when I look at it I don't think ShaderResources are needed in ShaderStageInfo at all.
The problem is that right now, PatchShaderConvertUniformBufferToPushConstant is called separately from RemapOrVerifyShaderResources, but it should be part of RemapOrVerifyShaderResources.
RemapOrVerifyShaderResources should both patch bindings and push constants, if necessary.
If needed, it will created new resources and add them to pDvpShaderResources. If pDvpShaderResources is null, new resources are not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored PipelineStateVkImpl::ShaderStageInfo, but now when I look at it I don't think ShaderResources are needed in ShaderStageInfo at all. The problem is that right now, PatchShaderConvertUniformBufferToPushConstant is called separately from RemapOrVerifyShaderResources, but it should be part of RemapOrVerifyShaderResources. RemapOrVerifyShaderResources should both patch bindings and push constants, if necessary. If needed, it will created new resources and add them to pDvpShaderResources. If pDvpShaderResources is null, new resources are not needed.

but pDvpShaderResources is a DILIGENT_DEVELOPMENT-only variable which is not available in production build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, which is why in production build there is no even need to create new shader resources after patching SPIRV.

ResCI.Name = pShader->GetDesc().Name;
ResCI.CombinedSamplerSuffix = pShader->GetDesc().UseCombinedTextureSamplers ? pShader->GetDesc().CombinedSamplerSuffix : nullptr;
ResCI.LoadShaderStageInputs = pShader->GetDesc().ShaderType == SHADER_TYPE_VERTEX;
ResCI.LoadUniformBufferReflection = true; //LoadConstantBufferReflection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is uniform buffer reflection needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just leave it false or?

Copy link
Contributor

@TheMostDiligent TheMostDiligent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you submit changes to PipelineLayoutVk.cpp/hpp as a separate PR - they are clean and isolated.

@hzqst
Copy link
Contributor Author

hzqst commented Jan 2, 2026

Seems that we have PipelineResourceSignatureVkImpl::HasInlineConstants failed and causing m_PushConstantInfo to be left empty. what do we need next?

    bool HasInlineConstants() const
    {
        // TODO
        return false;
    }

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch 3 times, most recently from e405c1f to 7be6864 Compare January 3, 2026 00:50
@TheMostDiligent
Copy link
Contributor

Seems that we have PipelineResourceSignatureVkImpl::HasInlineConstants failed and causing m_PushConstantInfo to be left empty. what do we need next?

This is a simple function that helps to avoid looping through all resources for all signatures even if there are no inline constants

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch 4 times, most recently from a022722 to 09a471d Compare January 4, 2026 02:10
@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch 2 times, most recently from 7a5328a to 1c5f655 Compare January 4, 2026 16:46
hzqst added a commit to hzqst/DiligentCore that referenced this pull request Jan 5, 2026
@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch 3 times, most recently from 43e3d98 to bd9769e Compare January 6, 2026 05:23
@TheMostDiligent
Copy link
Contributor

Take a look at how much simpler I made the inline constant initialization in the resource cache.
Few and simpler changes are always preferable as they are easier to understand, and less code to maintain.

@hzqst
Copy link
Contributor Author

hzqst commented Jan 6, 2026

Can you please do rebases instead of merges? Linearizing history after merge is very inconvenient

will do next time

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch from a36c137 to 293f205 Compare January 6, 2026 17:27
float4 main(in PSInput PSIn) : SV_Target
{
return PSIn.Color;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why PS is not using the push constants block? It should to verify that the stages are properly merged.

Copy link
Contributor Author

@hzqst hzqst Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why PS is not using the push constants block? It should to verify that the stages are properly merged.

That's what I mentioned before:

If we have [[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants; declared both in VS and PS, they will be allocated as two resources instead of one, in PipelineStateVkImpl::GetDefaultResourceSignatureDesc.

Calling pPSO->GetStaticVariableByName(SHADER_TYPE_PIXEL, "PushConstants")->SetInlineConstants does nothing under the hood as data never get committed in m_CommandBuffer.PushConstants(Layout.GetVkPipelineLayout(), PushConstantInfo.vkRange, pPushConstantData);. The PushConstantInfo.vkRange goes with nothing more than VK_SHADER_STAGE_VERTEX_BIT.

image

I suggust ensure that [[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants; has exact the same size in both VS and PS first, if they are both found in VS and PS.

We merge PCInfo.vkRange.stageFlags with ShaderTypesToVkShaderStageFlags(SHADER_TYPE_PIXEL) in the later pass in PipelineLayoutVk::GetPushConstantInfo then.

image

PS inline constants need to be merged into VS inline constants in PipelineStateVkImpl::GetDefaultResourceSignatureDesc as an identical resource also.

@TheMostDiligent
Copy link
Contributor

@hzqst Don't rebase on inline_constants yet - the tests will break due to incorrect memory size for SRB allocator.

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch 3 times, most recently from efe8f86 to fbe3f5d Compare January 7, 2026 03:59
@TheMostDiligent
Copy link
Contributor

I am going to rebase and overwrite your branch - give me a few minutes.
You will need to submit the last change again - it is not yet working anyway.

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch from 43ec87a to 3159a82 Compare January 7, 2026 05:56
@TheMostDiligent
Copy link
Contributor

OK, done

@hzqst
Copy link
Contributor Author

hzqst commented Jan 7, 2026

@TheMostDiligent we are now error out with 9aad908

image

If we have [[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants; declared both in VS and PS, they will be allocated as two resources instead of one, in PipelineStateVkImpl::GetDefaultResourceSignatureDesc.

Calling pPSO->GetStaticVariableByName(SHADER_TYPE_PIXEL, "PushConstants")->SetInlineConstants does nothing under the hood as data never get committed in m_CommandBuffer.PushConstants(Layout.GetVkPipelineLayout(), PushConstantInfo.vkRange, pPushConstantData);. The PushConstantInfo.vkRange goes with nothing more than VK_SHADER_STAGE_VERTEX_BIT.

image

I suggust ensure that [[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants; has exact the same size in both VS and PS first, if they are both found in VS and PS.

We should probably merge PCInfo.vkRange.stageFlags with ShaderTypesToVkShaderStageFlags(SHADER_TYPE_PIXEL) later in PipelineLayoutVk::GetPushConstantInfo.

image

PS inline constants as a PRSDesc need to be merged into VS inline constants in PipelineStateVkImpl::GetDefaultResourceSignatureDesc also.

@TheMostDiligent
Copy link
Contributor

I suggust ensure that [[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants; has exact the same size in both VS and PS first, if they are both found in VS and PS.

Yes, this is what we need to do.
Instead of break, the loop should check if PCInfo is not empty already, and if so:

  • Check if the name and size matches, then add the shader stage flag
  • Otherwise throw an error

Can you work on this in a separate PR?
I want to finish merging this one.

@TheMostDiligent
Copy link
Contributor

I will also remove the test from this branch.

@hzqst
Copy link
Contributor Author

hzqst commented Jan 7, 2026

I suggust ensure that [[vk::push_constant]] ConstantBuffer<PushConstants_t> PushConstants; has exact the same size in both VS and PS first, if they are both found in VS and PS.

Yes, this is what we need to do. Instead of break, the loop should check if PCInfo is not empty already, and if so:

  • Check if the name and size matches, then add the shader stage flag
  • Otherwise throw an error

Can you work on this in a separate PR? I want to finish merging this one.

base on DiligentGraphics:inline_constants or hzqst:inline_constants_747_fix?

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch from 9aad908 to 9e12690 Compare January 7, 2026 14:48
@TheMostDiligent
Copy link
Contributor

On hzqst:inline_constants_747_fix, DiligentGraphics:inline_constants don't have full implementation yet.

@TheMostDiligent
Copy link
Contributor

Can you please create another PR?
I am working on merging this one.

@hzqst
Copy link
Contributor Author

hzqst commented Jan 7, 2026

Done in b0e30b5

Next problem: what we gonna do with PushConstantInfo::SignatureIndex and PushConstantInfo::ResourceIndex? we have two ResourceIndex now, if merge happens.

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch 3 times, most recently from 9e00a88 to 7b500ee Compare January 7, 2026 16:06
Comment on lines 580 to 603

const Uint32 SRBIndex = pResBindingVkImpl->GetBindingIndex();
const PipelineResourceSignatureVkImpl* pSignature = pResBindingVkImpl->GetSignature();

// PRS has no resources and thus PIPELINE_TYPE_INVALID ?
PIPELINE_TYPE SRBPipelineType = pResBindingVkImpl->GetPipelineType();
if (SRBPipelineType == PIPELINE_TYPE_INVALID)
return;

ResourceBindInfo& BindInfo = GetBindInfo(SRBPipelineType);
ResourceBindInfo::DescriptorSetInfo& SetInfo = BindInfo.SetInfo[SRBIndex];

// Always bind the SRB, even if it has no descriptor sets (e.g., only push constants)
// The resource cache is needed to store push constant data
BindInfo.Set(SRBIndex, pResBindingVkImpl);

// If there are no descriptor sets, we're done (SRB only contains push constants)
// Clear the stale flag since there are no descriptor sets to commit
if (ResourceCache.GetNumDescriptorSets() == 0)
{
// Ignore SRBs that contain no resources
// Clear the stale bit for this SRB since it has no descriptor sets to commit
// The SRB is still bound and ResourceCaches[SRBIndex] is set, so push constants can be accessed
const auto SRBBit = static_cast<ResourceBindInfo::SRBMaskType>(1u << SRBIndex);
BindInfo.StaleSRBMask &= ~SRBBit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all these changed needed?
If I revert all of them, everything works fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on comments, it looks like this is remained from your earlier versions, since now all inline constants get descriptor sets, this does not make sense:
// Always bind the SRB, even if it has no descriptor sets (e.g., only push constants)
Also,

    PIPELINE_TYPE SRBPipelineType = pResBindingVkImpl->GetPipelineType();
    if (SRBPipelineType == PIPELINE_TYPE_INVALID)
        return;

Should never happen.

@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch from 7b500ee to ba44fc8 Compare January 7, 2026 16:26
@TheMostDiligent TheMostDiligent force-pushed the inline_constants_747_fix branch from ba44fc8 to 7cac8db Compare January 7, 2026 16:28
@TheMostDiligent TheMostDiligent merged commit 7cac8db into DiligentGraphics:inline_constants Jan 7, 2026
37 checks passed
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

Successfully merging this pull request may close these issues.

2 participants