Commit 9076612e authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Shadow format flags in the resource.

parent b6717dc2
...@@ -128,7 +128,7 @@ static void context_attach_depth_stencil_fbo(struct wined3d_context *context, ...@@ -128,7 +128,7 @@ static void context_attach_depth_stencil_fbo(struct wined3d_context *context,
if (depth_stencil) if (depth_stencil)
{ {
DWORD format_flags = depth_stencil->resource.format->flags; DWORD format_flags = depth_stencil->resource.format_flags;
if (depth_stencil->current_renderbuffer) if (depth_stencil->current_renderbuffer)
{ {
...@@ -3168,11 +3168,12 @@ static void context_setup_target(struct wined3d_context *context, struct wined3d ...@@ -3168,11 +3168,12 @@ static void context_setup_target(struct wined3d_context *context, struct wined3d
{ {
/* Disable blending when the alpha mask has changed and when a format doesn't support blending. */ /* Disable blending when the alpha mask has changed and when a format doesn't support blending. */
if ((old->alpha_size && !new->alpha_size) || (!old->alpha_size && new->alpha_size) if ((old->alpha_size && !new->alpha_size) || (!old->alpha_size && new->alpha_size)
|| !(new->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)) || !(target->resource.format_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE));
/* Update sRGB writing when switching between formats that do/do not support sRGB writing */ /* Update sRGB writing when switching between formats that do/do not support sRGB writing */
if ((old->flags & WINED3DFMT_FLAG_SRGB_WRITE) != (new->flags & WINED3DFMT_FLAG_SRGB_WRITE)) if ((context->current_rt->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)
!= (target->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE))
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE));
} }
......
...@@ -649,13 +649,15 @@ static void wined3d_cs_exec_set_texture(struct wined3d_cs *cs, const void *data) ...@@ -649,13 +649,15 @@ static void wined3d_cs_exec_set_texture(struct wined3d_cs *cs, const void *data)
{ {
const struct wined3d_format *new_format = op->texture->resource.format; const struct wined3d_format *new_format = op->texture->resource.format;
const struct wined3d_format *old_format = prev ? prev->resource.format : NULL; const struct wined3d_format *old_format = prev ? prev->resource.format : NULL;
unsigned int old_fmt_flags = prev ? prev->resource.format_flags : 0;
unsigned int new_fmt_flags = op->texture->resource.format_flags;
if (InterlockedIncrement(&op->texture->resource.bind_count) == 1) if (InterlockedIncrement(&op->texture->resource.bind_count) == 1)
op->texture->sampler = op->stage; op->texture->sampler = op->stage;
if (!prev || op->texture->target != prev->target if (!prev || op->texture->target != prev->target
|| !is_same_fixup(new_format->color_fixup, old_format->color_fixup) || !is_same_fixup(new_format->color_fixup, old_format->color_fixup)
|| (new_format->flags & WINED3DFMT_FLAG_SHADOW) != (old_format->flags & WINED3DFMT_FLAG_SHADOW)) || (new_fmt_flags & WINED3DFMT_FLAG_SHADOW) != (old_fmt_flags & WINED3DFMT_FLAG_SHADOW))
device_invalidate_state(cs->device, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL)); device_invalidate_state(cs->device, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL));
if (!prev && op->stage < d3d_info->limits.ffp_blend_stages) if (!prev && op->stage < d3d_info->limits.ffp_blend_stages)
......
...@@ -1925,7 +1925,7 @@ static void resolve_depth_buffer(struct wined3d_state *state) ...@@ -1925,7 +1925,7 @@ static void resolve_depth_buffer(struct wined3d_state *state)
struct wined3d_surface *depth_stencil, *surface; struct wined3d_surface *depth_stencil, *surface;
if (!texture || texture->resource.type != WINED3D_RTYPE_TEXTURE if (!texture || texture->resource.type != WINED3D_RTYPE_TEXTURE
|| !(texture->resource.format->flags & WINED3DFMT_FLAG_DEPTH)) || !(texture->resource.format_flags & WINED3DFMT_FLAG_DEPTH))
return; return;
surface = surface_from_resource(texture->sub_resources[0]); surface = surface_from_resource(texture->sub_resources[0]);
if (!(depth_stencil = wined3d_rendertarget_view_get_surface(state->fb->depth_stencil))) if (!(depth_stencil = wined3d_rendertarget_view_get_surface(state->fb->depth_stencil)))
...@@ -3674,7 +3674,7 @@ HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device ...@@ -3674,7 +3674,7 @@ HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device
} }
texture = state->textures[i]; texture = state->textures[i];
if (!texture || texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING) continue; if (!texture || texture->resource.format_flags & WINED3DFMT_FLAG_FILTERING) continue;
if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_POINT) if (state->sampler_states[i][WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_POINT)
{ {
......
...@@ -81,29 +81,12 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * ...@@ -81,29 +81,12 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
const struct wined3d *d3d = device->wined3d; const struct wined3d *d3d = device->wined3d;
resource_check_usage(usage); resource_check_usage(usage);
if (pool != WINED3D_POOL_SCRATCH && type != WINED3D_RTYPE_BUFFER)
{
if ((usage & WINED3DUSAGE_RENDERTARGET) && !(format->flags & WINED3DFMT_FLAG_RENDERTARGET))
{
WARN("Format %s cannot be used for render targets.\n", debug_d3dformat(format->id));
return WINED3DERR_INVALIDCALL;
}
if ((usage & WINED3DUSAGE_DEPTHSTENCIL) && !(format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
{
WARN("Format %s cannot be used for depth/stencil buffers.\n", debug_d3dformat(format->id));
return WINED3DERR_INVALIDCALL;
}
if ((usage & WINED3DUSAGE_TEXTURE) && !(format->flags & WINED3DFMT_FLAG_TEXTURE))
{
WARN("Format %s cannot be used for texturing.\n", debug_d3dformat(format->id));
return WINED3DERR_INVALIDCALL;
}
}
resource->ref = 1; resource->ref = 1;
resource->device = device; resource->device = device;
resource->type = type; resource->type = type;
resource->format = format; resource->format = format;
resource->format_flags = format->flags;
resource->multisample_type = multisample_type; resource->multisample_type = multisample_type;
resource->multisample_quality = multisample_quality; resource->multisample_quality = multisample_quality;
resource->usage = usage; resource->usage = usage;
...@@ -121,6 +104,26 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * ...@@ -121,6 +104,26 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
resource->resource_ops = resource_ops; resource->resource_ops = resource_ops;
resource->map_binding = WINED3D_LOCATION_SYSMEM; resource->map_binding = WINED3D_LOCATION_SYSMEM;
if (pool != WINED3D_POOL_SCRATCH && type != WINED3D_RTYPE_BUFFER)
{
if ((usage & WINED3DUSAGE_RENDERTARGET) && !(resource->format_flags & WINED3DFMT_FLAG_RENDERTARGET))
{
WARN("Format %s cannot be used for render targets.\n", debug_d3dformat(format->id));
return WINED3DERR_INVALIDCALL;
}
if ((usage & WINED3DUSAGE_DEPTHSTENCIL) &&
!(resource->format_flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
{
WARN("Format %s cannot be used for depth/stencil buffers.\n", debug_d3dformat(format->id));
return WINED3DERR_INVALIDCALL;
}
if ((usage & WINED3DUSAGE_TEXTURE) && !(resource->format_flags & WINED3DFMT_FLAG_TEXTURE))
{
WARN("Format %s cannot be used for texturing.\n", debug_d3dformat(format->id));
return WINED3DERR_INVALIDCALL;
}
}
if (size) if (size)
{ {
if (!wined3d_resource_allocate_sysmem(resource)) if (!wined3d_resource_allocate_sysmem(resource))
......
...@@ -2459,7 +2459,7 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3 ...@@ -2459,7 +2459,7 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3
} }
args->color_fixup[i] = texture->resource.format->color_fixup; args->color_fixup[i] = texture->resource.format->color_fixup;
if (texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW) if (texture->resource.format_flags & WINED3DFMT_FLAG_SHADOW)
args->shadow |= 1 << i; args->shadow |= 1 << i;
/* Flag samplers that need NP2 texcoord fixup. */ /* Flag samplers that need NP2 texcoord fixup. */
......
...@@ -3632,11 +3632,11 @@ static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc ...@@ -3632,11 +3632,11 @@ static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc
&& sampler_states[WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_ANISOTROPIC) && sampler_states[WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_ANISOTROPIC)
|| (texture->flags & WINED3D_TEXTURE_COND_NP2)) || (texture->flags & WINED3D_TEXTURE_COND_NP2))
desc->max_anisotropy = 1; desc->max_anisotropy = 1;
desc->compare = texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW; desc->compare = texture->resource.format_flags & WINED3DFMT_FLAG_SHADOW;
desc->comparison_func = WINED3D_CMP_LESSEQUAL; desc->comparison_func = WINED3D_CMP_LESSEQUAL;
desc->srgb_decode = sampler_states[WINED3D_SAMP_SRGB_TEXTURE]; desc->srgb_decode = sampler_states[WINED3D_SAMP_SRGB_TEXTURE];
if (!(texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)) if (!(texture->resource.format_flags & WINED3DFMT_FLAG_FILTERING))
{ {
desc->mag_filter = WINED3D_TEXF_POINT; desc->mag_filter = WINED3D_TEXF_POINT;
desc->min_filter = WINED3D_TEXF_POINT; desc->min_filter = WINED3D_TEXF_POINT;
......
...@@ -865,7 +865,7 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi ...@@ -865,7 +865,7 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi
GLsizei width = surface->pow2Width; GLsizei width = surface->pow2Width;
const BYTE *mem = NULL; const BYTE *mem = NULL;
if (format->flags & WINED3DFMT_FLAG_HEIGHT_SCALE) if (texture->resource.format_flags & WINED3DFMT_FLAG_HEIGHT_SCALE)
{ {
height *= format->height_scale.numerator; height *= format->height_scale.numerator;
height /= format->height_scale.denominator; height /= format->height_scale.denominator;
...@@ -898,7 +898,7 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi ...@@ -898,7 +898,7 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi
} }
} }
if (format->flags & WINED3DFMT_FLAG_COMPRESSED && mem) if (texture->resource.format_flags & WINED3DFMT_FLAG_COMPRESSED && mem)
{ {
GL_EXTCALL(glCompressedTexImage2D(surface->texture_target, surface->texture_level, GL_EXTCALL(glCompressedTexImage2D(surface->texture_target, surface->texture_level,
internal, width, height, 0, surface->resource.size, mem)); internal, width, height, 0, surface->resource.size, mem));
......
...@@ -44,7 +44,7 @@ void wined3d_volume_get_pitch(const struct wined3d_volume *volume, UINT *row_pit ...@@ -44,7 +44,7 @@ void wined3d_volume_get_pitch(const struct wined3d_volume *volume, UINT *row_pit
{ {
const struct wined3d_format *format = volume->resource.format; const struct wined3d_format *format = volume->resource.format;
if (format->flags & WINED3DFMT_FLAG_BLOCKS) if (volume->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
{ {
/* Since compressed formats are block based, pitch means the amount of /* Since compressed formats are block based, pitch means the amount of
* bytes to the next row of block rather than the next row of pixels. */ * bytes to the next row of block rather than the next row of pixels. */
...@@ -89,7 +89,7 @@ void wined3d_volume_upload_data(struct wined3d_volume *volume, const struct wine ...@@ -89,7 +89,7 @@ void wined3d_volume_upload_data(struct wined3d_volume *volume, const struct wine
if (data->buffer_object) if (data->buffer_object)
ERR("Loading a converted volume from a PBO.\n"); ERR("Loading a converted volume from a PBO.\n");
if (format->flags & WINED3DFMT_FLAG_BLOCKS) if (volume->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
ERR("Converting a block-based format.\n"); ERR("Converting a block-based format.\n");
dst_row_pitch = width * format->conv_byte_count; dst_row_pitch = width * format->conv_byte_count;
...@@ -551,6 +551,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume, ...@@ -551,6 +551,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
const struct wined3d_gl_info *gl_info; const struct wined3d_gl_info *gl_info;
BYTE *base_memory; BYTE *base_memory;
const struct wined3d_format *format = volume->resource.format; const struct wined3d_format *format = volume->resource.format;
const unsigned int fmt_flags = volume->resource.format_flags;
TRACE("volume %p, map_desc %p, box %p, flags %#x.\n", TRACE("volume %p, map_desc %p, box %p, flags %#x.\n",
volume, map_desc, box, flags); volume, map_desc, box, flags);
...@@ -571,7 +572,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume, ...@@ -571,7 +572,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
WARN("Map box is invalid.\n"); WARN("Map box is invalid.\n");
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
if ((format->flags & WINED3DFMT_FLAG_BLOCKS) && !volume_check_block_align(volume, box)) if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !volume_check_block_align(volume, box))
{ {
WARN("Map box is misaligned for %ux%u blocks.\n", WARN("Map box is misaligned for %ux%u blocks.\n",
format->block_width, format->block_height); format->block_width, format->block_height);
...@@ -635,7 +636,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume, ...@@ -635,7 +636,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
TRACE("Base memory pointer %p.\n", base_memory); TRACE("Base memory pointer %p.\n", base_memory);
if (format->flags & WINED3DFMT_FLAG_BROKEN_PITCH) if (fmt_flags & WINED3DFMT_FLAG_BROKEN_PITCH)
{ {
map_desc->row_pitch = volume->resource.width * format->byte_count; map_desc->row_pitch = volume->resource.width * format->byte_count;
map_desc->slice_pitch = map_desc->row_pitch * volume->resource.height; map_desc->slice_pitch = map_desc->row_pitch * volume->resource.height;
...@@ -655,7 +656,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume, ...@@ -655,7 +656,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
TRACE("Lock Box (%p) = l %u, t %u, r %u, b %u, fr %u, ba %u\n", TRACE("Lock Box (%p) = l %u, t %u, r %u, b %u, fr %u, ba %u\n",
box, box->left, box->top, box->right, box->bottom, box->front, box->back); box, box->left, box->top, box->right, box->bottom, box->front, box->back);
if ((format->flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS) if ((fmt_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS)
{ {
/* Compressed textures are block based, so calculate the offset of /* Compressed textures are block based, so calculate the offset of
* the block that contains the top-left pixel of the locked rectangle. */ * the block that contains the top-left pixel of the locked rectangle. */
......
...@@ -2108,6 +2108,7 @@ struct wined3d_resource ...@@ -2108,6 +2108,7 @@ struct wined3d_resource
struct wined3d_device *device; struct wined3d_device *device;
enum wined3d_resource_type type; enum wined3d_resource_type type;
const struct wined3d_format *format; const struct wined3d_format *format;
unsigned int format_flags;
enum wined3d_multisample_type multisample_type; enum wined3d_multisample_type multisample_type;
UINT multisample_quality; UINT multisample_quality;
DWORD usage; DWORD usage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment