mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #130 from oneandonlydean/feat/agc-texture-min-lod
feat(agc): apply a texture descriptor's MIN_LOD clamp through the image view
This commit is contained in:
@@ -197,12 +197,28 @@ target_link_libraries(agc_driver_flip_tests PRIVATE
|
||||
set_target_properties(agc_driver_flip_tests PROPERTIES CXX_EXTENSIONS OFF)
|
||||
configure_windows_unwind(agc_driver_flip_tests)
|
||||
|
||||
set(agcSampleLodShaderSource ${CMAKE_CURRENT_SOURCE_DIR}/tests/shaders/SampleLod.comp)
|
||||
set(agcTestShaderGeneratedRoot ${CMAKE_CURRENT_BINARY_DIR}/generated-tests)
|
||||
set(agcSampleLodShaderSpv ${agcTestShaderGeneratedRoot}/SampleLod.spv)
|
||||
set(agcSampleLodShaderHeader ${agcTestShaderGeneratedRoot}/SampleLod_spv.h)
|
||||
add_custom_command(
|
||||
OUTPUT "${agcSampleLodShaderHeader}"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${agcTestShaderGeneratedRoot}"
|
||||
COMMAND "$<TARGET_FILE:glslang-standalone>" -V --target-env vulkan1.1 -o "${agcSampleLodShaderSpv}" "${agcSampleLodShaderSource}"
|
||||
COMMAND ${CMAKE_COMMAND} -DINPUT=${agcSampleLodShaderSpv} -DOUTPUT=${agcSampleLodShaderHeader}
|
||||
-DSYMBOL=SAMPLE_LOD_SPV -P "${CMAKE_CURRENT_SOURCE_DIR}/embed_spirv.cmake"
|
||||
DEPENDS "${agcSampleLodShaderSource}" glslang-standalone
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_executable(agc_driver_recorder_tests EXCLUDE_FROM_ALL
|
||||
tests/Recorder.cpp
|
||||
${agcSampleLodShaderHeader}
|
||||
)
|
||||
|
||||
target_include_directories(agc_driver_recorder_tests PRIVATE
|
||||
${LIBS_INCLUDE_DIR}
|
||||
${agcTestShaderGeneratedRoot}
|
||||
${CMAKE_SOURCE_DIR}/core/shader/recompiler
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/Vulkan-Headers/include
|
||||
)
|
||||
|
||||
@@ -188,6 +188,7 @@ struct VulkanDevice::State {
|
||||
bool descriptorIndexing = false;
|
||||
bool primitiveListRestart = false;
|
||||
bool depthClipControl = false;
|
||||
bool imageViewMinLod = false;
|
||||
bool depthClamp = false;
|
||||
bool occlusionQueryPrecise = false;
|
||||
VkDeviceSize hostImportAlignment = 0;
|
||||
@@ -743,6 +744,15 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u
|
||||
}
|
||||
listRestartFeatures = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT};
|
||||
listRestartFeatures.primitiveTopologyListRestart = state->primitiveListRestart ? VK_TRUE : VK_FALSE;
|
||||
VkPhysicalDeviceImageViewMinLodFeaturesEXT minLodFeatures{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT};
|
||||
if (hasExtension(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME)) {
|
||||
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &minLodFeatures};
|
||||
state->InstanceFunction<PFN_vkGetPhysicalDeviceFeatures2>("vkGetPhysicalDeviceFeatures2")(selected, &features);
|
||||
state->imageViewMinLod = minLodFeatures.minLod == VK_TRUE;
|
||||
if (state->imageViewMinLod) deviceExtensions.push_back(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME);
|
||||
}
|
||||
minLodFeatures = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT};
|
||||
minLodFeatures.minLod = VK_TRUE;
|
||||
VkPhysicalDeviceDepthClipControlFeaturesEXT depthClipFeatures{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_CONTROL_FEATURES_EXT};
|
||||
if (hasExtension(VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME)) {
|
||||
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &depthClipFeatures};
|
||||
@@ -838,6 +848,10 @@ VulkanDevice::VulkanDevice(const PresentationWindow* window) : state(std::make_u
|
||||
listRestartFeatures.pNext = const_cast<void*>(deviceInfo.pNext);
|
||||
deviceInfo.pNext = &listRestartFeatures;
|
||||
}
|
||||
if (state->imageViewMinLod) {
|
||||
minLodFeatures.pNext = const_cast<void*>(deviceInfo.pNext);
|
||||
deviceInfo.pNext = &minLodFeatures;
|
||||
}
|
||||
byteFeatures.pNext = const_cast<void*>(deviceInfo.pNext);
|
||||
if (state->fragmentShaderBarycentric) {
|
||||
barycentricFeatures.pNext = byteFeatures.pNext;
|
||||
@@ -2189,6 +2203,7 @@ Graphics::Context VulkanDevice::buildContext() const {
|
||||
context.functions = state->functionsReady ? &state->deviceFunctions : nullptr;
|
||||
context.descriptorIndexing = state->descriptorIndexing;
|
||||
context.primitiveListRestart = state->primitiveListRestart;
|
||||
context.imageViewMinLod = state->imageViewMinLod;
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ struct Context {
|
||||
// (bindless image tables in graphics stages).
|
||||
bool descriptorIndexing = false;
|
||||
bool primitiveListRestart = false;
|
||||
bool imageViewMinLod = false;
|
||||
|
||||
template<typename TFunction>
|
||||
TFunction Function(const char* name) const {
|
||||
|
||||
@@ -60,8 +60,11 @@ struct GuestTextureResource {
|
||||
// DCC metadata of a compressed surface, or 0 (see DccMetadata.hpp).
|
||||
std::uint64_t dccAddress = 0;
|
||||
bool dccAlphaOnMsb = false;
|
||||
std::uint32_t minLod = 0;
|
||||
};
|
||||
|
||||
float EffectiveMinLod(const GuestTextureResource& resource);
|
||||
|
||||
GuestTextureResource DecodeTextureResource(std::span<const std::uint32_t> words);
|
||||
bool MatchesGuestDimension(ShaderRecompiler::DescriptorImageShape shape, TextureDimension dimension);
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ GuestTextureResource DecodeTextureResource(std::span<const std::uint32_t> words)
|
||||
requireValidDstSel(dstSelZ);
|
||||
requireValidDstSel(dstSelW);
|
||||
|
||||
Require(minLod == 0, "guest texture descriptor uses a nonzero minimum LOD clamp which is not implemented");
|
||||
// The LOD warning threshold and mip statistics counters are texture-streaming feedback: the GPU
|
||||
// reports which mips were wanted. Nothing is reported back here, which only affects what the title
|
||||
// chooses to stream, not what this access returns.
|
||||
@@ -176,9 +175,15 @@ GuestTextureResource DecodeTextureResource(std::span<const std::uint32_t> words)
|
||||
result.dstSelW = static_cast<std::uint8_t>(dstSelW);
|
||||
result.dccAddress = metaCompress ? metaAddr << 8u : 0u;
|
||||
result.dccAlphaOnMsb = dccAlphaPos;
|
||||
result.minLod = minLod;
|
||||
return result;
|
||||
}
|
||||
|
||||
float EffectiveMinLod(const GuestTextureResource& resource) {
|
||||
if (resource.minLod <= resource.baseLevel * 256u) return 0.0f;
|
||||
return std::min(static_cast<float>(resource.minLod) / 256.0f, static_cast<float>(resource.lastLevel));
|
||||
}
|
||||
|
||||
bool MatchesGuestDimension(ShaderRecompiler::DescriptorImageShape shape, TextureDimension dimension) {
|
||||
switch (shape) {
|
||||
case ShaderRecompiler::DescriptorImageShape::Image1D: return dimension == TextureDimension::k1D;
|
||||
|
||||
@@ -2420,6 +2420,7 @@ void ShaderResources::resolveImageBinding(const ShaderRecompiler::DescriptorBind
|
||||
const auto resource = record != nullptr && record->decoded ? record->resource : DecodeTextureResource(words);
|
||||
if (binding.imageShape.has_value()) Require(MatchesGuestDimension(*binding.imageShape, resource.dimension), "guest storage texture dimension disagrees with the shader's declared image shape");
|
||||
const auto mip = std::min(resource.baseLevel + mipOffset, resource.mipCount - 1u);
|
||||
Require(resource.minLod <= mip * 256u, "guest storage texture descriptor clamps its minimum LOD above the level it addresses, which is not implemented");
|
||||
const auto guestBytes = record != nullptr && record->decoded ? record->guestBytes : DescribeSurface(resource).guestBytes;
|
||||
// The same surface as the previous element: its image was just looked up and refreshed.
|
||||
if (sameAsPrevious && StorageDedupeEnabled()) storageTextures.push_back(storageTextures.back());
|
||||
|
||||
@@ -210,6 +210,19 @@ VkImageViewType ViewTypeFor(TextureDimension dimension, [[maybe_unused]] std::ui
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void ChainMinLod(const Context& context, const GuestTextureResource& descriptor, VkImageViewCreateInfo& viewInfo, VkImageViewMinLodCreateInfoEXT& minLod) {
|
||||
const auto clamp = EffectiveMinLod(descriptor);
|
||||
if (clamp == 0.0f) return;
|
||||
Require(context.imageViewMinLod, "guest texture descriptor uses a minimum LOD clamp, which needs VK_EXT_image_view_min_lod");
|
||||
minLod.minLod = clamp;
|
||||
minLod.pNext = viewInfo.pNext;
|
||||
viewInfo.pNext = &minLod;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Texture::Texture(const Context& context, TextureDetiler& detiler, const GuestTextureResource& descriptor, VkComponentMapping components, std::span<const std::byte> snapshot) : context(context) {
|
||||
static const bool profile = std::getenv("APS5_PROFILE_DRAW") != nullptr;
|
||||
PhaseTimer timer;
|
||||
@@ -403,6 +416,8 @@ Texture::Texture(const Context& context, TextureDetiler& detiler, const GuestTex
|
||||
viewInfo.format = vkFormat;
|
||||
viewInfo.components = components;
|
||||
viewInfo.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, descriptor.baseLevel, viewLevelCount, descriptor.baseArray, viewLayerCount};
|
||||
VkImageViewMinLodCreateInfoEXT minLod{VK_STRUCTURE_TYPE_IMAGE_VIEW_MIN_LOD_CREATE_INFO_EXT};
|
||||
ChainMinLod(context, descriptor, viewInfo, minLod);
|
||||
Check(context.Function<PFN_vkCreateImageView>("vkCreateImageView")(context.device, &viewInfo, nullptr, &view), "vkCreateImageView");
|
||||
if (profile) {
|
||||
auto& totals = Profile();
|
||||
@@ -444,6 +459,8 @@ Texture::Texture(const Context& context, const std::shared_ptr<StorageTexture>&
|
||||
viewInfo.format = vkFormat;
|
||||
viewInfo.components = components;
|
||||
viewInfo.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, descriptor.baseLevel, viewLevelCount, descriptor.baseArray, viewLayerCount};
|
||||
VkImageViewMinLodCreateInfoEXT minLod{VK_STRUCTURE_TYPE_IMAGE_VIEW_MIN_LOD_CREATE_INFO_EXT};
|
||||
ChainMinLod(context, descriptor, viewInfo, minLod);
|
||||
Check(context.Function<PFN_vkCreateImageView>("vkCreateImageView")(context.device, &viewInfo, nullptr, &view), "vkCreateImageView storage view");
|
||||
if (profile) {
|
||||
auto& totals = Profile();
|
||||
|
||||
@@ -178,9 +178,27 @@ void RunGuestTextureResourceTests() {
|
||||
zeroAddress.base40 = 0;
|
||||
rejectFields(zeroAddress, "null base address");
|
||||
|
||||
Fields badMinLod = base;
|
||||
badMinLod.minLod = 1;
|
||||
rejectFields(badMinLod, "nonzero minimum LOD clamp");
|
||||
Fields minLod = base;
|
||||
minLod.maxMip = 4;
|
||||
minLod.baseLevel = 1;
|
||||
minLod.lastLevel = 3;
|
||||
minLod.minLod = 0x180;
|
||||
auto clamped = DecodeTextureResource(pack(minLod));
|
||||
Require(clamped.minLod == 0x180 && EffectiveMinLod(clamped) == 1.5f, "MIN_LOD 1.5 over levels 1..3 did not clamp at 1.5");
|
||||
minLod.minLod = 0x100;
|
||||
clamped = DecodeTextureResource(pack(minLod));
|
||||
Require(EffectiveMinLod(clamped) == 0.0f, "MIN_LOD at BASE_LEVEL cannot bind but was applied");
|
||||
minLod.minLod = 0x0c0;
|
||||
clamped = DecodeTextureResource(pack(minLod));
|
||||
Require(EffectiveMinLod(clamped) == 0.0f, "MIN_LOD below BASE_LEVEL cannot bind but was applied");
|
||||
minLod.minLod = 0xfff;
|
||||
clamped = DecodeTextureResource(pack(minLod));
|
||||
Require(EffectiveMinLod(clamped) == 3.0f, "MIN_LOD past the view's last level was not bounded by it");
|
||||
minLod.baseLevel = 0;
|
||||
minLod.minLod = 0x001;
|
||||
clamped = DecodeTextureResource(pack(minLod));
|
||||
Require(EffectiveMinLod(clamped) == 1.0f / 256.0f, "the smallest MIN_LOD step above level 0 was lost");
|
||||
Require(DecodeTextureResource(pack(base)).minLod == 0 && EffectiveMinLod(DecodeTextureResource(pack(base))) == 0.0f, "an unclamped descriptor gained a MIN_LOD");
|
||||
|
||||
// Streaming feedback fields decode; nothing is reported back.
|
||||
Fields feedback = base;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "prx/libc/include/GuestAllocations.hpp"
|
||||
#include "prx/libc/include/GuestArena.hpp"
|
||||
#include "prx/libc/include/GuestWriteWatch.hpp"
|
||||
#include "SampleLod_spv.h"
|
||||
#include <SDL_loadso.h>
|
||||
#ifdef _WIN32
|
||||
#ifndef NOMINMAX
|
||||
@@ -25,6 +26,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
@@ -130,6 +132,19 @@ public:
|
||||
function<PFN_vkGetPhysicalDeviceProperties2>("vkGetPhysicalDeviceProperties2")(context.physical, &properties);
|
||||
context.hostImportAlignment = hostProperties.minImportedHostPointerAlignment;
|
||||
}
|
||||
VkPhysicalDeviceImageViewMinLodFeaturesEXT minLod{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT};
|
||||
if (hasExtension(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME)) {
|
||||
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &minLod};
|
||||
function<PFN_vkGetPhysicalDeviceFeatures2>("vkGetPhysicalDeviceFeatures2")(context.physical, &features);
|
||||
context.imageViewMinLod = minLod.minLod == VK_TRUE;
|
||||
}
|
||||
minLod = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_MIN_LOD_FEATURES_EXT};
|
||||
minLod.minLod = VK_TRUE;
|
||||
if (context.imageViewMinLod) {
|
||||
extensionsEnabled.push_back(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME);
|
||||
minLod.pNext = address.pNext;
|
||||
address.pNext = &minLod;
|
||||
}
|
||||
VkDeviceCreateInfo device{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, &address};
|
||||
device.queueCreateInfoCount = 1;
|
||||
device.pQueueCreateInfos = &queue;
|
||||
@@ -1555,6 +1570,157 @@ void dataRefreshTests(const Device& device, Recorder& recorder) {
|
||||
|
||||
}
|
||||
|
||||
class SampleProgram {
|
||||
public:
|
||||
SampleProgram(const Context& context, Recorder& recorder) : context(context), recorder(recorder), result(context, sizeof(float) * 4, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) {
|
||||
VkDescriptorSetLayoutBinding bindings[2]{};
|
||||
bindings[0] = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
|
||||
bindings[1] = {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
|
||||
VkDescriptorSetLayoutCreateInfo layoutInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
|
||||
layoutInfo.bindingCount = 2;
|
||||
layoutInfo.pBindings = bindings;
|
||||
Check(context.Function<PFN_vkCreateDescriptorSetLayout>("vkCreateDescriptorSetLayout")(context.device, &layoutInfo, nullptr, &setLayout), "vkCreateDescriptorSetLayout");
|
||||
const VkPushConstantRange push{VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(float)};
|
||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
|
||||
pipelineLayoutInfo.setLayoutCount = 1;
|
||||
pipelineLayoutInfo.pSetLayouts = &setLayout;
|
||||
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||
pipelineLayoutInfo.pPushConstantRanges = &push;
|
||||
Check(context.Function<PFN_vkCreatePipelineLayout>("vkCreatePipelineLayout")(context.device, &pipelineLayoutInfo, nullptr, &pipelineLayout), "vkCreatePipelineLayout");
|
||||
VkShaderModuleCreateInfo moduleInfo{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
|
||||
moduleInfo.codeSize = sizeof(SAMPLE_LOD_SPV);
|
||||
moduleInfo.pCode = SAMPLE_LOD_SPV;
|
||||
Check(context.Function<PFN_vkCreateShaderModule>("vkCreateShaderModule")(context.device, &moduleInfo, nullptr, &module), "vkCreateShaderModule");
|
||||
VkComputePipelineCreateInfo pipelineInfo{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO};
|
||||
pipelineInfo.stage = {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, module, "main", nullptr};
|
||||
pipelineInfo.layout = pipelineLayout;
|
||||
Check(context.Function<PFN_vkCreateComputePipelines>("vkCreateComputePipelines")(context.device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline), "vkCreateComputePipelines");
|
||||
VkSamplerCreateInfo samplerInfo{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
|
||||
samplerInfo.magFilter = VK_FILTER_NEAREST;
|
||||
samplerInfo.minFilter = VK_FILTER_NEAREST;
|
||||
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||
samplerInfo.addressModeU = samplerInfo.addressModeV = samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
samplerInfo.maxLod = VK_LOD_CLAMP_NONE;
|
||||
Check(context.Function<PFN_vkCreateSampler>("vkCreateSampler")(context.device, &samplerInfo, nullptr, &sampler), "vkCreateSampler");
|
||||
const VkDescriptorPoolSize sizes[2]{{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}};
|
||||
VkDescriptorPoolCreateInfo poolInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
|
||||
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
poolInfo.maxSets = 1;
|
||||
poolInfo.poolSizeCount = 2;
|
||||
poolInfo.pPoolSizes = sizes;
|
||||
Check(context.Function<PFN_vkCreateDescriptorPool>("vkCreateDescriptorPool")(context.device, &poolInfo, nullptr, &pool), "vkCreateDescriptorPool");
|
||||
}
|
||||
~SampleProgram() {
|
||||
context.Function<PFN_vkDestroyDescriptorPool>("vkDestroyDescriptorPool")(context.device, pool, nullptr);
|
||||
context.Function<PFN_vkDestroySampler>("vkDestroySampler")(context.device, sampler, nullptr);
|
||||
context.Function<PFN_vkDestroyPipeline>("vkDestroyPipeline")(context.device, pipeline, nullptr);
|
||||
context.Function<PFN_vkDestroyShaderModule>("vkDestroyShaderModule")(context.device, module, nullptr);
|
||||
context.Function<PFN_vkDestroyPipelineLayout>("vkDestroyPipelineLayout")(context.device, pipelineLayout, nullptr);
|
||||
context.Function<PFN_vkDestroyDescriptorSetLayout>("vkDestroyDescriptorSetLayout")(context.device, setLayout, nullptr);
|
||||
}
|
||||
SampleProgram(const SampleProgram&) = delete;
|
||||
SampleProgram& operator=(const SampleProgram&) = delete;
|
||||
|
||||
float Red(VkImageView view, VkImageLayout layout, float lod) {
|
||||
VkDescriptorSetAllocateInfo allocateInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
|
||||
allocateInfo.descriptorPool = pool;
|
||||
allocateInfo.descriptorSetCount = 1;
|
||||
allocateInfo.pSetLayouts = &setLayout;
|
||||
VkDescriptorSet set = VK_NULL_HANDLE;
|
||||
Check(context.Function<PFN_vkAllocateDescriptorSets>("vkAllocateDescriptorSets")(context.device, &allocateInfo, &set), "vkAllocateDescriptorSets");
|
||||
const VkDescriptorImageInfo image{sampler, view, layout};
|
||||
const VkDescriptorBufferInfo buffer{result.Handle(), 0, VK_WHOLE_SIZE};
|
||||
VkWriteDescriptorSet writes[2]{{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}};
|
||||
writes[0].dstSet = set;
|
||||
writes[0].dstBinding = 0;
|
||||
writes[0].descriptorCount = 1;
|
||||
writes[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
writes[0].pImageInfo = ℑ
|
||||
writes[1].dstSet = set;
|
||||
writes[1].dstBinding = 1;
|
||||
writes[1].descriptorCount = 1;
|
||||
writes[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
||||
writes[1].pBufferInfo = &buffer;
|
||||
context.Function<PFN_vkUpdateDescriptorSets>("vkUpdateDescriptorSets")(context.device, 2, writes, 0, nullptr);
|
||||
const auto commands = recorder.Commands();
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
context.Function<PFN_vkCmdBindPipeline>("vkCmdBindPipeline")(commands, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
|
||||
context.Function<PFN_vkCmdBindDescriptorSets>("vkCmdBindDescriptorSets")(commands, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0, 1, &set, 0, nullptr);
|
||||
context.Function<PFN_vkCmdPushConstants>("vkCmdPushConstants")(commands, pipelineLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(lod), &lod);
|
||||
context.Function<PFN_vkCmdDispatch>("vkCmdDispatch")(commands, 1, 1, 1);
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT);
|
||||
recorder.Submit();
|
||||
recorder.Sync();
|
||||
Check(context.Function<PFN_vkFreeDescriptorSets>("vkFreeDescriptorSets")(context.device, pool, 1, &set), "vkFreeDescriptorSets");
|
||||
float texel[4];
|
||||
std::memcpy(texel, result.Bytes().data(), sizeof(texel));
|
||||
return texel[0];
|
||||
}
|
||||
|
||||
private:
|
||||
const Context& context;
|
||||
Recorder& recorder;
|
||||
Buffer result;
|
||||
VkDescriptorSetLayout setLayout = VK_NULL_HANDLE;
|
||||
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
||||
VkShaderModule module = VK_NULL_HANDLE;
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
VkSampler sampler = VK_NULL_HANDLE;
|
||||
VkDescriptorPool pool = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
void expectRed(float got, float want, const char* what) {
|
||||
if (std::abs(got - want) > 1.5f / 255.0f) throw std::runtime_error(std::string(what) + ": read " + std::to_string(got) + ", expected " + std::to_string(want));
|
||||
}
|
||||
|
||||
void minLodTests(const Device& device, Recorder& recorder) {
|
||||
const auto& context = device.GetContext();
|
||||
if (!context.imageViewMinLod) {
|
||||
std::cout << "VK_EXT_image_view_min_lod unavailable: minimum LOD clamp not tested\n";
|
||||
return;
|
||||
}
|
||||
TextureDetiler detiler(context);
|
||||
GuestTextureResource resource{};
|
||||
resource.baseAddress = 0x100000;
|
||||
resource.width = 8;
|
||||
resource.height = 8;
|
||||
resource.mipCount = 4;
|
||||
resource.baseLevel = 0;
|
||||
resource.lastLevel = 3;
|
||||
resource.tileMode = TextureTileMode::kLinear;
|
||||
resource.dimension = TextureDimension::k2D;
|
||||
resource.format = 56;
|
||||
resource.dstSelX = 4;
|
||||
resource.dstSelY = 5;
|
||||
resource.dstSelZ = 6;
|
||||
resource.dstSelW = 7;
|
||||
const auto geometry = DescribeSurface(resource);
|
||||
Require(geometry.mips.size() == 4, "the min LOD test surface has an unexpected mip count");
|
||||
const std::array<std::uint8_t, 4> levels{0x00, 0x40, 0x80, 0xff};
|
||||
std::vector<std::byte> snapshot(static_cast<std::size_t>(geometry.guestBytes));
|
||||
for (std::size_t level = 0; level < levels.size(); ++level) {
|
||||
const auto& mip = geometry.mips[level];
|
||||
std::fill_n(snapshot.begin() + static_cast<std::ptrdiff_t>(mip.tiledOffset), static_cast<std::size_t>(mip.tiledSize), std::byte{levels[level]});
|
||||
}
|
||||
SampleProgram program(context, recorder);
|
||||
const VkComponentMapping identity{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY};
|
||||
const auto sample = [&](std::uint32_t minLod, float lod, std::uint32_t baseLevel = 0) {
|
||||
auto described = resource;
|
||||
described.minLod = minLod;
|
||||
described.baseLevel = baseLevel;
|
||||
Texture texture(context, detiler, described, identity, snapshot);
|
||||
return program.Red(texture.View(), texture.Layout(), lod);
|
||||
};
|
||||
const auto unorm = [&](std::size_t level) { return levels[level] / 255.0f; };
|
||||
expectRed(sample(0, 0.0f), unorm(0), "minimum LOD clamp: no clamp reads level 0");
|
||||
expectRed(sample(0x100, 0.0f), unorm(1), "minimum LOD clamp: MIN_LOD 1 reads level 1 at LOD 0");
|
||||
expectRed(sample(0x180, 0.0f), (unorm(1) + unorm(2)) / 2.0f, "minimum LOD clamp: MIN_LOD 1.5 blends levels 1 and 2");
|
||||
expectRed(sample(0x100, 2.0f), unorm(2), "minimum LOD clamp: MIN_LOD 1 lowered LOD 2");
|
||||
expectRed(sample(0xfff, 0.0f), unorm(3), "minimum LOD clamp: MIN_LOD past the last level reads the last level");
|
||||
expectRed(sample(0x200, 0.0f, 1), unorm(2), "minimum LOD clamp: MIN_LOD 2 over a view from level 1 reads level 2");
|
||||
expectRed(sample(0x100, 0.0f, 1), unorm(1), "minimum LOD clamp: MIN_LOD at the view's base level reads its base level");
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
Device device;
|
||||
@@ -1581,6 +1747,7 @@ int main() {
|
||||
importWindowTests(device, recorder);
|
||||
dataWordPositionsTests();
|
||||
dataRefreshTests(device, recorder);
|
||||
minLodTests(device, recorder);
|
||||
std::cout << "Recorder read tracking and label tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#version 450
|
||||
|
||||
layout(local_size_x = 1) in;
|
||||
layout(set = 0, binding = 0) uniform sampler2D source;
|
||||
layout(set = 0, binding = 1, std430) buffer Result { vec4 texel; };
|
||||
layout(push_constant) uniform Parameters { float lod; } parameters;
|
||||
|
||||
void main() {
|
||||
texel = textureLod(source, vec2(0.5), parameters.lod);
|
||||
}
|
||||
Reference in New Issue
Block a user