mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-14 02:14:35 +00:00
GPUDevice: Remap input attributes when transpiling to HLSL
This commit is contained in:
@@ -21,10 +21,13 @@ class Error;
|
||||
X(spvc_compiler_install_compiler_options) \
|
||||
X(spvc_compiler_require_extension) \
|
||||
X(spvc_compiler_compile) \
|
||||
X(spvc_compiler_get_decoration) \
|
||||
X(spvc_resources_get_resource_list_for_type)
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SPIRV_CROSS_HLSL_FUNCTIONS(X) X(spvc_compiler_hlsl_add_resource_binding)
|
||||
#define SPIRV_CROSS_HLSL_FUNCTIONS(X) \
|
||||
X(spvc_compiler_hlsl_add_resource_binding) \
|
||||
X(spvc_compiler_hlsl_add_vertex_attribute_remap)
|
||||
#else
|
||||
#define SPIRV_CROSS_HLSL_FUNCTIONS(X)
|
||||
#endif
|
||||
|
||||
@@ -1729,6 +1729,32 @@ bool GPUDevice::TranslateVulkanSpvToLanguage(const std::span<const u8> spirv, GP
|
||||
#ifdef _WIN32
|
||||
case GPUShaderLanguage::HLSL:
|
||||
{
|
||||
if (execmodel == SpvExecutionModelVertex)
|
||||
{
|
||||
const spvc_reflected_resource* inputs;
|
||||
size_t inputs_count;
|
||||
if ((sres = dyn_libs::spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_STAGE_INPUT,
|
||||
&inputs, &inputs_count)) != SPVC_SUCCESS)
|
||||
{
|
||||
Error::SetStringFmt(error, "spvc_resources_get_resource_list_for_type() for vertex attributes failed: {}",
|
||||
static_cast<int>(sres));
|
||||
return {};
|
||||
}
|
||||
|
||||
for (const spvc_reflected_resource& res : std::span<const spvc_reflected_resource>(inputs, inputs_count))
|
||||
{
|
||||
const unsigned location = dyn_libs::spvc_compiler_get_decoration(scompiler, res.id, SpvDecorationLocation);
|
||||
const TinyString name = TinyString::from_format("ATTR{}", location);
|
||||
const spvc_hlsl_vertex_attribute_remap va = {.location = location, .semantic = name.c_str()};
|
||||
if ((sres = dyn_libs::spvc_compiler_hlsl_add_vertex_attribute_remap(scompiler, &va, 1)) != SPVC_SUCCESS)
|
||||
{
|
||||
Error::SetStringFmt(error, "spvc_compiler_hlsl_add_vertex_attribute_remap() failed: {}",
|
||||
static_cast<int>(sres));
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((sres = dyn_libs::spvc_compiler_options_set_uint(soptions, SPVC_COMPILER_OPTION_HLSL_SHADER_MODEL,
|
||||
target_version)) != SPVC_SUCCESS)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user