Skip to content

Commit

Permalink
Fix UIntSet calcSubtract to handle mismatched buffer sizes (#6205)
Browse files Browse the repository at this point in the history
* fix calcSubtract on UIntSet

* add test

---------

Co-authored-by: Yong He <yonghe@outlook.com>
  • Loading branch information
fairywreath and csyonghe authored Jan 29, 2025
1 parent f4e3692 commit 1f99c20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
20 changes: 16 additions & 4 deletions source/core/slang-uint-set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,23 @@ void UIntSet::subtractWith(const UIntSet& set)

/* static */ void UIntSet::calcSubtract(UIntSet& outRs, const UIntSet& set1, const UIntSet& set2)
{
outRs.resizeBackingBufferDirectly(set1.m_buffer.getCount());
const auto set1Count = set1.m_buffer.getCount();
const auto set2Count = set2.m_buffer.getCount();

const Index minCount = Math::Min(set1.m_buffer.getCount(), set2.m_buffer.getCount());
for (Index i = 0; i < minCount; i++)
outRs.m_buffer[i] = set1.m_buffer[i] & (~set2.m_buffer[i]);
outRs.resizeBackingBufferDirectly(set1Count);

for (Index i = 0; i < set1Count; i++)
{
if (i < set2Count)
{
outRs.m_buffer[i] = set1.m_buffer[i] & (~set2.m_buffer[i]);
}
else
{
// If `set2` is smaller, copy the remaining values from `set1`
outRs.m_buffer[i] = set1.m_buffer[i];
}
}
}

/* static */ bool UIntSet::hasIntersection(const UIntSet& set1, const UIntSet& set2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK_SPIRV): -stage fragment -entry fragmentMain -target spirv -profile spirv_1_3

// We currently do not have GLSL profiles, pass in SPIRV profile instead. We need
// to pass in a profile parameter to emit the warning.
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK_GLSL): -stage fragment -entry fragmentMain -target glsl -profile spirv_1_3

// CHECK_SPIRV: warning 41012{{.*}}'spvImageGatherExtended'
// CHECK_GLSL: warning 41012{{.*}}'GLSL_150 + GL_ARB_texture_gather'
float4 fragmentMain(float2 pos : SV_Position, Sampler2D<float> foo) : SV_Target
{
return foo.Gather(uint2(pos));
}

0 comments on commit 1f99c20

Please sign in to comment.