SampleCmp with gradient or bias flag is lost when a later sample in the function has none

未关闭 适合新手
#9,135 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp
领域
compilers

调研方向

从 lib/DXIL/DxilShaderFlags.cpp 开始,issue 在此指出了 flag 赋值的位置,然后找到计算同一 flag 的 validator 代码。检查该 flag 如何随列出的 sample opcode 更新,并与 DXIL.rst 中的预期行为进行比较。当 SampleCmpBias 或 SampleCmpGrad 出现在另一条 sample 指令之前时,两条 flag 计算路径都保留该 flag,并且验证接受相应的声明,即为完成。

由索引模型根据 Issue 内容生成。

描述

bug needs-triage

Description
The SampleCmpGradientOrBias shader flag is not set when SampleCmpBias or SampleCmpGrad is followed in the same function by Sample, SampleBias, SampleGrad, or SampleCmp. It seems the flag depends on the order of the instructions and not on whether SampleCmpBias or SampleCmpGrad itself is used.

Steps to Reproduce

Texture2D<float> depth : register(t0);
SamplerComparisonState less : register(s0);

float4 main(float2 uv : TEXCOORD0) : SV_Target {
	return depth.SampleCmpBias(less, uv, 0.5, 1.0) + depth.SampleCmp(less, uv, 0.25);
}

Compiled with dxc -T ps_6_8 -E main you will find no additional functionality is listed, but with the two calls swapped the listing will contain

; Note: shader requires additional functionality:
;       SampleCmp with gradient or bias

Expected

The flag should be set whenever SampleCmpBias or SampleCmpGrad is used. The documentation in DXIL.rst says the feature should be listed if "Use of the instructions SampleCmpGrad or SampleCmpBias". When the flag is not present the shader is accepted on devices that lack SampleCmpGradientAndBiasSupported.

Cause
It looks like the flag is assigned rather than accumulated in lib/DXIL/DxilShaderFlags.cpp:

case DXIL::OpCode::Sample:
case DXIL::OpCode::SampleBias:
case DXIL::OpCode::SampleCmp:
case DXIL::OpCode::SampleCmpBias:
  ...
  hasSampleCmpGradientOrBias = dxilOp == DXIL::OpCode::SampleCmpBias;

Since SampleGrad and SampleCmpGrad have a case of their own with the same assignment against SampleCmpGrad, whichever of these instructions comes last in the function decides the flag. I suspect this should've been |= rather than =.

The validator also computes the flags the same way so it has the same issue. If you have a a module that declares the flag for the shader above, it too fails validation with "Flags must match usage" error.

Environment

  • DXC 1.9.2609.5
主要语言
C++
星标
3.7k
派生
918
平均合并
3 天 12 小时
30 天内合并 PR
41

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/DirectXShaderCompiler 的其他 Issue

查看 microsoft/DirectXShaderCompiler 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。