首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从vulkan附件中读取当前示例

从vulkan附件中读取当前示例
EN

Stack Overflow用户
提问于 2020-09-09 06:53:44
回答 1查看 173关注 0票数 0

我有一个全屏幕效果通行证,是多采样。如果我阅读一个输入注意(这也是多样本)。我似乎只读过同样的样本。

管道示例设置:

代码语言:javascript
复制
VkPipelineMultisampleStateCreateInfo multisampling_info = {};
multisampling_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
multisampling_info.rasterizationSamples = static_cast<VkSampleCountFlagBits>(samples);
multisampling_info.sampleShadingEnable = samples > 1 ? VK_TRUE : VK_FALSE;
multisampling_info.minSampleShading = 1.0;
multisampling_info.pSampleMask = nullptr;
multisampling_info.alphaToCoverageEnable = VK_FALSE;
multisampling_info.alphaToOneEnable = VK_FALSE;

在着色器内部,我使用的图像类型为:

代码语言:javascript
复制
%28 = OpTypeImage %float SubpassData 0 0 1 2 Unknown

并以(0,0)的坐标读取。

代码语言:javascript
复制
 %34 = OpImageRead %v4float %30 %36

着色器似乎被要求为每一个样本,因为我得到正确的SampleId。

斯皮尔-V规范说:

当图像操作数为SubpassData时,坐标相对于当前片段的位置。也就是说,将当前片段的窗口相对(x,y)坐标的整数值(四舍五入)添加到(u,v)中。

如果我正确理解了这一点,在坐标为(0,0)的情况下,我应该总是得到相应的样本吗?

我是误解了什么,还是这不可能?

这是我使用的完整的螺旋着色器:

代码语言:javascript
复制
               OpCapability Shader
               OpCapability InputAttachment
               OpCapability SampleRateShading
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %44 "main" %41 %gl_SampleID
               OpExecutionMode %44 OriginUpperLeft
               OpDecorate %_struct_3 Block
               OpMemberDecorate %_struct_3 0 Offset 0
               OpDecorate %gl_SampleID BuiltIn SampleId
               OpDecorate %32 DescriptorSet 0
               OpDecorate %32 Binding 0
               OpDecorate %32 InputAttachmentIndex 0
               OpDecorate %41 Location 0
        %int = OpTypeInt 32 1
  %_struct_3 = OpTypeStruct %int
%_ptr_PushConstant__struct_3 = OpTypePointer PushConstant %_struct_3
          %5 = OpVariable %_ptr_PushConstant__struct_3 PushConstant
%_ptr_PushConstant_int = OpTypePointer PushConstant %int
       %bool = OpTypeBool
%_ptr_Input_int = OpTypePointer Input %int
%gl_SampleID = OpVariable %_ptr_Input_int Input
      %float = OpTypeFloat 32
         %28 = OpTypeImage %float SubpassData 0 0 1 2 Unknown
%_ptr_UniformConstant_28 = OpTypePointer UniformConstant %28
         %32 = OpVariable %_ptr_UniformConstant_28 UniformConstant
    %v4float = OpTypeVector %float 4
      %v2int = OpTypeVector %int 2
%_ptr_Output_v4float = OpTypePointer Output %v4float
         %41 = OpVariable %_ptr_Output_v4float Output
       %void = OpTypeVoid
         %42 = OpTypeFunction %void
      %int_0 = OpConstant %int 0
      %int_3 = OpConstant %int 3
      %int_1 = OpConstant %int 1
      %int_5 = OpConstant %int 5
     %int_16 = OpConstant %int 16
         %36 = OpConstantComposite %v2int %int_16 %int_0
         %39 = OpConstantNull %v4float
         %44 = OpFunction %void None %42
          %1 = OpLabel
          %7 = OpAccessChain %_ptr_PushConstant_int %5 %int_0
          %9 = OpLoad %int %7
         %10 = OpShiftRightArithmetic %int %9 %int_3
         %13 = OpSLessThan %bool %10 %int_0
         %14 = OpSelect %int %13 %int_1 %int_0
         %16 = OpBitwiseAnd %int %9 %int_5
         %18 = OpINotEqual %bool %16 %int_0
         %19 = OpSelect %int %18 %int_1 %int_0
         %20 = OpBitwiseOr %int %19 %14
         %21 = OpIAdd %int %10 %20
         %22 = OpLoad %int %gl_SampleID
         %25 = OpSLessThan %bool %22 %21
               OpSelectionMerge %26 None
               OpBranchConditional %25 %27 %26
         %27 = OpLabel
         %30 = OpLoad %28 %32
         %34 = OpImageRead %v4float %30 %36
               OpBranch %26
         %26 = OpLabel
         %38 = OpPhi %v4float %34 %27 %39 %1
               OpStore %41 %38
               OpReturn
               OpFunctionEnd
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-09 13:19:16

最后,它是超级简单。OpImageRead可能有可选的图像操作数,其中一个可以是Sample,这就获得了它将要读取的示例。将内置变量SampleId (当前阴影样本)输入到它中,将其固定。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63806256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档