Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 8 additions & 37 deletions Graphics/GraphicsEngineWebGPU/src/ShaderWebGPUImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,12 @@
#include "GLSLUtils.hpp"
#include "ShaderToolsCommon.hpp"
#include "WGSLUtils.hpp"
#include "HLSLUtils.hpp"
#include "HLSLParsingTools.hpp"
#include "SPIRVUtils.hpp"

#if !DILIGENT_NO_GLSLANG
# include "GLSLangUtils.hpp"
# include "SPIRVShaderResources.hpp"
#endif

#if !DILIGENT_NO_HLSL
# include "SPIRVTools.hpp"
#endif

namespace Diligent
{

Expand All @@ -69,38 +62,16 @@ std::vector<uint32_t> CompileShaderToSPIRV(const ShaderCreateInfo& S
{
SPIRV = GLSLangUtils::HLSLtoSPIRV(ShaderCI, GLSLangUtils::SpirvVersion::Vk100, WebGPUDefine, WebGPUShaderCI.ppCompilerOutput);

SPIRVShaderResources::CreateInfo ResCI;
ResCI.ShaderType = ShaderCI.Desc.ShaderType;
ResCI.Name = ShaderCI.Desc.Name;
ResCI.CombinedSamplerSuffix = ShaderCI.Desc.UseCombinedTextureSamplers ? ShaderCI.Desc.CombinedSamplerSuffix : nullptr;
ResCI.LoadShaderStageInputs = ShaderCI.Desc.ShaderType == SHADER_TYPE_VERTEX;
ResCI.LoadUniformBufferReflection = false;

SPIRVShaderResources Resources{
GetRawAllocator(),
SPIRV,
ResCI,
};

if (ShaderCI.Desc.ShaderType == SHADER_TYPE_VERTEX)
if (!SPIRV.empty() && ShaderCI.Desc.ShaderType == SHADER_TYPE_VERTEX)
{
Resources.MapHLSLVertexShaderInputs(SPIRV);
}
SPIRVShaderResources::CreateInfo ResCI;
ResCI.ShaderType = ShaderCI.Desc.ShaderType;
ResCI.Name = ShaderCI.Desc.Name;
ResCI.CombinedSamplerSuffix = ShaderCI.Desc.UseCombinedTextureSamplers ? ShaderCI.Desc.CombinedSamplerSuffix : nullptr;
ResCI.LoadShaderStageInputs = true;

if (Resources.GetNumImgs() > 0)
{
// Image formats are lost during HLSL->SPIRV conversion, so we need to patch them manually
const std::string HLSLSource = BuildHLSLSourceString(ShaderCI);
if (!HLSLSource.empty())
{
// Extract image formats from special comments in HLSL code:
// Texture2D<float4 /*format=rgba32f*/> g_RWTexture;
const auto ImageFormats = Parsing::ExtractGLSLImageFormatsFromHLSL(HLSLSource);
if (!ImageFormats.empty())
{
SPIRV = PatchImageFormats(SPIRV, ImageFormats);
}
}
SPIRVShaderResources Resources{GetRawAllocator(), SPIRV, ResCI};
Resources.MapHLSLVertexShaderInputs(SPIRV);
}
}
else
Expand Down
3 changes: 0 additions & 3 deletions Graphics/ShaderTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ project(Diligent-ShaderTools CXX)
set(INCLUDE
include/ShaderToolsCommon.hpp
include/GLSLParsingTools.hpp
include/HLSLParsingTools.hpp
include/HLSLTokenizer.hpp
include/HLSLDefinitions.fxh
include/HLSLKeywords.h
)

set(SOURCE
src/ShaderToolsCommon.cpp
src/GLSLParsingTools.cpp
src/HLSLParsingTools.cpp
src/HLSLTokenizer.cpp
)

Expand Down
7 changes: 0 additions & 7 deletions Graphics/ShaderTools/include/GLSLParsingTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#pragma once

#include "ParsingTools.hpp"
#include "GraphicsTypes.h"

namespace Diligent
{
Expand Down Expand Up @@ -105,12 +104,6 @@ std::string ExtractGLSLImageFormatFromComment(const InteratorType& Start, const
return {Pos, ImgFmtEndPos};
}

/// Parses GLSL image format string, e.g. "rgba8" or "rg32f" and returns the corresponding texture format.
///
/// \param[in] Format - GLSL image format string
/// \return Texture format, or TEXTURE_FORMAT_UNKNOWN if the format is not recognized.
TEXTURE_FORMAT ParseGLSLImageFormat(const std::string& Format);

} // namespace Parsing

} // namespace Diligent
3 changes: 3 additions & 0 deletions Graphics/ShaderTools/include/HLSLDefinitions.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ float2x2 MatrixFromRows(float2 row0, float2 row1)

#if defined(VULKAN) && defined(DXCOMPILER)
# define VK_IMAGE_FORMAT(format) [[vk::image_format(format)]]
#elif defined(GLSLANG) && (defined(VULKAN) || defined(WEBGPU))
# define format_r11g11b10f format_r11fg11fb10f
# define VK_IMAGE_FORMAT(format) [[spv::format_##format]]
#else
# define VK_IMAGE_FORMAT(format)
#endif
Expand Down
59 changes: 0 additions & 59 deletions Graphics/ShaderTools/include/HLSLParsingTools.hpp

This file was deleted.

15 changes: 0 additions & 15 deletions Graphics/ShaderTools/include/SPIRVUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,9 @@

#pragma once

#include <vector>
#include <unordered_map>

#include "GraphicsTypes.h"
#include "HashUtils.hpp"

namespace Diligent
{

/// Patches image format declarations in the SPIRV code using the provided mapping.
///
/// \param [in] SPIRV - SPIRV code.
/// \param [in] ImageFormats - Mapping from image format names to texture formats.
///
/// \return Patched SPIRV code.
std::vector<uint32_t> PatchImageFormats(const std::vector<uint32_t>& SPIRV,
const std::unordered_map<HashMapStringKey, TEXTURE_FORMAT>& ImageFormats);

/// Warms up SPIRV-Cross GLSL compiler to initialize internal static data before concurrent use.
void WarmUpSPIRVCrossGLSLCompiler();

Expand Down
Loading
Loading