You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Texture2DArray.Load异常:非零索引返回(0,0,0,1),仅能加载首纹理

问题:HLSL中Texture2DArray.Load仅能读取第一个纹理像素

在HLSL中使用Texture2DArray.Load方法时出现异常:仅能加载数组中第一个纹理的像素;当调用Texture2DArray.Load(int4)并为向量的第三个分量(纹理索引)传入非零值时,返回结果始终为float(0, 0, 0, 1)。

以下是相关着色器代码:

float4 sample_source(int sourceIndex, float2 texcoord)
{
    const int2 tileSize = int2(
        TileWidth,
        TileHeight);
    
    const int2 wholeSize = int2(
        TileWidth * TileColumns,
        TileHeight * TileRows);

    const int2 xy = int2(
        (int) texcoord.x,
        (int) texcoord.y);
    
    Texture2DArray tiles = _input[sourceIndex];
    
    int tileIndex = (xy.y / TileHeight) * TileColumns + (xy.x / TileWidth);
    float4 loadResult = tiles.Load(int4(
        xy.x % TileWidth,
        xy.y % TileHeight,
        tileIndex,
        0));
    
    float4 sampleResult = tiles.Sample(_sampler, float3(
        (float)(xy.x % TileWidth) / TileWidth,
        (float)(xy.y % TileHeight) / TileHeight,
        tileIndex));
    
    return (loadResult + sampleResult) / 2;
}

实际输出结果显示:当tileIndex不为0时,Load方法返回全黑结果(对应float(0,0,0,1)),但Sample方法的输出完全正常(画面中Load结果区域为黑色,Sample结果区域显示正确纹理内容)。

内容的提问来源于stack exchange,提问作者SlimeNull

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 07:12:47