diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2020-04-03 12:21:41 +0300 |
---|---|---|
committer | Hans-Kristian Arntzen <post@arntzen-software.no> | 2020-04-03 12:50:50 +0300 |
commit | 28bf9057df1ff525695f3f80ebe9a3d1bb8f19de (patch) | |
tree | ff670c157bb9db28ae6a4bcb1b155890166c4d50 /spirv_hlsl.cpp | |
parent | e58e8d5dbe03ea2cc755dbaf43ffefa1b8d77bef (diff) |
HLSL: Add support for treating NonWritable UAV texture as SRV instead.
Diffstat (limited to 'spirv_hlsl.cpp')
-rw-r--r-- | spirv_hlsl.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 8639f201..29846c76 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -210,6 +210,8 @@ string CompilerHLSL::image_type_hlsl_modern(const SPIRType &type, uint32_t id) bool typed_load = false; uint32_t components = 4; + bool force_image_srv = hlsl_options.nonwritable_uav_texture_as_srv && has_decoration(id, DecorationNonWritable); + switch (type.image.dim) { case Dim1D: @@ -239,7 +241,14 @@ string CompilerHLSL::image_type_hlsl_modern(const SPIRType &type, uint32_t id) if (interlocked_resources.count(id)) return join("RasterizerOrderedBuffer<", image_format_to_type(type.image.format, imagetype.basetype), ">"); - return join("RWBuffer<", image_format_to_type(type.image.format, imagetype.basetype), ">"); + + typed_load = !force_image_srv && type.image.sampled == 2; + + const char *rw = force_image_srv ? "" : "RW"; + return join(rw, "Buffer<", + typed_load ? image_format_to_type(type.image.format, imagetype.basetype) : + join(type_to_glsl(imagetype), components), + ">"); } else SPIRV_CROSS_THROW("Sampler buffers must be either sampled or unsampled. Cannot deduce in runtime."); @@ -252,9 +261,14 @@ string CompilerHLSL::image_type_hlsl_modern(const SPIRType &type, uint32_t id) } const char *arrayed = type.image.arrayed ? "Array" : ""; const char *ms = type.image.ms ? "MS" : ""; - const char *rw = typed_load ? "RW" : ""; + const char *rw = typed_load && !force_image_srv ? "RW" : ""; + + if (force_image_srv) + typed_load = false; + if (typed_load && interlocked_resources.count(id)) rw = "RasterizerOrdered"; + return join(rw, "Texture", dim, ms, arrayed, "<", typed_load ? image_format_to_type(type.image.format, imagetype.basetype) : join(type_to_glsl(imagetype), components), @@ -2971,8 +2985,16 @@ string CompilerHLSL::to_resource_binding(const SPIRVariable &var) case SPIRType::Image: if (type.image.sampled == 2 && type.image.dim != DimSubpassData) { - space = 'u'; // UAV - resource_flags = HLSL_BINDING_AUTO_UAV_BIT; + if (has_decoration(var.self, DecorationNonWritable) && hlsl_options.nonwritable_uav_texture_as_srv) + { + space = 't'; // SRV + resource_flags = HLSL_BINDING_AUTO_SRV_BIT; + } + else + { + space = 'u'; // UAV + resource_flags = HLSL_BINDING_AUTO_UAV_BIT; + } } else { @@ -4813,7 +4835,12 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction) imgexpr = join(to_expression(ops[2]), "[", to_expression(ops[3]), "]"); // The underlying image type in HLSL depends on the image format, unlike GLSL, where all images are "vec4", // except that the underlying type changes how the data is interpreted. - if (var && !subpass_data) + + bool force_srv = + hlsl_options.nonwritable_uav_texture_as_srv && var && has_decoration(var->self, DecorationNonWritable); + pure = force_srv; + + if (var && !subpass_data && !force_srv) imgexpr = remap_swizzle(get<SPIRType>(result_type), image_format_to_components(get<SPIRType>(var->basetype).image.format), imgexpr); } |