Separate texture dimensions to multiple descriptor indices.

This commit is contained in:
Skyth 2024-10-27 20:07:40 +03:00
parent 25b4f604af
commit 5f6a8e6c2a
3 changed files with 48 additions and 28 deletions

View file

@ -26,6 +26,10 @@ target_link_libraries(ShaderRecomp PRIVATE
target_precompile_headers(ShaderRecomp PRIVATE pch.h) target_precompile_headers(ShaderRecomp PRIVATE pch.h)
add_compile_definitions(ShaderRecomp _CRT_SECURE_NO_WARNINGS) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(ShaderRecomp PRIVATE -Wno-switch -Wno-unused-variable)
endif()
target_compile_definitions(ShaderRecomp PRIVATE _CRT_SECURE_NO_WARNINGS)
file(COPY ${PACKAGE_PREFIX_DIR}/bin/dxil.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${PACKAGE_PREFIX_DIR}/bin/dxil.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

View file

@ -14,22 +14,22 @@ struct PushConstants
[[vk::push_constant]] ConstantBuffer<PushConstants> g_PushConstants; [[vk::push_constant]] ConstantBuffer<PushConstants> g_PushConstants;
#define g_AlphaTestMode vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 128) #define g_AlphaTestMode vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 256)
#define g_AlphaThreshold vk::RawBufferLoad<float>(g_PushConstants.SharedConstants + 132) #define g_AlphaThreshold vk::RawBufferLoad<float>(g_PushConstants.SharedConstants + 260)
#define g_Booleans vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 136) #define g_Booleans vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 264)
#define g_SwappedTexcoords vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 140) #define g_SwappedTexcoords vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 268)
#define g_InputLayoutFlags vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 144) #define g_InputLayoutFlags vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 272)
#define g_EnableGIBicubicFiltering vk::RawBufferLoad<bool>(g_PushConstants.SharedConstants + 148) #define g_EnableGIBicubicFiltering vk::RawBufferLoad<bool>(g_PushConstants.SharedConstants + 276)
#else #else
#define DEFINE_SHARED_CONSTANTS() \ #define DEFINE_SHARED_CONSTANTS() \
uint g_AlphaTestMode : packoffset(c8.x); \ uint g_AlphaTestMode : packoffset(c16.x); \
float g_AlphaThreshold : packoffset(c8.y); \ float g_AlphaThreshold : packoffset(c16.y); \
uint g_Booleans : packoffset(c8.z); \ uint g_Booleans : packoffset(c16.z); \
uint g_SwappedTexcoords : packoffset(c8.w); \ uint g_SwappedTexcoords : packoffset(c16.w); \
uint g_InputLayoutFlags : packoffset(c9.x); \ uint g_InputLayoutFlags : packoffset(c17.x); \
bool g_EnableGIBicubicFiltering : packoffset(c9.y) bool g_EnableGIBicubicFiltering : packoffset(c17.y)
#endif #endif

View file

@ -117,6 +117,13 @@ static constexpr std::pair<DeclUsage, size_t> INTERPOLATORS[] =
{ DeclUsage::Color, 1 } { DeclUsage::Color, 1 }
}; };
static constexpr std::string_view TEXTURE_DIMENSIONS[] =
{
"2D",
"3D",
"Cube"
};
static FetchDestinationSwizzle getDestSwizzle(uint32_t dstSwizzle, uint32_t index) static FetchDestinationSwizzle getDestSwizzle(uint32_t dstSwizzle, uint32_t index)
{ {
return FetchDestinationSwizzle((dstSwizzle >> (index * 3)) & 0x7); return FetchDestinationSwizzle((dstSwizzle >> (index * 3)) & 0x7);
@ -254,7 +261,7 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr, bool bicu
if (instr.constIndex == 0 && instr.dimension == TextureDimension::Texture2D) if (instr.constIndex == 0 && instr.dimension == TextureDimension::Texture2D)
{ {
indent(); indent();
print("pixelCoord = getPixelCoord({}_ResourceDescriptorIndex, ", constNamePtr); print("pixelCoord = getPixelCoord({}_Texture2DDescriptorIndex, ", constNamePtr);
printSrcRegister(2); printSrcRegister(2);
out += ");\n"; out += ");\n";
} }
@ -274,31 +281,34 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr, bool bicu
break; break;
} }
std::string_view dimension;
uint32_t componentCount = 0; uint32_t componentCount = 0;
switch (instr.dimension) switch (instr.dimension)
{ {
case TextureDimension::Texture1D: case TextureDimension::Texture1D:
out += "1D"; dimension = "1D";
componentCount = 1; componentCount = 1;
break; break;
case TextureDimension::Texture2D: case TextureDimension::Texture2D:
out += "2D"; dimension = "2D";
componentCount = 2; componentCount = 2;
break; break;
case TextureDimension::Texture3D: case TextureDimension::Texture3D:
out += "3D"; dimension = "3D";
componentCount = 3; componentCount = 3;
break; break;
case TextureDimension::TextureCube: case TextureDimension::TextureCube:
out += "Cube"; dimension = "Cube";
componentCount = 3; componentCount = 3;
break; break;
} }
out += dimension;
if (bicubic) if (bicubic)
out += "Bicubic"; out += "Bicubic";
print("({0}_ResourceDescriptorIndex, {0}_SamplerDescriptorIndex, ", constNamePtr); print("({0}_Texture{1}DescriptorIndex, {0}_SamplerDescriptorIndex, ", constNamePtr, dimension);
printSrcRegister(componentCount); printSrcRegister(componentCount);
switch (instr.dimension) switch (instr.dimension)
@ -1073,8 +1083,8 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData)
if (constantInfo->registerCount > 1) if (constantInfo->registerCount > 1)
{ {
println("#define {}(INDEX) vk::RawBufferLoad<float4>(g_PushConstants.{}ShaderConstants + ({} + INDEX) * 16, 0x10)", println("#define {}(INDEX) ((INDEX) < {} ? vk::RawBufferLoad<float4>(g_PushConstants.{}ShaderConstants + ({} + (INDEX)) * 16, 0x10) : 0.0)",
constantName, shaderName, constantInfo->registerIndex.get()); constantName, constantInfo->registerCount.get(), shaderName, constantInfo->registerIndex.get());
} }
else else
{ {
@ -1090,11 +1100,14 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData)
case RegisterSet::Sampler: case RegisterSet::Sampler:
{ {
println("#define {}_ResourceDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + {})", for (size_t j = 0; j < std::size(TEXTURE_DIMENSIONS); j++)
constantName, constantInfo->registerIndex * 4); {
println("#define {}_Texture{}DescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + {})",
constantName, TEXTURE_DIMENSIONS[j], j * 64 + constantInfo->registerIndex * 4);
}
println("#define {}_SamplerDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + {})", println("#define {}_SamplerDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + {})",
constantName, 64 + constantInfo->registerIndex * 4); constantName, std::size(TEXTURE_DIMENSIONS) * 64 + constantInfo->registerIndex * 4);
samplers.emplace(constantInfo->registerIndex, constantName); samplers.emplace(constantInfo->registerIndex, constantName);
break; break;
@ -1125,7 +1138,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData)
println(" : packoffset(c{});", constantInfo->registerIndex.get()); println(" : packoffset(c{});", constantInfo->registerIndex.get());
if (constantInfo->registerCount > 1) if (constantInfo->registerCount > 1)
println("#define {0}(INDEX) {0}[INDEX]", constantName); println("#define {0}(INDEX) ((INDEX) < {1} ? {0}[INDEX] : 0.0)", constantName, constantInfo->registerCount.get());
} }
} }
@ -1143,11 +1156,14 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData)
{ {
const char* constantName = reinterpret_cast<const char*>(constantTableData + constantInfo->name); const char* constantName = reinterpret_cast<const char*>(constantTableData + constantInfo->name);
println("\tuint {}_ResourceDescriptorIndex : packoffset(c{}.{});", for (size_t j = 0; j < std::size(TEXTURE_DIMENSIONS); j++)
constantName, constantInfo->registerIndex / 4, SWIZZLES[constantInfo->registerIndex % 4]); {
println("\tuint {}_Texture{}DescriptorIndex : packoffset(c{}.{});",
constantName, TEXTURE_DIMENSIONS[j], j * 4 + constantInfo->registerIndex / 4, SWIZZLES[constantInfo->registerIndex % 4]);
}
println("\tuint {}_SamplerDescriptorIndex : packoffset(c{}.{});", println("\tuint {}_SamplerDescriptorIndex : packoffset(c{}.{});",
constantName, 4 + constantInfo->registerIndex / 4, SWIZZLES[constantInfo->registerIndex % 4]); constantName, 4 * std::size(TEXTURE_DIMENSIONS) + constantInfo->registerIndex / 4, SWIZZLES[constantInfo->registerIndex % 4]);
} }
} }