Skip to content

Conversation

@luciechoi
Copy link
Collaborator

@luciechoi luciechoi commented Jan 7, 2026

Part of #7979

  • Add SampledTexture2D resource type in the vk namespace.
  • Add .Sample(float2 location) method.
  • Add default type parameter float4.
  • Allow optional arguments int2 offset, float clamp, uint status.
  • Add .CalculateLevelOfDetail(float2 location) method.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@luciechoi luciechoi marked this pull request as draft January 7, 2026 09:03
Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

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

This seems like a reasonable direction. There are some issues that we need to figure out how to handle.

// CHECK: [[in_var_TEXCOORD:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Input_v2float Input
// CHECK: [[out_var_SV_Target:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Output_v4float Output

vk::SampledTexture2D<float4> tex : register(t0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you test this with an int so it is different then the next test? That we will know if you accidentally always output a float type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing out, added a test for vk::SampledTexture2D<uint> type.

Comment on lines 4021 to 4024
QualType float4Type =
LookupVectorType(HLSLScalarType::HLSLScalarType_float, 4);
recordDecl = DeclareVkSampledTexture2DType(*m_context, m_vkNSDecl,
float2Type, float4Type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the result of the sample have to be a 4 element vector? What happens if the template type is a scalar?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, if a template type is scalar, the results are extracted. Added a test.

Comment on lines 625 to 628
if (isSampledTexture(imageType)) {
sampledImage = image;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we assert that the sampler is false? Not necessary, but this function has a complicated interface, and it could be easy to use it incorrectly.

Is there documentation for this function to update?

Copy link
Collaborator Author

@luciechoi luciechoi Jan 8, 2026

Choose a reason for hiding this comment

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

Should we assert that the sampler is false?

Added.

Is there documentation for this function to update?

Updated the function documentation.

@luciechoi luciechoi force-pushed the sampledtexture2d branch 3 times, most recently from 67fef39 to 8030b4e Compare January 8, 2026 04:56
@luciechoi luciechoi marked this pull request as ready for review January 8, 2026 05:03
@luciechoi
Copy link
Collaborator Author

Thanks for the early review! I've updated the method to take in optional arguments.

@luciechoi luciechoi requested a review from s-perron January 8, 2026 05:06
@luciechoi luciechoi changed the title [SPIR-V] Add vk::SampledTexture2D resource type and .Sample() method. [SPIR-V] Add vk::SampledTexture2D resource type and .Sample(), CalculateLevelOfDetail() method. Jan 9, 2026
@luciechoi luciechoi changed the title [SPIR-V] Add vk::SampledTexture2D resource type and .Sample(), CalculateLevelOfDetail() method. [SPIR-V] Add vk::SampledTexture2D resource type and .Sample(), .CalculateLevelOfDetail() method. Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants