Skip to content

Commit ce5f618

Browse files
iwwuigcbot
authored andcommitted
Preserve forced-SIMD hint bits in SIMDInfo
Two SIMDInfo bits are set once during input translation, not per codegen attempt. ClearSIMDInfo zeroed a whole slot, so a recompiled shader lost them and the output no longer showed why a SIMD width had been forced. Preserve them across a clear; only per-attempt bits are dropped. Also add helpers for recording a forced SIMD width.
1 parent d47c69a commit ce5f618

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

IGC/Compiler/CodeGenPublic.h

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ enum SIMDInfoBit {
438438
// fits in m_SIMDInfo ***
439439
};
440440

441+
// SIMDInfo bits describing a hint about the shader itself, not the outcome of one
442+
// codegen attempt. Set only in the input translation stage, which is not re-run
443+
// on a retry, so ClearSIMDInfo must preserve them.
444+
constexpr uint32_t g_cStickySIMDInfoBits = (1U << SIMD_FORCE_CONTENT) | (1U << SIMD_FORCE_HINT);
445+
441446
struct SKernelProgram {
442447
SProgramOutput simd1;
443448
SProgramOutput simd8;
@@ -1191,17 +1196,19 @@ class CodeGenContext {
11911196
void ModifySIMDInfo(SIMDMode simd, ShaderDispatchMode mode, Action action, SIMDInfoBit bit = SIMD_INFO_RESERVED) {
11921197
uint32_t bit_value = 1UL << bit;
11931198
bool clear = action == Action::Clear ? true : false;
1199+
// Clear drops the per-attempt bits only: see g_cStickySIMDInfoBits.
1200+
auto apply = [&](uint32_t current) { return clear ? (current & g_cStickySIMDInfoBits) : (current | bit_value); };
11941201
switch (mode) {
11951202
case ShaderDispatchMode::NOT_APPLICABLE:
11961203
switch (simd) {
11971204
case SIMDMode::SIMD8:
1198-
m_SIMDInfo.simd8 = clear ? 0 : m_SIMDInfo.simd8 | bit_value;
1205+
m_SIMDInfo.simd8 = apply(m_SIMDInfo.simd8);
11991206
break;
12001207
case SIMDMode::SIMD16:
1201-
m_SIMDInfo.simd16 = clear ? 0 : m_SIMDInfo.simd16 | bit_value;
1208+
m_SIMDInfo.simd16 = apply(m_SIMDInfo.simd16);
12021209
break;
12031210
case SIMDMode::SIMD32:
1204-
m_SIMDInfo.simd32 = clear ? 0 : m_SIMDInfo.simd32 | bit_value;
1211+
m_SIMDInfo.simd32 = apply(m_SIMDInfo.simd32);
12051212
break;
12061213
default:
12071214
IGC_ASSERT_MESSAGE(0, "Unknown SIMD Mode");
@@ -1210,10 +1217,10 @@ class CodeGenContext {
12101217
break;
12111218

12121219
case ShaderDispatchMode::DUAL_SIMD8:
1213-
m_SIMDInfo.dual_simd8 = clear ? 0 : m_SIMDInfo.dual_simd8 | bit_value;
1220+
m_SIMDInfo.dual_simd8 = apply(m_SIMDInfo.dual_simd8);
12141221
break;
12151222
case ShaderDispatchMode::QUAD_SIMD8_DYNAMIC:
1216-
m_SIMDInfo.quad_simd8_dynamic = clear ? 0 : m_SIMDInfo.quad_simd8_dynamic | bit_value;
1223+
m_SIMDInfo.quad_simd8_dynamic = apply(m_SIMDInfo.quad_simd8_dynamic);
12171224
break;
12181225

12191226
default:
@@ -1227,6 +1234,26 @@ class CodeGenContext {
12271234
ModifySIMDInfo(simd, mode, Action::Set, bit);
12281235
}
12291236

1237+
// Record a hint-forced wave size. Convert lanes to SIMDMode type
1238+
void SetForcedWaveSizeSIMDInfo(unsigned waveSizeInLanes) {
1239+
if (waveSizeInLanes == 8 || waveSizeInLanes == 16 || waveSizeInLanes == 32) {
1240+
SetSIMDInfo(SIMD_FORCE_HINT, lanesToSIMDMode(waveSizeInLanes), ShaderDispatchMode::NOT_APPLICABLE);
1241+
}
1242+
}
1243+
1244+
// Record a hint-forced wave size for PS.
1245+
void SetForcedPSSIMDModeSIMDInfo(unsigned psSIMDModeMask) {
1246+
if (psSIMDModeMask & FLAG_PS_SIMD_MODE_FORCE_SIMD8) {
1247+
SetSIMDInfo(SIMD_FORCE_HINT, SIMDMode::SIMD8, ShaderDispatchMode::NOT_APPLICABLE);
1248+
}
1249+
if (psSIMDModeMask & FLAG_PS_SIMD_MODE_FORCE_SIMD16) {
1250+
SetSIMDInfo(SIMD_FORCE_HINT, SIMDMode::SIMD16, ShaderDispatchMode::NOT_APPLICABLE);
1251+
}
1252+
if (psSIMDModeMask & FLAG_PS_SIMD_MODE_FORCE_SIMD32) {
1253+
SetSIMDInfo(SIMD_FORCE_HINT, SIMDMode::SIMD32, ShaderDispatchMode::NOT_APPLICABLE);
1254+
}
1255+
}
1256+
12301257
void ClearSIMDInfo(SIMDMode simd, ShaderDispatchMode mode) { ModifySIMDInfo(simd, mode, Action::Clear); }
12311258

12321259
SIMDInfoStruct GetSIMDInfo() const { return m_SIMDInfo; }

0 commit comments

Comments
 (0)