Skip to content
Open
1 change: 1 addition & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SamplerCache {

void RequireFilterMinmax(const Context& context, VkFormat format, std::uint64_t samplerMask, std::span<const std::shared_ptr<Sampler>> samplers);
bool ForcesDegammaOn(std::uint32_t guestFormat, std::uint64_t samplerMask, std::span<const std::shared_ptr<Sampler>> samplers);
bool DisablesDegammaOn(std::uint32_t guestFormat, std::uint64_t samplerMask, std::span<const std::shared_ptr<Sampler>> samplers);
void RequireBorderSwizzle(std::uint32_t bcSwizzle, std::uint64_t samplerMask, std::span<const std::shared_ptr<Sampler>> samplers);
std::uint32_t BorderMappingKey(const std::optional<BorderComponentMapping>& mapping);
std::optional<BorderComponentMapping> OpaqueBlackBorderMapping(const Context& context, std::span<const OpaqueBlackPairing> pairings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TextureCacheUse TextureCacheUsage();
void OverrideCacheBudgetForTest(std::uint64_t bytes);
void SampledFromStorageForTest(bool enabled);
std::uint64_t SampledTextureCacheBudget(const Context& context);
std::shared_ptr<Texture> CachedSampledTexture(const Context& context, std::span<const std::uint32_t> words, VkImageViewType multisampleViewType = VK_IMAGE_VIEW_TYPE_2D);
std::shared_ptr<Texture> CachedSampledTexture(const Context& context, std::span<const std::uint32_t> words, VkImageViewType multisampleViewType = VK_IMAGE_VIEW_TYPE_2D, bool unormView = false);
bool SampledTexturesShareEntry(std::span<const std::uint32_t> first, std::span<const std::uint32_t> second);
bool AnyPendingCpuWrites(const Context& context);
bool CompletePendingCpuWrites(const Context& context, std::uint64_t address, std::size_t bytes);
Expand Down Expand Up @@ -786,7 +786,7 @@ class ShaderResources {
std::vector<bool> textureFirstLayer;
std::unordered_set<std::size_t> arrayViewTextures;
std::vector<bool> textureBaseLevel;
std::vector<bool> textureSrgb;
std::vector<std::uint8_t> textureGamma;
std::vector<std::shared_ptr<StorageTexture>> storageTextures;
std::vector<VkImageView> multisampleStorageViews;
std::vector<std::uint32_t> storageMips;
Expand Down
16 changes: 10 additions & 6 deletions core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ struct OwnedImage {

class Texture {
public:
Texture(const Context& context, TextureDetiler& detiler, const GuestTextureResource& descriptor, VkComponentMapping components, std::span<const std::byte> snapshot, bool depthCompare = false, bool layerRows = false, const VkClearColorValue* clear = nullptr, std::optional<std::span<const std::uint32_t>> packedSlabs = std::nullopt, std::span<const HostImportCopy> sources = {});
Texture(const Context& context, TextureDetiler& detiler, const GuestTextureResource& descriptor, VkComponentMapping components, std::shared_ptr<Buffer> staging, bool depthCompare = false, bool layerRows = false, std::optional<std::span<const std::uint32_t>> packedSlabs = std::nullopt);
Texture(const Context& context, TextureDetiler& detiler, const GuestTextureResource& descriptor, VkComponentMapping components, std::span<const std::byte> snapshot, bool depthCompare = false, bool layerRows = false, const VkClearColorValue* clear = nullptr, std::optional<std::span<const std::uint32_t>> packedSlabs = std::nullopt, std::span<const HostImportCopy> sources = {}, bool unormView = false);
Texture(const Context& context, TextureDetiler& detiler, const GuestTextureResource& descriptor, VkComponentMapping components, std::shared_ptr<Buffer> staging, bool depthCompare = false, bool layerRows = false, std::optional<std::span<const std::uint32_t>> packedSlabs = std::nullopt, bool unormView = false);
Texture(const Context& context, const std::shared_ptr<ResidentColor>& source, const GuestTextureResource& descriptor, VkComponentMapping components);
// A view of a storage image's own VkImage: the sampled texture follows the image's content, so a
// compute pass writing it and the next pass sampling it share one image and copy nothing.
Expand All @@ -104,7 +104,7 @@ class Texture {
static VkFormat DepthCopyFormat(VkFormat colorFormat);
static bool CanDepthCopyFrom(const StorageTexture& source, const GuestTextureResource& descriptor);
struct BlockCopyTag {};
Texture(const Context& context, const std::shared_ptr<StorageTexture>& source, const GuestTextureResource& descriptor, VkComponentMapping components, BlockCopyTag);
Texture(const Context& context, const std::shared_ptr<StorageTexture>& source, const GuestTextureResource& descriptor, VkComponentMapping components, BlockCopyTag, bool unormView = false);
static bool CanBlockCopyFrom(const StorageTexture& source, const GuestTextureResource& descriptor);
struct RepackCopyTag {};
Texture(const Context& context, const std::shared_ptr<StorageTexture>& source, const GuestTextureResource& descriptor, VkComponentMapping components, RepackCopyTag);
Expand All @@ -125,9 +125,11 @@ class Texture {
VkImageView FirstLayerView() const { return firstLayerView; }
VkImageView BaseLevelView() const;
bool HasSrgbView() const { return srgbInfo.has_value(); }
bool HasUnormView() const { return unormInfo.has_value(); }
bool HasArrayView() const { return arrayInfo.has_value(); }
VkImageView ArrayView() const;
VkImageView SrgbView(bool firstLayer, bool baseLevel) const;
VkImageView SampledGammaView(bool firstLayer, bool baseLevel, bool srgb) const;
struct ViewRange {
VkImageViewType type;
std::uint32_t levels;
Expand Down Expand Up @@ -163,13 +165,13 @@ class Texture {
void MarkReleased() { released.store(true, std::memory_order_release); }

private:
Texture(const Context& context, TextureDetiler& detiler, const GuestTextureResource& descriptor, VkComponentMapping components, std::span<const std::byte> snapshot, std::shared_ptr<Buffer> staging, bool depthCompare, bool layerRows, const VkClearColorValue* clear, std::optional<std::span<const std::uint32_t>> packedSlabs, std::span<const HostImportCopy> sources);
Texture(const Context& context, TextureDetiler& detiler, const GuestTextureResource& descriptor, VkComponentMapping components, std::span<const std::byte> snapshot, std::shared_ptr<Buffer> staging, bool depthCompare, bool layerRows, const VkClearColorValue* clear, std::optional<std::span<const std::uint32_t>> packedSlabs, std::span<const HostImportCopy> sources, bool unormView);
void release() noexcept;
bool refreshBlockCopy();
bool refreshSrgbExpand();
void createFirstLayerView(const GuestTextureResource& descriptor, VkImageViewCreateInfo viewInfo);
void prepareBaseLevelView(const GuestTextureResource& descriptor, VkImageViewCreateInfo viewInfo);
void prepareSrgbView(const GuestTextureResource& descriptor, VkImageViewCreateInfo viewInfo);
void prepareSrgbView(const GuestTextureResource& descriptor, VkImageViewCreateInfo viewInfo, bool unormView = false);

// Held by value: cached textures outlive the Context of the draw that created them.
Context context;
Expand All @@ -185,9 +187,11 @@ class Texture {
mutable std::mutex baseLevelMutex;
mutable VkImageView baseLevelView = VK_NULL_HANDLE;
std::optional<VkImageViewCreateInfo> srgbInfo;
std::optional<VkImageViewCreateInfo> unormInfo;
float srgbMinLod = 0.0f;
mutable std::mutex srgbMutex;
mutable std::array<VkImageView, 3> srgbViews{};
mutable std::array<VkImageView, 3> unormViews{};
std::optional<VkImageViewCreateInfo> arrayInfo;
float arrayMinLod = 0.0f;
mutable std::mutex arrayMutex;
Expand Down Expand Up @@ -216,7 +220,7 @@ class Texture {
};

VkFormat AttachmentProxyFormat(const Context& context, VkFormat format);
VkFormat SrgbTwinFormat(const Context& context, VkFormat format);
VkFormat SrgbTwinFormat(const Context& context, VkFormat format, bool unormView = false);

class UnitFlags {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ class MultisampleTarget : public std::enable_shared_from_this<MultisampleTarget>
});
const std::array<std::uint32_t, 5> key{static_cast<std::uint32_t>(components.r), static_cast<std::uint32_t>(components.g), static_cast<std::uint32_t>(components.b), static_cast<std::uint32_t>(components.a), static_cast<std::uint32_t>(viewType)};
auto& texture = textures[key];
if (texture == nullptr) texture = std::make_shared<Texture>(context, image, target.format, VK_IMAGE_ASPECT_COLOR_BIT, components, viewType, 0, std::shared_ptr<OwnedImage>{}, orderFormat != VK_FORMAT_UNDEFINED ? VK_IMAGE_USAGE_SAMPLED_BIT : VkImageUsageFlags{0});
if (texture == nullptr) texture = std::make_shared<Texture>(context, image, target.format, VK_IMAGE_ASPECT_COLOR_BIT, components, viewType, 0, std::shared_ptr<OwnedImage>{}, VK_IMAGE_USAGE_SAMPLED_BIT);
return {shared_from_this(), texture.get()};
}

Expand Down
17 changes: 16 additions & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/src/Sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace AgcDriver::Graphics {
Sampler::Sampler(const Context& context, const GuestSamplerResource& descriptor, const std::optional<BorderComponentMapping>& borderMapping) : context(context), borderMapping(borderMapping) {
Validate(context, descriptor);
forcesDegamma = descriptor.forceDegamma;
disablesDegamma = descriptor.disableDegamma;
disablesDegamma = descriptor.disableDegamma && !descriptor.forceDegamma;

VkSamplerCreateInfo info{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
VkSamplerReductionModeCreateInfoEXT reduction{VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT, nullptr, descriptor.reductionMode};
Expand Down Expand Up @@ -202,6 +202,21 @@ namespace AgcDriver::Graphics {
return false;
}

bool DisablesDegammaOn(std::uint32_t guestFormat, std::uint64_t samplerMask, std::span<const std::shared_ptr<Sampler>> samplers) {
bool disabled = false;
bool enabled = false;
for (auto mask = samplerMask; mask != 0u; mask &= mask - 1u) {
const auto element = static_cast<std::uint32_t>(std::countr_zero(mask));
Require(element < samplers.size(), "a sampled texture is paired with an unbound sampler element " + std::to_string(element));
const auto& sampler = samplers[element];
disabled = disabled || sampler->DisablesDegamma();
enabled = enabled || !sampler->DisablesDegamma();
}
if (!IsSrgbTextureFormat(guestFormat)) return false;
Require(!disabled || !enabled, "an sRGB texture is paired with both ordinary and SKIP_DEGAMMA samplers, which needs distinct sampled views and is not implemented");
return disabled;
}

void RequireBorderSwizzle(std::uint32_t bcSwizzle, std::uint64_t samplerMask, std::span<const std::shared_ptr<Sampler>> samplers) {
constexpr std::uint32_t BcSwizzleXyzw = 0u;
constexpr std::uint32_t BcSwizzleZyxw = 4u;
Expand Down
Loading
Loading